add network #7
This file contains hidden or 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: Deploy docker image and update production | |
| on: | |
| push: | |
| branches: | |
| - 'main' | |
| env: | |
| REGISTRY: ghcr.io | |
| DOCKER_STACK_NAME: mixdrinks | |
| DEPLOY_USER: deploy | |
| HOST: 167.235.52.168 | |
| jobs: | |
| build-and-push-image: | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: read | |
| packages: write | |
| attestations: write | |
| id-token: write | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| - name: Log in to the Container registry | |
| uses: docker/login-action@v2 | |
| with: | |
| registry: ${{ env.REGISTRY }} | |
| username: ${{ github.actor }} | |
| password: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Get repository name in lowercase | |
| id: repo_name | |
| run: echo "REPO_NAME=$(echo ${{ github.repository }} | tr '[:upper:]' '[:lower:]')" >> $GITHUB_ENV | |
| - name: Build and push Docker image | |
| uses: docker/build-push-action@v6 | |
| with: | |
| context: . | |
| push: true | |
| tags: | | |
| ${{ env.REGISTRY }}/${{ env.REPO_NAME }}:latest | |
| ${{ env.REGISTRY }}/${{ env.REPO_NAME }}:${{ github.sha }} | |
| build-args: | | |
| GIT_COMMIT_SHA=${{ github.sha }} | |
| deploy: | |
| runs-on: ubuntu-latest | |
| needs: | |
| - build-and-push-image | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| - name: Create env file | |
| run: | | |
| echo "GIT_COMMIT_SHA=${{ github.sha }}" >> ./envfile | |
| echo "MONGO_URI=${{ secrets.MONGO_URI }}" >> ./envfile | |
| - name: Docker Stack Deploy | |
| uses: cssnr/stack-deploy-action@v1 | |
| with: | |
| name: ${{ env.DOCKER_STACK_NAME }} | |
| file: docker-stack.yaml | |
| host: ${{ env.HOST }} | |
| user: ${{ env.DEPLOY_USER }} | |
| ssh_key: ${{ secrets.DEPLOY_SSH_PRIVATE_KEY }} | |
| env_file: ./envfile |