diff --git a/.github/workflows/master.yml b/.github/workflows/master.yml index 60dbeb4..dfcb085 100644 --- a/.github/workflows/master.yml +++ b/.github/workflows/master.yml @@ -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 @@ -77,8 +39,24 @@ 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: . @@ -86,12 +64,6 @@ BuildECR: 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