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
Reference
name: "Build and push images 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: "MyLambda/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, og generated Deployment-ID.
# Syntax: Multiline-string "NAME=VALUE"
image-tags: |
latest
my_other_tag
my_last_tag
Examples
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: Continous Deployment
on:
push:
branches: [master]
jobs:
build_push_image_to_ecr:
name: Build and push images to ECR
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 defaults the build context to the root directory (./) and assumes that the Dockerfile resides in same directory (i.e. ./Dockerfile).
In some projects this will not be the correct assumption.
Case 1: The default case
Example project
. # <-- Build Context
├── ...
├── Program.cs
└── Dockerfile # <-- Target this Dockerfile
Via GitHub Actions:
Which effectively executes the following command:
Case 2: Build context is not the root directory
Example project
.
├── Lambda.CreateBooking/
│ ├── ... # <-- Build Context
│ └── Dockerfile # <-- Target this Dockerfile
└── Lambda.DeleteBooking/
├── ...
└── Dockerfile
Via GitHub Actions:
Which effectively executes the following command:
Case 3: Build context and Dockerfile reside in different directories
Example project
. # <-- Build Context
│
├── Lambda.CreateBooking/
│ ├── ...
│ └── Dockerfile # <-- Target this Dockerfile
└── Lambda.DeleteBooking/
├── ...
└── Dockerfile
Via GitHub Actions:
Which effectively executes the following command: