Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add secrets env vars to build workflow #68

Merged
merged 1 commit into from
Jun 19, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 17 additions & 6 deletions .github/workflows/build_docker_image_and_push_to_ecr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ on:
setNodeVersion:
description: Put NODE_VERSION from path/to/.nvmrc to docker build args
required: false
type: string
type: boolean
default: true
nvmrcPath:
description: Path to nvmrc file
Expand Down Expand Up @@ -68,6 +68,11 @@ on:
npmToken:
description: Put NPM_TOKEN to docker build args
required: false
buildSecretEnvVars:
description: |
Secrets passed to build as secret file.
See https://docs.docker.com/engine/reference/commandline/buildx_build/#secret
required: false

env:
AWS_ACCESS_KEY_ID: ${{ secrets.awsAccessKeyId }}
Expand Down Expand Up @@ -120,7 +125,7 @@ jobs:

- name: clone repository
uses: actions/checkout@v3

- name: set docker build args and secrets
run: |
BUILD_ARGS=${{ inputs.dockerBuildArgs }}
Expand All @@ -132,13 +137,18 @@ jobs:
echo -e ${BUILD_ARGS} >> $GITHUB_ENV
echo 'EOF' >> $GITHUB_ENV

# Create secret file for build
if [ ! -z "${{ secrets.buildSecretEnvVars }}" ]; then
echo "${{ secrets.buildSecretEnvVars }}" | tr ',' '\n' > build-secret-env-vars.txt
fi

# NOTE: can be useful
# - name: Set up QEMU
# uses: docker/setup-qemu-action@v2

- name: setup Docker Buildx
uses: docker/setup-buildx-action@v2

- name: login to AWS ECR
uses: docker/login-action@v2
with:
Expand All @@ -154,6 +164,7 @@ jobs:
file: ${{ inputs.dockerFilePath }}
push: true
tags: ${{ inputs.registry }}/${{ inputs.repository }}:${{ inputs.imageTag }}
secret-files: SECRET_ENV_VARS=build-secret-env-vars.txt
build-args: |
${{ env.BUILD_ARGS }}
NPM_TOKEN=${{ secrets.npmToken }}
Expand All @@ -170,7 +181,7 @@ jobs:
echo "color=#ff0000" >> $GITHUB_OUTPUT
echo "emoji=red_circle" >> $GITHUB_OUTPUT
fi

- name: send result to slack
if: always() && inputs.slackChannelId != ''
uses: slackapi/[email protected]
Expand Down Expand Up @@ -209,4 +220,4 @@ jobs:
]
}
]
}
}