use aws oidc github federation #9
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: prod | ||
permissions: | ||
id-token: write | ||
contents: read | ||
on: | ||
pull_request: | ||
types: [closed] | ||
branches: | ||
- master | ||
workflow_dispatch: | ||
env: | ||
STACK_NAME: ${{ github.event.repository.name }} | ||
AWS_DEFAULT_REGION: eu-west-1 | ||
jobs: | ||
BuildDocker: | ||
name: build-docker-hub | ||
#if: "github.event.pull_request.merged || github.ref == 'refs/heads/master'" | ||
if: github.event.pull_request.merged | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- name: Login to Docker Hub | ||
uses: docker/login-action@v1 | ||
with: | ||
username: ${{ secrets.DOCKERHUB_USERNAME }} | ||
password: ${{ secrets.DOCKERHUB_TOKEN }} | ||
- name: Build, tag, and push image to Amazon ECR Public | ||
id: build-image-ecr-public | ||
env: | ||
ECR_REGISTRY: 'allamand' | ||
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" | ||
BuildECR: | ||
name: build-ecr-public | ||
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: | ||
- 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: aws-actions/amazon-ecr-login@v2 | ||
with: | ||
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 |