Last active
September 16, 2023 21:27
-
-
Save sombriks/c8e8979d80efaf02de6bf04ffe5805cc to your computer and use it in GitHub Desktop.
build and publish docker image on ECR on tag push
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: Publish git tag as ECR image | |
on: | |
push: | |
tags: | |
- '*' | |
env: | |
REGISTRY_USER: ${{ secrets.REGISTRY_USER }} | |
REGISTRY_TOKEN: ${{ secrets.REGISTRY_TOKEN }} | |
OPENAI_TOKEN: ${{ secrets.OPENAI_TOKEN }} | |
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} | |
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | |
AWS_REGION: ${{ secrets.AWS_REGION }} | |
ECR_REGISTRY: myalias.dkr.ecr.us-east-1.amazonaws.com | |
SERVICE_NAME: my-service | |
DOCKERFILE: ./src/infrastructure/Dockerfile # see https://gist.github.com/sombriks/2c810d07eca883dba179377be515b6cf | |
GIT_TAG: ${{ github.ref_name }} | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v3 | |
- name: Set up JDK 17 | |
uses: actions/setup-java@v3 | |
with: | |
java-version: '17' | |
distribution: 'temurin' | |
- name: Build with Gradle | |
uses: gradle/gradle-build-action@749f47bda3e44aa060e82d7b3ef7e40d953bd629 | |
with: | |
gradle-version: 7.6 | |
arguments: build | |
- name: Configure AWS credentials | |
uses: aws-actions/configure-aws-credentials@0e613a0980cbf65ed5b322eb7a1e075d28913a83 | |
with: | |
aws-access-key-id: ${{ env.AWS_ACCESS_KEY_ID }} | |
aws-secret-access-key: ${{ env.AWS_SECRET_ACCESS_KEY }} | |
aws-region: ${{ env.AWS_REGION }} | |
- name: Login to Amazon ECR | |
uses: aws-actions/amazon-ecr-login@v1 | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v2 | |
- name: Build and publish image | |
uses: docker/build-push-action@v4 | |
with: | |
context: . | |
build-args: | | |
SERVICE=${{ env.SERVICE_NAME }} | |
VERSION=${{ env.GIT_TAG }} | |
file: ${{ env.DOCKERFILE }} | |
tags: ${{ env.ECR_REGISTRY }}/${{ env.SERVICE_NAME }}:${{ env.GIT_TAG }} | |
push: true |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment