From 757eee99569e4cd8e7f9c27706493a9138c9971a Mon Sep 17 00:00:00 2001 From: Joris Bertomeu Date: Tue, 1 Oct 2024 10:52:33 +0200 Subject: [PATCH] Refactor ci workflow --- .gitea/workflows/ci.yaml | 36 ++++++++++++++++++++++++++++-------- 1 file changed, 28 insertions(+), 8 deletions(-) diff --git a/.gitea/workflows/ci.yaml b/.gitea/workflows/ci.yaml index 2b9328e..daa93d7 100644 --- a/.gitea/workflows/ci.yaml +++ b/.gitea/workflows/ci.yaml @@ -1,7 +1,13 @@ name: ci - on: push: + branches: + - main + +env: + REGISTRY: ${{ vars.DOCKER_REGISTRY_URL }} + IMAGE_NAME: bertomlab/crawlflix-front + IMAGE_TAG: ${{ github.sha }} jobs: docker: @@ -15,15 +21,15 @@ jobs: uses: docker/setup-buildx-action@v3 with: config-inline: | - [registry."192.168.1.230:8080"] + [registry."${{ env.REGISTRY }}"] http = true - - name: Login to Docker Hub + - name: Login to Docker Registry uses: docker/login-action@v3 with: - registry: ${{ vars.DOCKER_REGISTRY_URL }} + registry: ${{ env.REGISTRY }} username: ${{ vars.DOCKER_REGISTRY_USERNAME }} - password: ${{ vars.DOCKER_REGISTRY_PASSWORD }} + password: ${{ secrets.DOCKER_REGISTRY_PASSWORD }} - name: Build and push uses: docker/build-push-action@v6 @@ -31,8 +37,22 @@ jobs: platforms: linux/amd64,linux/arm64 push: true tags: | - 192.168.1.230:8080/bertomlab/crawlflix-front:latest - + ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ env.IMAGE_TAG }} + ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest + - name: Inspect run: | - docker buildx imagetools inspect 192.168.1.230:8080/bertomlab/crawlflix-front:latest \ No newline at end of file + docker buildx imagetools inspect ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ env.IMAGE_TAG }} + + - name: Deploy to server + uses: appleboy/ssh-action@master + with: + host: ${{ secrets.SERVER_HOST }} + username: ${{ secrets.SERVER_USERNAME }} + key: ${{ secrets.SERVER_SSH_KEY }} + envs: REGISTRY,IMAGE_NAME,IMAGE_TAG + script: | + docker pull ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ env.IMAGE_TAG }} + docker stop crawlflix-front || true + docker rm crawlflix-front || true + docker run -d --name crawlflix-front -p 80:80 ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ env.IMAGE_TAG }} \ No newline at end of file