Merge pull request #953 from sennetconsortium/maxsibilla/update-requests #38
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: Build and Deploy Docker Image on Dev | |
| on: | |
| push: | |
| branches: | |
| - dev-integrate | |
| permissions: | |
| contents: read | |
| jobs: | |
| build-and-push: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v6 | |
| - name: Login to Docker Hub | |
| uses: docker/login-action@v4 | |
| with: | |
| username: ${{ secrets.DOCKER_USERNAME }} | |
| password: ${{ secrets.DOCKER_PASSWORD }} | |
| - name: Create $ENTITY_API_VERSION | |
| run: | | |
| export ENTITY_API_VERSION=$(tr -d "\n\r" < ../VERSION | xargs) | |
| echo "ENTITY_API_VERSION=$ENTITY_API_VERSION" >> $GITHUB_ENV | |
| working-directory: ./docker | |
| - name: Make build script executable | |
| run: chmod +x ./docker-development.sh | |
| working-directory: ./docker | |
| - name: Run the Docker build shell script | |
| run: ./docker-development.sh build | |
| working-directory: ./docker | |
| - name: Tag the Docker Image | |
| # Alternatively we could use ${{ github.sha }} instead of latest | |
| run: docker image tag sennet/entity-api:$ENTITY_API_VERSION sennet/entity-api-dev:latest | |
| working-directory: ./docker | |
| - name: Push the Docker image | |
| run: docker push sennet/entity-api-dev:latest | |
| working-directory: ./docker | |
| deploy: | |
| runs-on: ubuntu-latest | |
| needs: build-and-push | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v6 | |
| - name: Get GitHub runner public IP | |
| id: runner_ip | |
| run: | | |
| IP=$(curl -s https://api.ipify.org) | |
| echo "Runner IP: $IP" | |
| echo "ip=$IP" >> $GITHUB_OUTPUT | |
| - name: Install dependencies | |
| run: npm install @aws-sdk/client-ec2 | |
| - name: Modify security group | |
| env: | |
| AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} | |
| AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | |
| AWS_REGION: us-east-1 | |
| SECURITY_GROUP_ID: sg-0ddfcbe0a83a5266c | |
| PORT: 22 | |
| RUNNER_IP: ${{ steps.runner_ip.outputs.ip }} | |
| MODE: authorize | |
| run: node $GITHUB_WORKSPACE/.github/scripts/update-security-group.mjs | |
| - name: Deploy to Server via SSH | |
| uses: appleboy/ssh-action@v1 | |
| with: | |
| host: '${{ secrets.REMOTE_HOST }}' | |
| username: ${{ secrets.REMOTE_USER }} | |
| key: ${{ secrets.SSH_PRIVATE_KEY }} | |
| use_insecure_cipher: true | |
| script: | | |
| # Change to codcc user on server | |
| sudo su - codcc -c "cd /opt/sennet/entity-api/docker/; git pull; docker pull sennet/entity-api-dev:latest; ./docker-development.sh down; ./docker-development.sh start;" | |
| - name: Remove runner IP from security group | |
| if: always() | |
| env: | |
| AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} | |
| AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | |
| AWS_REGION: us-east-1 | |
| SECURITY_GROUP_ID: sg-0ddfcbe0a83a5266c | |
| PORT: 22 | |
| RUNNER_IP: ${{ steps.runner_ip.outputs.ip }} | |
| MODE: revoke | |
| run: node $GITHUB_WORKSPACE/.github/scripts/update-security-group.mjs |