From 71a47d8646090ea1010230f13682f307ac6d9898 Mon Sep 17 00:00:00 2001 From: kaxada Date: Wed, 13 Dec 2023 19:16:10 +0300 Subject: [PATCH] changed deploy configs --- .github/workflows/deploy.yml | 67 +++++++++++++----------------------- 1 file changed, 23 insertions(+), 44 deletions(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 71c787c..9596256 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -7,8 +7,7 @@ on: pull_request: env: - REGISTRY: "registry.digitalocean.com/event-badging-bot" - IMAGE_NAME: "badging" + IMAGE_NAME: "event_badging" jobs: build: @@ -20,41 +19,28 @@ jobs: - name: Lint code run: npm run format - docker-build: + deploy: needs: build runs-on: ubuntu-latest if: github.ref == 'refs/heads/main' && github.event_name == 'push' steps: - uses: actions/checkout@v3 - - name: Login to DigitalOcean registry - uses: digitalocean/action-doctl@v2 - with: - token: ${{ secrets.DIGITALOCEAN_ACCESS_TOKEN }} - - name: Log in to DigitalOcean Container Registry with short-lived credentials - run: doctl registry login --expiry-seconds 600 - - name: Delete existing images with similar name - run: | - doctl registry repository list-tags $REGISTRY/$IMAGE_NAME --format Name --no-header | - while read -r image_tag; do - doctl registry image delete $REGISTRY/$IMAGE_NAME:$image_tag; - done - - name: Build and push Docker image - uses: docker/build-push-action@v4 - with: - context: . - push: true - tags: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ github.sha }} + - name: Build Docker image + run: docker build -t ${{ env.IMAGE_NAME }}:${{ github.sha }} . - deploy: - needs: docker-build - runs-on: ubuntu-latest - if: github.ref == 'refs/heads/main' && github.event_name == 'push' - steps: - - name: Login to DigitalOcean registry - uses: digitalocean/action-doctl@v2 + - name: Create image archive + run: docker save ${{ env.IMAGE_NAME }}:${{ github.sha }} -o event_badging.tar + + - name: Upload image archive using appleboy/scp-action + uses: appleboy/scp-action@v0.1.4 with: - token: ${{ secrets.DIGITALOCEAN_ACCESS_TOKEN }} - - name: Stop and remove existing images with the same name on the droplet + host: ${{ secrets.HOST }} + username: ${{ secrets.USERNAME }} + password: ${{ secrets.PASSWORD }} + source: event_badging.tar + target: ~/ + + - name: Extract and load image on droplet uses: appleboy/ssh-action@v0.1.10 with: host: ${{ secrets.HOST }} @@ -65,18 +51,11 @@ jobs: docker stop ${{ env.IMAGE_NAME }} docker rm ${{ env.IMAGE_NAME }} fi - - name: Deploy Docker image to DigitalOcean Droplet - uses: appleboy/ssh-action@v0.1.10 - with: - host: ${{ secrets.HOST }} - username: ${{ secrets.USERNAME }} - password: ${{ secrets.PASSWORD }} - script: | - docker pull ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ github.sha }} - echo ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ github.sha }} + docker rmi -f $(docker images -q ${{ env.IMAGE_NAME }}) || true + docker load -i ~/event_badging.tar docker run -d \ - -p ${{ secrets.PORT }}:${{ secrets.PORT }} \ - --env-file /home/${{ secrets.USERNAME }}/.env \ - --restart=always \ - --name ${{ env.IMAGE_NAME }} \ - ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ github.sha }} \ No newline at end of file + -p ${{ secrets.PORT }}:${{ secrets.PORT }} \ + --env-file /home/${{ secrets.USERNAME }}/.env.badging_bot \ + --restart=always \ + --name ${{ env.IMAGE_NAME }} \ + ${{ env.IMAGE_NAME }}:${{ github.sha }} \ No newline at end of file