Skip to content

Commit 6d1c8d1

Browse files
authored
Merge pull request #9 from commitdev/template-values-instead-of-env-vars
Template most values instead of using env vars for anything not secre…
2 parents 0b53ae6 + 05fc2f3 commit 6d1c8d1

File tree

2 files changed

+27
-30
lines changed

2 files changed

+27
-30
lines changed

.circleci/README.md

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,12 @@
55
### Requirements
66

77
Requires you to configure the below [CircleCI Environment Variables](https://circleci.com/docs/2.0/env-vars/):
8-
To get your ECR repositories and EKS clusters:
9-
```shell
10-
$ aws ecr describe-repositories --query "repositories[].repositoryUri"
11-
$ aws eks list-clusters --query "clusters"
12-
```
138

14-
- AWS_ACCESS_KEY_ID # AWS access key for the circleci user - this should be in AWS secret manager
15-
- AWS_SECRET_ACCESS_KEY # AWS secret for the circleci user - this should be in AWS secret manager
16-
- AWS_REGION # Region of your EKS cluster
17-
- AWS_ECR_ACCOUNT_URL # {awsAccountNum}.dkr.ecr.{region}.amazonaws.com
18-
- AWS_ECR_REPO_NAME # The ECR repository name to write images to
19-
- PRODUCTION_EKS_CLUSTER_NAME # The name of the production EKS cluster to deploy into
20-
- STAGING_EKS_CLUSTER_NAME # The name of the staging EKS cluster to deploy into
21-
- AWS_CLUSTER_AUTH_ROLE_ARN_STAGING # The ARN of the role to assume that allows access to the EK cluster. Most likely ends with `kubernetes-admin-staging`
22-
- AWS_CLUSTER_AUTH_ROLE_ARN_PRODUCTION # The ARN of the role to assume that allows access to the EKS cluster. Same as above but for production
23-
- SLACK_WEBHOOK # Webhook for slack notifications. Must be specified, but doesn't need to be set to a real value
24-
- CIRCLECI_API_KEY # Needed for the queueing orb. You can generate this in the project settings in CircleCI. It needs the `status` scope.
9+
- AWS_ACCESS_KEY_ID # AWS access key for the circleci user - this should be in AWS secret manager
10+
- AWS_SECRET_ACCESS_KEY # AWS secret for the circleci user - this should be in AWS secret manager
11+
- CIRCLECI_API_KEY # Needed for the queueing orb. You can generate this in the project settings in CircleCI. It needs the `status` scope.
12+
13+
- SLACK_WEBHOOK # Webhook for slack notifications. Must only be specified if you uncomment `slack/notify-on-failure`
2514

2615

2716
## Deployment Process

.circleci/config.yml

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -133,19 +133,25 @@ jobs:
133133
- store_artifacts:
134134
path: test-reports
135135

136-
# Requires the SLACK_WEBHOOK
137-
- slack/notify-on-failure
136+
# Requires the SLACK_WEBHOOK env var to be set
137+
#- slack/notify-on-failure
138138

139139
build_and_push:
140140
machine:
141141
docker_layer_caching: false # only for performance plan circleci accounts
142+
parameters:
143+
repo:
144+
type: string
145+
default: ''
146+
description: |
147+
The name of the ECR repo to push an image to.
142148
steps:
143149
- attach_workspace:
144150
at: *workspace
145151
- run: *checkout-shallow
146152
- version-tag/create
147153
- aws-ecr/build-and-push-image:
148-
repo: ${AWS_ECR_REPO_NAME}
154+
repo: << parameters.repo >>
149155
tag: $VERSION_TAG,latest
150156

151157
deploy:
@@ -192,9 +198,10 @@ jobs:
192198
- run: *checkout-shallow
193199
- version-tag/get
194200
- run: *install-binaries
201+
- run: # Required by aws-cli
202+
command: echo 'export AWS_DEFAULT_REGION=<< parameters.region >>' >> $BASH_ENV
195203
- aws-cli/install
196-
- aws-cli/setup:
197-
aws-region: AWS_REGION
204+
- aws-cli/setup
198205
- aws-eks/update-kubeconfig-with-authenticator:
199206
cluster-name: << parameters.cluster-name >>
200207
cluster-authentication-role-arn: << parameters.cluster-authentication-role-arn >>
@@ -207,7 +214,7 @@ jobs:
207214
command: |
208215
kubectl create namespace << parameters.namespace >> || echo "Namespace already exists"
209216
cd kubernetes/overlays/<< parameters.config-environment >>
210-
IMAGE=${AWS_ECR_ACCOUNT_URL}/<< parameters.repo >>
217+
IMAGE=<% index .Params `accountId` %>.dkr.ecr.<< parameters.region >>.amazonaws.com/<< parameters.repo >>
211218
kustomize edit set image fake-image=${IMAGE}:${VERSION_TAG}
212219
kustomize build . | kubectl apply -f - -n << parameters.namespace >>
213220
workflows:
@@ -222,6 +229,7 @@ workflows:
222229
- checkout_code
223230

224231
- build_and_push:
232+
repo: <% .Name %>
225233
requires:
226234
- unit_test
227235
filters:
@@ -231,11 +239,11 @@ workflows:
231239

232240
- deploy:
233241
name: deploy_staging
234-
repo: "${AWS_ECR_REPO_NAME}"
235-
cluster-name: "${STAGING_EKS_CLUSTER_NAME}"
242+
repo: "<% .Name %>"
243+
cluster-name: "<% .Name %>-staging-<% index .Params `region` %>"
236244
config-environment: "staging"
237-
cluster-authentication-role-arn: "${AWS_CLUSTER_AUTH_ROLE_ARN_STAGING}"
238-
region: "${AWS_REGION}"
245+
cluster-authentication-role-arn: "arn:aws:iam::<% index .Params `accountId` %>:role/<% .Name %>-kubernetes-admin-staging"
246+
region: "<% index .Params `region` %>"
239247
namespace: "<% .Name %>"
240248
tag: "${VERSION_TAG}"
241249
requires:
@@ -253,11 +261,11 @@ workflows:
253261

254262
- deploy:
255263
name: deploy_production
256-
repo: "${AWS_ECR_REPO_NAME}"
257-
cluster-name: "${PRODUCTION_EKS_CLUSTER_NAME}"
264+
repo: "<% .Name %>"
265+
cluster-name: "<% .Name %>-staging-<% index .Params `region` %>"
258266
config-environment: "production"
259-
cluster-authentication-role-arn: "${AWS_CLUSTER_AUTH_ROLE_ARN_PRODUCTION}"
260-
region: "${AWS_REGION}"
267+
cluster-authentication-role-arn: "arn:aws:iam::<% index .Params `accountId` %>:role/<% .Name %>-kubernetes-admin-production"
268+
region: "<% index .Params `region` %>"
261269
namespace: "<% .Name %>"
262270
tag: "${VERSION_TAG}"
263271
requires:

0 commit comments

Comments
 (0)