final deploy #33
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: Push Docker image to Docker Hub and deploy workflow | |
on: | |
push: | |
branches: [main] | |
jobs: | |
build_and_push_to_docker_hub: | |
name: Push Docker image to Docker Hub | |
runs-on: ubuntu-latest | |
if: | |
contains(' | |
refs/heads/main | |
', github.ref) | |
steps: | |
- name: Check out the repo | |
uses: actions/checkout@v3 | |
with: | |
fetch-depth: 0 | |
submodules: recursive | |
token: ${{ secrets.PAT_TOKEN }} | |
- name: Pull & update submodules recursively | |
run: | | |
git submodule update --init --recursive | |
git submodule update --recursive --remote | |
- name: Commit & push changes | |
run: | | |
git config user.email "[email protected]" | |
git config user.name "GitHub Actions - update submodules" | |
git commit -am "Update submodules" || echo "No changes to commit" | |
git push | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v3 | |
- name: Login to Docker | |
uses: docker/login-action@v3 | |
with: | |
username: ${{ secrets.DOCKER_USERNAME }} | |
password: ${{ secrets.DOCKER_PASSWORD }} | |
- name: Push to Docker Hub skills_frontend | |
uses: docker/build-push-action@v3 | |
with: | |
context: hackathon/ | |
file: hackathon/Dockerfile | |
push: true | |
tags: ${{ secrets.DOCKER_USERNAME }}/skills_frontend:latest | |
- name: Push to Docker Hub skills_backend | |
uses: docker/build-push-action@v3 | |
with: | |
context: backend/ | |
file: backend/Dockerfile | |
push: true | |
tags: ${{ secrets.DOCKER_USERNAME }}/skills_backend:latest | |
deploy: | |
runs-on: ubuntu-latest | |
needs: build_and_push_to_docker_hub | |
if: github.ref == 'refs/heads/main' | |
steps: | |
- name: executing remote ssh commands to deploy | |
uses: appleboy/ssh-action@master | |
with: | |
host: ${{ secrets.HOST }} | |
username: ${{ secrets.USER }} | |
key: ${{ secrets.SSH_KEY }} | |
script: | | |
sudo systemctl stop nginx | |
sudo docker compose stop | |
sudo docker container rm backend-container-skills | |
sudo docker container rm frontend-skills | |
sudo docker image pull ${{ secrets.DOCKER_USERNAME }}/skills_backend:latest | |
sudo docker image pull ${{ secrets.DOCKER_USERNAME }}/skills_frontend:latest | |
sudo docker compose up -d |