Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Build, Push, and Deploy Docker Image | |
on: | |
push: | |
branches: | |
- actions-test | |
jobs: | |
build-push-and-deploy: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v2 | |
- name: List files in the current working directory | |
run: | | |
ls -la | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v1 | |
- name: Build and Push Docker Image | |
run: | | |
echo "${{ secrets.DOCKERHUB_TOKEN }}" | docker login -u ${{ secrets.DOCKERHUB_USERNAME }} --password-stdin | |
docker build -t ${{ secrets.DOCKERHUB_USERNAME }}/motto:latest -f Dockerfile . | |
docker push ${{ secrets.DOCKERHUB_USERNAME }}/motto:latest | |
- name: Deploy to Server | |
uses: appleboy/ssh-action@master | |
with: | |
host: ${{ secrets.SERVER_IP }} | |
username: ${{ secrets.SERVER_USERNAME }} | |
key: ${{ secrets.SERVER_SSH_KEY }} | |
script: | | |
docker pull ${{ secrets.DOCKERHUB_USERNAME }}/motto:latest | |
docker stop motto || true | |
docker rm motto || true | |
docker run -d --name motto -p 3001:3001 ${{ secrets.DOCKERHUB_USERNAME }}/motto:latest |