-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(action-aws): add build-and-push-lambda-docker-image action
- Loading branch information
1 parent
1a72534
commit 4485953
Showing
2 changed files
with
124 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# AWS: build-and-push-lambda-docker-image | ||
|
||
## Behavior | ||
|
||
Build a docker image. | ||
Push image to ECR. | ||
Save image as artifact and outputs artifact name and filename. | ||
|
||
## Usage | ||
|
||
```yaml | ||
jobs: | ||
advanceTag: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: "Checkout Code" | ||
uses: "actions/checkout@v2" | ||
|
||
- name: "Move tag" | ||
uses: "meero-com/github-actions-shared-workflows/actions/aws/build-and-push-lambda-docker-image@main" | ||
with: | ||
version: github-commit-sha | ||
dockerfile: docker/lambda/Dockerfile | ||
artifact_name: image-uri | ||
AWS_ACCESS_KEY_ID: ${{ secrets.NP_AWS_ACCESS_KEY_ID }} | ||
AWS_SECRET_ACCESS_KEY: ${{ secrets.NP_AWS_SECRET_ACCESS_KEY }} | ||
AWS_REGION: ${{ secrets.AWS_REGION }} | ||
ECR_REPOSITORY_NAME: ${{ secrets.ECR_DEV_REPOSITORY_NAME }} | ||
``` | ||
will output | ||
```yaml | ||
artifact_name: image-uri | ||
artifact_file_name: image-uri.txt | ||
``` | ||
Beware of using a `@ref` (`@main` in the example above) which suits your stability requirements in your workflow: | ||
|
||
* Use `@main` if you always want to use the latest version of the workflow. | ||
* Use `@<tag>` if you wan to use a specific frozen version of the workflow. |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
name: "Build and push lambda container image" | ||
description: "Build lambda container image and push to AWS-ECR" | ||
|
||
inputs: | ||
version: | ||
description: version short sha | ||
resuired: true | ||
dockerfile: | ||
description: path to docker file | ||
resuired: true | ||
artifact_name: | ||
description: Name for artifact (without extension) | ||
resuired: true | ||
AWS_ACCESS_KEY_ID: | ||
description: "Aws access key" | ||
required: true | ||
AWS_SECRET_ACCESS_KEY: | ||
description: "AWS secret" | ||
required: true | ||
AWS_REGION: | ||
description: "AWS region" | ||
required: true | ||
ECR_REPOSITORY_NAME: | ||
description: "ECR repository name" | ||
required: true | ||
|
||
outputs: | ||
artifact_name: | ||
description: "Image artifact name" | ||
value: ${{ inputs.artifact_name }} | ||
artifact_file_name: | ||
description: "Image artifact filename" | ||
value: ${{ inputs.artifact_name }}.txt | ||
|
||
runs: | ||
using: "composite" | ||
steps: | ||
- name: Set up Docker Buildx | ||
uses: docker/setup-buildx-action@v2 | ||
with: | ||
version: v0.9.1 | ||
|
||
- name: Configure AWS credentials | ||
uses: aws-actions/configure-aws-credentials@v2 | ||
with: | ||
aws-access-key-id: ${{ inputs.AWS_ACCESS_KEY_ID }} | ||
aws-secret-access-key: ${{ inputs.AWS_SECRET_ACCESS_KEY }} | ||
aws-region: ${{ inputs.AWS_REGION }} | ||
|
||
- name: Login to Amazon ECR | ||
id: login-ecr | ||
uses: aws-actions/amazon-ecr-login@v1 | ||
|
||
- name: "Build image Tags/URIs" | ||
id: image-tags-uri | ||
shell: bash | ||
run: | | ||
lambda_tag=${{ steps.login-ecr.outputs.registry }}/${{ inputs.ECR_REPOSITORY_NAME }}:${{ inputs.version }} | ||
echo "lambda=$lambda_tag" >> $GITHUB_OUTPUT | ||
- name: Build, tag, and push image to Amazon ECR | ||
id: build-image | ||
uses: docker/build-push-action@v4 | ||
with: | ||
push: true | ||
file: ${{ inputs.dockerfile }} | ||
tags: ${{ steps.image-tags-uri.outputs.lambda }} | ||
cache-from: type=gha | ||
cache-to: type=gha,mode=max | ||
|
||
- name: Save ImageURI as artifact_name.txt | ||
shell: bash | ||
env: | ||
IMAGE_URI: ${{ steps.image-tags-uri.outputs.lambda }} | ||
run: | | ||
echo $IMAGE_URI > ${{ inputs.artifact_name }}.txt | ||
- name: Save Image URI as Artifact | ||
uses: actions/upload-artifact@v3 | ||
with: | ||
name: ${{ inputs.artifact_name }} | ||
path: ${{ inputs.artifact_name }}.txt | ||
|