From 9e1dcbb07d9eca02ba1a94835182557b292b9488 Mon Sep 17 00:00:00 2001 From: Sonny Date: Mon, 3 Jun 2024 00:13:11 +0200 Subject: [PATCH] chore(ci): bring back previous CD github workflow --- .github/workflows/cd.yml | 53 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 .github/workflows/cd.yml diff --git a/.github/workflows/cd.yml b/.github/workflows/cd.yml new file mode 100644 index 0000000..d1dd283 --- /dev/null +++ b/.github/workflows/cd.yml @@ -0,0 +1,53 @@ +name: CI/CD prod + +on: + release: + types: published + +jobs: + push_image_to_docker_hub: + name: Build and push image to Docker Hub + runs-on: ubuntu-latest + steps: + - name: Checkout the repo + uses: actions/checkout@v3 + + - name: Docker meta + id: docker_meta + uses: docker/metadata-action@v5.5.1 + with: + images: sonny93/my-links + flavor: latest=true + tags: | + type=semver,pattern={{version}} + + - name: Login to DockerHub + uses: docker/login-action@v3.1.0 + with: + username: ${{ secrets.DOCKER_USERNAME }} + password: ${{ secrets.DOCKER_PASSWORD }} + + - name: Build and push + uses: docker/build-push-action@v5.3.0 + with: + file: ./Dockerfile + context: . + push: true + tags: ${{ steps.docker_meta.outputs.tags }} + labels: ${{ steps.docker_meta.outputs.labels }} + + execute_commands_via_ssh: + name: Pull latest docker image and start up the application with Docker Compose + runs-on: ubuntu-latest + needs: push_image_to_docker_hub + steps: + - name: Executing remote ssh commands + uses: appleboy/ssh-action@master + with: + host: ${{ secrets.SSH_HOST }} + port: ${{ secrets.SSH_PORT }} + username: ${{ secrets.SSH_USERNAME }} + key: ${{ secrets.SSH_KEY }} + script: | + cd /infra/my-links + sh startup.sh