Publish to ECR #103
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: Docker Image CI | |
on: | |
push: | |
tags: | |
- '*' | |
branches: [ "master" ] | |
pull_request: | |
branches: [ "master" ] | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
outputs: | |
id: git_tag_output | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
- name: Set version | |
id: version | |
run: echo "VERSION=$(($(git describe --tags --abbrev=0 | sed 's/v//')+1))" >> $GITHUB_ENV | |
- name: Set up QEMU | |
uses: docker/setup-qemu-action@v3 | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v3 | |
- name: docker login | |
env: | |
DOCKER_USER: ${{secrets.DOCKER_USER}} | |
DOCKER_PASSWORD: ${{secrets.DOCKER_PASSWORD}} | |
run: | |
docker login -u $DOCKER_USER -p $DOCKER_PASSWORD | |
- name: Build and push dockerhub | |
uses: docker/build-push-action@v5 | |
env: | |
APP_VERSION: ${{ env.VERSION }} | |
with: | |
context: . | |
platforms: linux/amd64,linux/arm64 | |
push: true | |
tags: onedatashare/transfer_service:${APP_VERSION} | |
push-to-ecr: | |
needs: build | |
runs-on: ubuntu-latest | |
steps: | |
- name: Setup AWS ECR Details | |
uses: aws-actions/configure-aws-credentials@v3 | |
with: | |
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} | |
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | |
aws-region: us-west-1 | |
- name: Login to Amazon ECR | |
id: login-pf-aws-ecr | |
uses: aws-actions/amazon-ecr-login@v2 | |
- name: Build and push the tagged docker image to Amazon ECR | |
env: | |
ECR_REGISTRY: ${{ steps.login-pf-aws-ecr.outputs.registry }} | |
ECR_REPOSITORY: onedatashare/transfer_service | |
IMAGE_TAG: ${{ env.VERSION }} | |
run: | | |
docker pull onedatashare/transfer_service:${IMAGE_TAG} | |
docker tag onedatashare/transfer_service:${IMAGE_TAG} $ECR_REGISTRY/$ECR_REPOSITORY:${IMAGE_TAG} | |
docker push $ECR_REGISTRY/$ECR_REPOSITORY:${IMAGE_TAG} |