Push images til ECR
- Reference:
BYM-IKT/github-actions/build-and-push-image-to-ecr - Type: Composite Action
- Repository: BYM-IKT/github-actions/build-and-push-image-to-ecr
Example
name: Deploy ECS Fargate to TEST
on:
push:
branches: [master]
workflow_dispatch:
jobs:
build_push_image_to_shared:
name: Build image and publish to ECR
runs-on: ubuntu-latest
permissions:
id-token: write
contents: read
steps:
- name: "Build Kattehotell image and push to ECR"
uses: BYM-IKT/github-actions/build-and-push-image-to-ecr@master
with:
aws-account-id: "<<AWS-ACCOUNT-ID>>" # Mandatory
ecr-name: "kattehotell-service" # Mandatory
docker-context-path: "KattehotellService" # Optional: Defaults to "."
dockerfile-path: "Kattehotell.service/Dockerfile" # Optional: Defaults to "./Dockerfile"
# Optional: Defaults to no extra build-arguments
# Syntax: Multiline-string "NAME=VALUE"
docker-build-args: |
NUGET_AUTH_TOKEN=${{ secrets.PACKAGES_GITHUB_ACCESS_TOKEN }}
KATTEHOTELL_ID=123
# Optional: Defaults to 3 tags: 'latest', current commit SHA, and a generated deployment ID.
# Syntax: Multiline-string "NAME=VALUE"
image-tags: |
latest
my_other_tag
my_last_tag
<<AWS_ACCOUNT_ID>> with the AWS Account ID where the ECR repository is hosted.
Note
The workflow requires the following GitHub Actions permissions:
The repository must also be configured to assume an AWS IAM role with permissions to push images to ECR.
Other Scenarios
Pushing Multiple Images
You have the following project at hand:
Example project
.
├── Lambda.CreateBooking/
│ ├── ...
│ └── Dockerfile
└── Lambda.DeleteBooking/
├── ...
└── Dockerfile
You can build both projects and push the images by adding the following workflow-file:
.github/workflows/cd.yml
name: Continuous Deployment
on:
push:
branches: [master]
jobs:
build_push_image_to_lambda:
name: Build and push images to lambda
runs-on: ubuntu-latest
permissions:
id-token: write
contents: read
steps:
- name: "Lambda.CreateBooking"
uses: BYM-IKT/github-actions/build-and-push-image-to-ecr@master
with:
aws-account-id: "<<AWS-ACCOUNT-ID>>"
ecr-name: "kattehotell-create-booking"
docker-context-path: "Lambda.CreateBooking"
- name: "Lambda.DeleteBooking"
uses: BYM-IKT/github-actions/build-and-push-image-to-ecr@master
with:
aws-account-id: "<<AWS-ACCOUNT-ID>>"
ecr-name: "kattehotell-delete-booking"
docker-context-path: "Lambda.DeleteBooking"
Changing build context and target Dockerfile
The build-and-push-image-to-ecr action uses the repository root (./) as the default Docker build context and assumes the Dockerfile is located at ./Dockerfile.
In some projects this is not the correct assumption.
Case 1: Default Configuration
Example project
. # <-- Build Context
├── ...
├── Program.cs
└── Dockerfile # <-- Target this Dockerfile
Via GitHub Actions:
Which executes the following command:
Case 2: Custom Build Context
Example project
.
├── Lambda.CreateBooking/
│ ├── ... # <-- Build Context
│ └── Dockerfile # <-- Target this Dockerfile
└── Lambda.DeleteBooking/
├── ...
└── Dockerfile
Via GitHub Actions:
Which executes the following command:
Case 3: Separate Build Context and Dockerfile Location
Example project
. # <-- Build Context
│
├── Lambda.CreateBooking/
│ ├── ...
│ └── Dockerfile # <-- Target this Dockerfile
└── Lambda.DeleteBooking/
├── ...
└── Dockerfile
Via GitHub Actions:
Which executes the following command: