Skip to content
This repository was archived by the owner on Oct 23, 2023. It is now read-only.

Commit d9a1e1d

Browse files
committed
SSE-2732: Allow dockerfile and docker path to be different
The dockerfile doesn't necessarily always reside in the docker path; use the docker build command args accordingly. Allow the SAM template file to be different than the base build dir - the path from which SAM resources are resolved is not always the same as the template file, which is the default, therefore the --base-dir param must be used. Set default working dirs in the script The "." default value doesn't get carried to the script env vars. Handle default value of null in the script itself.
1 parent 560a13f commit d9a1e1d

File tree

2 files changed

+10
-12
lines changed

2 files changed

+10
-12
lines changed

action.yaml

+6-5
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,13 @@ inputs:
77
container-sign-kms-key-arn:
88
description: "The secret with the ARN of the key to sign container images e.g. secrets.CONTAINER_SIGN_KMS_KEY"
99
required: false
10-
default: "none"
1110
template-file:
1211
description: "The name of the CF template for the application. This defaults to template.yaml"
1312
required: false
1413
default: template.yaml
15-
working-directory:
16-
description: "The working directory containing the app"
14+
sam-base-directory:
15+
description: "The base directory to use when building the SAM app; defaults to the template file's location"
1716
required: false
18-
default: .
1917
artifact-bucket-name:
2018
description: "The secret with the name of the artifact S3 bucket (required) eg secrets.ARTIFACT_SOURCE_BUCKET_NAME"
2119
required: true
@@ -56,8 +54,11 @@ runs:
5654
- name: Login to Amazon ECR
5755
id: login-ecr
5856
uses: aws-actions/amazon-ecr-login@v1
57+
with:
58+
mask-password: true
5959

6060
- name: Install Cosign
61+
if: ${{ inputs.container-sign-kms-key-arn != null }}
6162
uses: sigstore/cosign-installer@main
6263
with:
6364
cosign-release: 'v1.9.0'
@@ -67,8 +68,8 @@ runs:
6768
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
6869
CONTAINER_SIGN_KMS_KEY_ARN: ${{ inputs.container-sign-kms-key-arn }}
6970
GITHUB_SHA: ${{ github.sha }}
70-
WORKING_DIRECTORY: ${{ inputs.working-directory }}
7171
TEMPLATE_FILE: ${{ inputs.template-file }}
72+
SAM_BASE_DIR: ${{ inputs.sam-base-directory }}
7273
ECR_REPO_NAME: ${{ inputs.ecr-repo-name }}
7374
ARTIFACT_BUCKET_NAME: ${{ inputs.artifact-bucket-name }}
7475
DOCKERFILE: ${{ inputs.dockerfile }}

scripts/build-tag-push-ecr.sh

+4-7
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,19 @@
22

33
set -eu
44

5-
if [ -z $DOCKER_BUILD_PATH ]; then
6-
DOCKER_BUILD_PATH=$WORKING_DIRECTORY
7-
fi
5+
: "${DOCKER_BUILD_PATH:=.}"
86

97
echo "Building image"
108

11-
docker build -t "$ECR_REGISTRY/$ECR_REPO_NAME:$GITHUB_SHA" -f "$DOCKER_BUILD_PATH"/"$DOCKERFILE" "$DOCKER_BUILD_PATH"
9+
docker build -t "$ECR_REGISTRY/$ECR_REPO_NAME:$GITHUB_SHA" -f "$DOCKERFILE" "$DOCKER_BUILD_PATH"
1210
docker push "$ECR_REGISTRY/$ECR_REPO_NAME:$GITHUB_SHA"
1311

14-
if [ ${CONTAINER_SIGN_KMS_KEY_ARN} != "none" ]; then
12+
if [[ $CONTAINER_SIGN_KMS_KEY_ARN ]]; then
1513
cosign sign --key "awskms:///${CONTAINER_SIGN_KMS_KEY_ARN}" "$ECR_REGISTRY/$ECR_REPO_NAME:$GITHUB_SHA"
1614
fi
1715

1816
echo "Running sam build on template file"
19-
cd $WORKING_DIRECTORY
20-
sam build --template-file="$TEMPLATE_FILE"
17+
sam build --template-file="$TEMPLATE_FILE" ${SAM_BASE_DIR:+--base-dir=$SAM_BASE_DIR}
2118
mv .aws-sam/build/template.yaml cf-template.yaml
2219

2320
if grep -q "CONTAINER-IMAGE-PLACEHOLDER" cf-template.yaml; then

0 commit comments

Comments
 (0)