diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 103db57..8a2eff4 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -7,7 +7,7 @@ on: pull_request: env: - REGISTRY: "registry.digitalocean.com/project-badging" + REGISTRY: "registry.digitalocean.com/badging" IMAGE_NAME: "badging" jobs: @@ -20,7 +20,7 @@ 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' @@ -38,23 +38,10 @@ jobs: 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.REGISTRY }}/${{ 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 - with: - token: ${{ secrets.DIGITALOCEAN_ACCESS_TOKEN }} - - name: Stop and remove existing images with the same name on the droplet + - name: Push Docker image to DigitalOcean Droplet uses: appleboy/ssh-action@v0.1.10 with: host: ${{ secrets.HOST }} @@ -65,18 +52,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 ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ github.sha }} || true + docker load -i - << '${{ runner.workspace }}/.image.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 }} + -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