Skip to content

Publish to ECR

Publish to ECR #98

Workflow file for this run

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: Run git tag
run: git tag
shell: bash
- 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
with:
context: .
platforms: linux/amd64,linux/arm64
push: true
tags: onedatashare/transfer_service:${{ needs.build.outputs.git_tag_output }}
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: ${{ needs.build.outputs.git_tag_output }}
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