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

Propagate environment #1358 #1392

Merged
merged 27 commits into from
Jan 23, 2024
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
1a44ab3
adds propagate-environment tp pipeline #1358
ajain58 Jan 10, 2024
6fbc631
updates documentation
ajain58 Jan 17, 2024
17077f7
Merge branch 'seek-oss:master' into propagate-environment
ajain58 Jan 17, 2024
1857ca3
Adds back the missing github api token #1358
ajain58 Jan 18, 2024
e779bd7
Update documentation #1358
ajain58 Jan 18, 2024
66222f1
adds missing variables #1358
ajain58 Jan 19, 2024
35044ab
update documentation #1358
ajain58 Jan 19, 2024
0b56846
adds missing env variables #1358
ajain58 Jan 19, 2024
cd5f838
fixes lint and adds changeset #1358
ajain58 Jan 19, 2024
681328d
Merge branch 'master' into propagate-environment
ajain58 Jan 19, 2024
c31aa4b
Merge branch 'master' into propagate-environment
72636c Jan 20, 2024
5dfce6d
Merge branch 'master' into propagate-environment
72636c Jan 20, 2024
413537b
Merge branch 'master' into propagate-environment
ajain58 Jan 22, 2024
de9266b
support alternate repo folder names
samchungy Jan 22, 2024
f4b0a55
Update changeset and documentation
samchungy Jan 23, 2024
61d8499
Update new-crabs-buy.md
samchungy Jan 23, 2024
bbdd178
prettier
samchungy Jan 23, 2024
b0f4f6b
add VERSION environment variable
samchungy Jan 23, 2024
82b0e99
continue to explicitly pass `ENVIRONMENT`
samchungy Jan 23, 2024
1451c3c
pipeline vars get propagated automatically
samchungy Jan 23, 2024
2a81a60
Update pipeline.yml
samchungy Jan 23, 2024
6894985
Update github.md
samchungy Jan 23, 2024
6c3eb22
praise capitalism
samchungy Jan 23, 2024
a224ee3
Update diff
samchungy Jan 23, 2024
51b7fa9
Add one more line to diff
samchungy Jan 23, 2024
50a8f30
Update new-crabs-buy.md
72636c Jan 23, 2024
10ddc21
Update github.md
72636c Jan 23, 2024
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
5 changes: 5 additions & 0 deletions .changeset/new-crabs-buy.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'skuba': patch
---

Updates templates to use propagate-environment for docker-compose plugins
44 changes: 43 additions & 1 deletion docs/deep-dives/github.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,37 @@ steps:
```

With Docker Compose,
declare the environment variables and volume mounts in your [Compose file]:
declare volume mounts in your [Compose file].

You won't need to declare the environment variables in the compose file since `propagate-environment: true` will ensure the variables defined are propagated to the docker environment.

For example, with the [Docker Compose Buildkite plugin], we will need to add the `propagate-environment: true`:

```yaml
steps:
- commands:
- pnpm run lint
- pnpm run test
env:
# At SEEK, this instructs the build agent to populate the GITHUB_API_TOKEN environment variable for this step.
GET_GITHUB_TOKEN: 'please'
plugins:
- *aws-sm
- *private-npm
- *docker-ecr-cache
- docker#v5.0.0:
# Enable GitHub integrations.
environment:
- GITHUB_API_TOKEN
propagate-environment: true
volumes:
# Mount cached dependencies.
- /workdir/node_modules
ajain58 marked this conversation as resolved.
Show resolved Hide resolved
```

And then your [Compose file] will not need to define the `environment` like you had to before to ensure the environment variables are available in Docker

Docker compose file before:
samchungy marked this conversation as resolved.
Show resolved Hide resolved

```yaml
services:
Expand All @@ -61,6 +91,17 @@ services:
- /workdir/node_modules
```

Docker compose file after:

```yaml
services:
app:
volumes:
- ./:/workdir
# Mount cached dependencies.
- /workdir/node_modules
```

If you're running in GitHub Actions,
your workflow will automatically have access to the following environment variables to achieve the same effect:

Expand Down Expand Up @@ -121,6 +162,7 @@ jobs:
[actions/checkout]: https://github.com/actions/checkout
[compose file]: https://docs.docker.com/compose/compose-file
[docker buildkite plugin]: https://github.com/buildkite-plugins/docker-buildkite-plugin
[docker compose buildkite plugin]: https://github.com/buildkite-plugins/docker-compose-buildkite-plugin
[github checks api]: https://docs.github.com/en/rest/reference/checks/
[github.createcheckrun]: ../development-api/github.md#createcheckrun
[will not trigger workflows]: https://docs.github.com/en/actions/using-workflows/triggering-a-workflow#triggering-a-workflow-from-a-workflow
6 changes: 4 additions & 2 deletions scripts/test-template.sh
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,12 @@ EOF

mv "${directory}" "../${directory}"

skuba_dir=$(pwd)

cd "../${directory}" || exit 1

echo "--- pnpm add --save-dev ../skuba/${skuba_tar}"
pnpm add --save-dev "../skuba/${skuba_tar}"
echo "--- pnpm add --save-dev ${skuba_dir}/${skuba_tar}"
pnpm add --save-dev "${skuba_dir}/${skuba_tar}"

echo "--- skuba version ${template}"
pnpm exec skuba version
Expand Down
3 changes: 3 additions & 0 deletions template/express-rest-api/.buildkite/pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ steps:
- *docker-ecr-cache
- docker-compose#v4.16.0:
run: app
environment:
- GITHUB_API_TOKEN
propagate-environment: true
timeout_in_minutes: 10

- label: 📦 Build & Package
Expand Down
10 changes: 0 additions & 10 deletions template/express-rest-api/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,6 @@ version: '3.7'

services:
app:
environment:
# Enable Buildkite + GitHub integrations.
- BUILDKITE
- BUILDKITE_AGENT_ACCESS_TOKEN
- BUILDKITE_BRANCH
- BUILDKITE_BUILD_NUMBER
- BUILDKITE_JOB_ID
- BUILDKITE_PIPELINE_DEFAULT_BRANCH
- BUILDKITE_STEP_ID
- GITHUB_API_TOKEN
ajain58 marked this conversation as resolved.
Show resolved Hide resolved
image: ${BUILDKITE_PLUGIN_DOCKER_IMAGE:-''}
init: true
volumes:
Expand Down
3 changes: 3 additions & 0 deletions template/greeter/.buildkite/pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,7 @@ steps:
- *docker-ecr-cache
- docker-compose#v4.16.0:
run: app
environment:
- GITHUB_API_TOKEN
propagate-environment: true
timeout_in_minutes: 10
10 changes: 0 additions & 10 deletions template/greeter/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,6 @@ version: '3.7'

services:
app:
environment:
# Enable Buildkite + GitHub integrations.
- BUILDKITE
- BUILDKITE_AGENT_ACCESS_TOKEN
- BUILDKITE_BRANCH
- BUILDKITE_BUILD_NUMBER
- BUILDKITE_JOB_ID
- BUILDKITE_PIPELINE_DEFAULT_BRANCH
- BUILDKITE_STEP_ID
- GITHUB_API_TOKEN
image: ${BUILDKITE_PLUGIN_DOCKER_IMAGE:-''}
init: true
volumes:
Expand Down
3 changes: 3 additions & 0 deletions template/koa-rest-api/.buildkite/pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ steps:
- *docker-ecr-cache
- docker-compose#v4.16.0:
run: app
environment:
- GITHUB_API_TOKEN
propagate-environment: true
timeout_in_minutes: 10

- label: 📦 Build & Package
Expand Down
10 changes: 0 additions & 10 deletions template/koa-rest-api/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,6 @@ version: '3.7'

services:
app:
environment:
# Enable Buildkite + GitHub integrations.
- BUILDKITE
- BUILDKITE_AGENT_ACCESS_TOKEN
- BUILDKITE_BRANCH
- BUILDKITE_BUILD_NUMBER
- BUILDKITE_JOB_ID
- BUILDKITE_PIPELINE_DEFAULT_BRANCH
- BUILDKITE_STEP_ID
- GITHUB_API_TOKEN
image: ${BUILDKITE_PLUGIN_DOCKER_IMAGE:-''}
init: true
volumes:
Expand Down
10 changes: 10 additions & 0 deletions template/lambda-sqs-worker-cdk/.buildkite/pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ configs:
- docker-compose#v4.16.0:
dependencies: false
run: app
environment:
- ENVIRONMENT
- GITHUB_API_TOKEN
- VERSION
propagate-environment: true
retry:
manual:
# Only use this if you need to roll back a deployment ASAP.
Expand All @@ -56,6 +61,11 @@ steps:
- *docker-ecr-cache
- docker-compose#v4.16.0:
run: app
environment:
- ENVIRONMENT
- GITHUB_API_TOKEN
ajain58 marked this conversation as resolved.
Show resolved Hide resolved
- VERSION
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any ideas where VERSION comes from? @72636c. I can see ENVIRONMENT in the UI so it will get propagated successfully by the propagate-environment setting.

Copy link
Contributor

@samchungy samchungy Jan 23, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

VERSION: ${BUILDKITE_COMMIT:0:7}.${BUILDKITE_BUILD_NUMBER}

Is this template meant to have this line?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah yes, I think that's right re: VERSION. Maybe we should extend the CDK template to use the version variable too

CDK

const logger = createLogger({
name: '<%- serviceName %>',
});

Serverless

version: Env.string('VERSION'),

base: {
environment: config.environment,
version: config.version,
},

propagate-environment: true
timeout_in_minutes: 10

- agents:
Expand Down
15 changes: 0 additions & 15 deletions template/lambda-sqs-worker-cdk/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,6 @@ version: '3.7'

services:
app:
environment:
# Enable Buildkite + GitHub integrations.
- BUILDKITE
- BUILDKITE_AGENT_ACCESS_TOKEN
- BUILDKITE_BRANCH
- BUILDKITE_BUILD_NUMBER
- BUILDKITE_JOB_ID
- BUILDKITE_PIPELINE_DEFAULT_BRANCH
- BUILDKITE_STEP_ID
- GITHUB_API_TOKEN
# Tag AWS resources with the commit hash.
- BUILDKITE_COMMIT
# Pass through application configuration.
- ENVIRONMENT
- VERSION
image: ${BUILDKITE_PLUGIN_DOCKER_IMAGE:-''}
init: true
volumes:
Expand Down
6 changes: 6 additions & 0 deletions template/lambda-sqs-worker/.buildkite/pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ configs:
- docker-compose#v4.16.0:
dependencies: false
run: app
propagate-environment: true
retry:
manual:
# Only use this if you need to roll back a deployment ASAP.
Expand Down Expand Up @@ -65,6 +66,11 @@ steps:
- *docker-ecr-cache
- docker-compose#v4.16.0:
run: app
environment:
- ENVIRONMENT
- GITHUB_API_TOKEN
ajain58 marked this conversation as resolved.
Show resolved Hide resolved
- VERSION
propagate-environment: true
timeout_in_minutes: 10

- agents:
Expand Down
15 changes: 0 additions & 15 deletions template/lambda-sqs-worker/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,6 @@ version: '3.7'

services:
app:
environment:
# Enable Buildkite + GitHub integrations.
- BUILDKITE
- BUILDKITE_AGENT_ACCESS_TOKEN
- BUILDKITE_BRANCH
- BUILDKITE_BUILD_NUMBER
- BUILDKITE_JOB_ID
- BUILDKITE_PIPELINE_DEFAULT_BRANCH
- BUILDKITE_STEP_ID
- GITHUB_API_TOKEN
# Tag AWS resources with the commit hash.
- BUILDKITE_COMMIT
# Pass through application configuration.
- ENVIRONMENT
- VERSION
ajain58 marked this conversation as resolved.
Show resolved Hide resolved
image: ${BUILDKITE_PLUGIN_DOCKER_IMAGE:-''}
init: true
volumes:
Expand Down