Skip to content

Commit 3b5ead3

Browse files
Restructure gitlab-ci to remove ephemeral instances, and make token mandatory.
1 parent 594c3d5 commit 3b5ead3

1 file changed

Lines changed: 10 additions & 68 deletions

File tree

src/content/docs/aws/ci-pipelines/gitlab-ci.md

Lines changed: 10 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -18,25 +18,26 @@ You must always use `privileged = true` in your GitLab CI's `config.toml` file w
1818
For more information, see [GitLab CI Docker-in-Docker](https://docs.gitlab.com/ee/ci/docker/using_docker_build.html#use-docker-in-docker-executor) documentation.
1919
:::
2020

21+
LocalStack requires a [CI Auth Token](https://app.localstack.cloud/workspace/auth-tokens), which you must add to the repository's environment variables as `LOCALSTACK_AUTH_TOKEN`.
22+
Go to your project's **Settings > CI/CD** and expand the **Variables** section.
23+
Select the **Add Variable** button and fill in the necessary details with `LOCALSTACK_AUTH_TOKEN` as the key and your CI Auth Token as the value.
24+
After you create the variable, you can use it in the `.gitlab-ci.yml` file.
2125

22-
<details>
23-
<summary>For LocalStack versions before 3.0.0</summary>
24-
Under test>variables, add:<br>
25-
LOCALSTACK_HOSTNAME: localhost.localstack.cloud<br>
26-
HOSTNAME_EXTERNAL: localhost.localstack.cloud.
27-
</details>
26+
However, variables set in the GitLab UI are not automatically passed down to service containers.
27+
You need to assign them as variables in the UI, and then re-assign them in your `.gitlab-ci.yml`.
2828

2929
#### Service
3030

3131
```yaml showshowLineNumbers
3232
...
3333
variables:
34+
LOCALSTACK_AUTH_TOKEN: $LOCALSTACK_AUTH_TOKEN
3435
DOCKER_SOCK: tcp://docker:2375
3536
DOCKER_HOST: tcp://docker:2375
3637
DOCKER_TLS_CERTDIR: ""
3738
...
3839
services:
39-
- name: localstack/localstack:latest
40+
- name: localstack/localstack-pro:latest
4041
alias: localstack
4142
- name: docker:dind
4243
alias: docker
@@ -56,6 +57,7 @@ job:
5657
stage: job
5758
variables:
5859
...
60+
LOCALSTACK_AUTH_TOKEN: $LOCALSTACK_AUTH_TOKEN
5961
DOCKER_HOST: tcp://docker:2375
6062
DOCKER_TLS_CERTDIR: ""
6163
AWS_ENDPOINT_URL: "http://localhost.localstack.cloud:4566"
@@ -71,33 +73,12 @@ job:
7173
- apk add gcc musl-dev linux-headers py3-pip python3 python3-dev
7274
- python3 -m pip install localstack awscli
7375
script:
74-
- docker pull localstack/localstack:latest
76+
- docker pull localstack/localstack-pro:latest
7577
- dind_ip="$(getent hosts docker | cut -d' ' -f1)"
7678
- echo "${dind_ip} localhost.localstack.cloud " >> /etc/hosts
7779
- DOCKER_HOST="tcp://${dind_ip}:2375" localstack start -d
7880
```
7981
80-
### Configure a CI Auth Token
81-
82-
You can easily enable LocalStack for AWS by using the `localstack/localstack-pro` image and adding your [CI Auth Token](https://app.localstack.cloud/workspace/auth-tokens) to the repository's environment variables as `LOCALSTACK_AUTH_TOKEN`.
83-
Go to your project's **Settings > CI/CD** and expand the **Variables** section.
84-
Select the **Add Variable** button and fill in the necessary details with `LOCALSTACK_AUTH_TOKEN` as the key and your CI Auth Token as the value.
85-
After you create the variable, you can use it in the `.gitlab-ci.yml` file.
86-
87-
However, variables set in the GitLab UI are not automatically passed down to service containers.
88-
You need to assign them as variables in the UI, and then re-assign them in your `.gitlab-ci.yml`.
89-
90-
```yaml showshowLineNumbers
91-
...
92-
variables:
93-
LOCALSTACK_AUTH_TOKEN: $LOCALSTACK_AUTH_TOKEN
94-
...
95-
services:
96-
- name: localstack/localstack-pro:latest
97-
alias: localstack
98-
...
99-
```
100-
10182
You can check the logs of the LocalStack container to see if the activation was successful.
10283
If the CI Auth Token activation fails, LocalStack container will exit with an error code.
10384
@@ -176,45 +157,6 @@ job:
176157

177158
Find more information about cloud pods [here](/aws/developer-tools/snapshots/cloud-pods).
178159

179-
#### Ephemeral Instance (Preview)
180-
181-
```yaml showshowLineNumbers
182-
...
183-
variables:
184-
LOCALSTACK_AUTH_TOKEN: $LOCALSTACK_AUTH_TOKEN
185-
...
186-
setup-job:
187-
stage: build
188-
before_script:
189-
- |
190-
response=$(curl -X POST -d '{"auto_load_pod": "false"}' \
191-
-H 'ls-api-key: $LOCALSTACK_API_KEY' \
192-
-H 'authorization: token $LOCALSTACK_API_KEY' \
193-
-H 'content-type: application/json' \
194-
https://api.localstack.cloud/v1/previews/my-gitlab-state)
195-
196-
if [ "$endpointUrl" = "null" ] || [ "$endpointUrl" = "" ]; then
197-
echo "Unable to create preview environment. API response: $response"
198-
exit 1
199-
fi
200-
echo "Created preview environment with endpoint URL: $endpointUrl"
201-
202-
echo "export AWS_ENDPOINT_URL=$endpointUrl"
203-
echo "$AWS_ENDPOINT_URL" >> ls-endpoint.env
204-
...
205-
artifacts:
206-
reports:
207-
dotenv: ls-endpoint.env
208-
209-
test-job:
210-
stage: test
211-
script:
212-
- echo "$AWS_ENDPOINT_URL" # Output is the address of the ephemeral instance
213-
...
214-
```
215-
216-
Find out more about ephemeral instances [here](/aws/developer-tools/cloud-sandbox/ephemeral-instances).
217-
218160
## Current Limitations
219161

220162
- Localstack must be able to reach a docker socket to provision containers for certain services, ie Lambda, EKS, ECS...etc

0 commit comments

Comments
 (0)