build: github action to build docker image for ecr #5
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 | |
on: | |
push: | |
branches: | |
- "main" | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
permissions: | |
id-token: write | |
contents: read | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v2 | |
- name: Configure AWS credentials | |
uses: aws-actions/configure-aws-credentials@v2 | |
with: | |
role-to-assume: arn:aws:iam::188245254368:role/github-role | |
aws-region: us-east-1 | |
- name: Get commit hash | |
id: get-commit-hash | |
run: echo "::set-output name=commit-hash::$(git rev-parse --short HEAD)" | |
- name: Login to Amazon ECR | |
id: login-ecr | |
uses: aws-actions/amazon-ecr-login@v1 | |
- name: Build, tag, and push the image to Amazon ECR | |
id: build-image | |
env: | |
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }} | |
ECR_REPOSITORY: globalbibletools-platform | |
IMAGE_TAG: ${{ steps.get-commit-hash.outputs.commit-hash }} | |
DATBASE_URL: ${{ secrets.DATABASE_URL }} | |
run: | | |
docker build --secret database-url=$DATABASE_URL -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG . | |
docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG |