Merge pull request #167 from Vitruveo/main #101
This file contains 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 API for Production | |
on: | |
push: | |
branches: [production] | |
paths: | |
- .github/workflows/*.yaml | |
- src/**/*.ts | |
- Dockerfile.production | |
- package.json | |
- package-lock.json | |
- tools/**/*.js | |
- entrypoint.sh | |
jobs: | |
build: | |
name: Building a new docker image | |
runs-on: ubuntu-latest | |
environment: production | |
permissions: | |
id-token: write | |
contents: read | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Configure AWS credentials | |
uses: aws-actions/configure-aws-credentials@v4 | |
with: | |
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} | |
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | |
aws-region: ${{ secrets.AWS_REGION }} | |
- name: Login to Amazon ECR | |
id: login-ecr | |
uses: aws-actions/amazon-ecr-login@v2 | |
- name: Setup Node.js | |
uses: actions/setup-node@v3 | |
with: | |
node-version: '18.x' | |
- run: npm install | |
- run: npm run build | |
- name: Getting project info | |
id: project-info | |
run: node tools/info.js | |
- name: Build, tag, and push docker image to Amazon ECR | |
env: | |
REGISTRY: ${{ steps.login-ecr.outputs.registry }} | |
IMAGE_TAG: ${{ steps.project-info.outputs.version }} | |
REPOSITORY: vitruveo.studio.api | |
UPDATE_TOKEN: ${{ secrets.UPDATE_TOKEN }} | |
UPDATE_URL: ${{ secrets.UPDATE_URL }} | |
REPOSITORY_IMAGE: ${{ vars.REPOSITORY_IMAGE }} | |
run: | | |
docker build -t $REGISTRY/$REPOSITORY:$IMAGE_TAG.production -t $REGISTRY/$REPOSITORY:latest.production -f Dockerfile.production --network host . | |
docker push $REGISTRY/$REPOSITORY:$IMAGE_TAG.production | |
docker push $REGISTRY/$REPOSITORY:latest.production | |
curl -X "POST" -H 'Content-Type: application/json' -d "{ \"token\": \"$UPDATE_TOKEN\", \"image\": \"$REPOSITORY_IMAGE:$IMAGE_TAG.production\", \"service\": \"vitruveo-studio_api\"}" $UPDATE_URL |