Merge branch 'develop' into fix#23-implement-cicd-setup #4
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: CD | ||
on: | ||
workflow_dispatch: | ||
pull_request: | ||
types: [closed] | ||
branches: [develop] | ||
jobs: | ||
deploy: | ||
if: github.event.pull_request.merged == true | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v3 | ||
- name: Set up Docker Buildx | ||
uses: docker/setup-buildx-action@v1 | ||
- name: Login to DockerHub | ||
uses: docker/login-action@v1 | ||
with: | ||
username: ${{ secrets.DOCKER_USERNAME }} | ||
password: ${{ secrets.DOCKER_PASSWORD }} | ||
- name: Build and push Docker image | ||
uses: docker/build-push-action@v2 | ||
with: | ||
context: . | ||
file: ./Dockerfile | ||
push: true | ||
tags: ${{ secrets.DOCKER_USERNAME }}/dev:latest | ||
- name: Add SSH | ||
push: true | ||
tags: ${{ secrets.DOCKER_USERNAME }}/dev:latest | ||
- name: Add SSH key | ||
uses: webfactory/[email protected] | ||
with: | ||
ssh-private-key: ${{ secrets.SSH_PRIVATE_KEY }} | ||
- name: Deploy to server | ||
run: | | ||
ssh ${{ secrets.SSH_USER }}@${{ secrets.SSH_HOST }} << 'EOF' | ||
docker pull ${{ secrets.DOCKER_USERNAME }}/dev:latest | ||
docker stop app || true | ||
docker rm app || true | ||
docker run -d --name app -p 80:80 ${{ secrets.DOCKER_USERNAME }}/dev:latest | ||
docker image prune -f | ||
EOF | ||