Skip to content

Commit

Permalink
Merge pull request #12 from allamand/upgrade
Browse files Browse the repository at this point in the history
use aws oidc github federation
  • Loading branch information
allamand authored Feb 26, 2025
2 parents 7a136da + 40a7f57 commit 4482b76
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 28 deletions.
4 changes: 4 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.git
.github
.gitignore
README.md
71 changes: 43 additions & 28 deletions .github/workflows/master.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
name: prod
permissions:
id-token: write
contents: read

on:
pull_request:
Expand Down Expand Up @@ -45,38 +48,50 @@ jobs:
docker push $ECR_REGISTRY/$ECR_REPOSITORY:latest
echo "::set-output name=image::$ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG"
BuildECR:
BuildECR:
name: build-ecr-public
#if: "github.event.pull_request.merged || github.ref == 'refs/heads/master'"
if: github.event.pull_request.merged
runs-on: ubuntu-latest
permissions:
id-token: write
contents: read

outputs:
image-tag: ${{ steps.build-image.outputs.image-tag }}

steps:
- uses: actions/checkout@v2

- name: Checkout code
uses: actions/checkout@v4

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: ${{ secrets.AWS_ROLE_ARN }}
aws-region: us-east-1

- name: Login to Public ECR
uses: docker/login-action@v1
uses: aws-actions/amazon-ecr-login@v2
with:
registry: public.ecr.aws
username: ${{ secrets.AWS_ACCESS_KEY_ID }}
password: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
env:
AWS_REGION: us-east-1

- name: Build, tag, and push image to Amazon ECR Public
id: build-image-ecr-public
registry-type: public

- name: Build and push
id: build-image
uses: docker/build-push-action@v5
with:
context: .
push: true
platforms: linux/amd64,linux/arm64
cache-from: type=gha
cache-to: type=gha,mode=max
tags: |
${{ env.ECR_REGISTRY }}/${{ github.event.repository.name }}:${{ github.sha }}
${{ env.ECR_REGISTRY }}/${{ github.event.repository.name }}:latest
labels: |
org.opencontainers.image.source=${{ github.server_url }}/${{ github.repository }}
org.opencontainers.image.revision=${{ github.sha }}
org.opencontainers.image.created=${{ steps.prep.outputs.created }}
env:
ECR_REGISTRY: 'public.ecr.aws/seb-demo'
ECR_REPOSITORY: ${{ github.event.repository.name }}
IMAGE_TAG: ${{ github.sha }}
#IMAGE_TAG: ${{ github.event.number }}
run: |
# Build a docker container and
# push it to ECR so that it can
# be deployed to ECS.
echo $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG
docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG .
docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG
#update latest
docker tag $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG $ECR_REGISTRY/$ECR_REPOSITORY:latest
docker push $ECR_REGISTRY/$ECR_REPOSITORY:latest
echo "::set-output name=image::$ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG"
ECR_REGISTRY: public.ecr.aws/seb-demo

0 comments on commit 4482b76

Please sign in to comment.