Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 23 additions & 51 deletions .github/workflows/master.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,51 +13,13 @@ on:
env:
STACK_NAME: ${{ github.event.repository.name }}
AWS_DEFAULT_REGION: eu-west-1
ECR_REGISTRY: public.ecr.aws/seb-demo

jobs:
BuildDocker:
name: build-docker-hub
#if: "github.event.pull_request.merged || github.ref == 'refs/heads/master'"
build-and-push:
name: Build and Push Images
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
Expand All @@ -77,21 +39,31 @@ BuildECR:
with:
registry-type: public

- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Extract metadata for Docker
id: meta
uses: docker/metadata-action@v5
with:
images: |
${{ env.ECR_REGISTRY }}/${{ github.event.repository.name }}
allamand/${{ github.event.repository.name }}
tags: |
type=sha,format=long
type=raw,value=latest

- 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
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
provenance: false
Loading