Skip to content

Commit e156398

Browse files
authored
Merge pull request #745 from spack/gitlab-dev-environment
Add GitLab + GitLab Runner to dev environment
2 parents 3b2b28f + 6f673de commit e156398

File tree

5 files changed

+110
-4
lines changed

5 files changed

+110
-4
lines changed

analytics/README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ This is the simplest configuration for developers to start with.
77
1. Run `docker-compose run --rm django ./manage.py migrate`
88
2. Run `docker-compose run --rm django ./manage.py createsuperuser`
99
and follow the prompts to create your own user
10+
3. Run `dev/init-gitlab.sh` to initialize your GitLab instance root
11+
password, register a runner, and bootstrap a `spack` repo.
1012

1113

1214
### Run Application
@@ -40,6 +42,8 @@ but allows developers to run Python code on their native system.
4042
6. Run `source ./dev/export-env.sh`
4143
7. Run `./manage.py migrate`
4244
8. Run `./manage.py createsuperuser` and follow the prompts to create your own user
45+
9. Run `dev/init-gitlab.sh` to initialize your GitLab instance root
46+
password, register a runner, and bootstrap a `spack` repo.
4347

4448
### Run Application
4549
1. Ensure `docker-compose -f ./docker-compose.yml up -d` is still active

analytics/dev/.env.docker-compose

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ OPENSEARCH_ENDPOINT=http://elasticsearch:9200
88
OPENSEARCH_USERNAME=elastic
99
OPENSEARCH_PASSWORD=elastic
1010
SECRET_KEY=deadbeef
11-
GITLAB_ENDPOINT="http://fakeurl"
12-
GITLAB_TOKEN="bar"
11+
GITLAB_ENDPOINT="http://gitlab/"
12+
GITLAB_TOKEN="insecure_token"
1313
GITLAB_DB_USER=gitlab
1414
GITLAB_DB_HOST=gitlab-db
1515
GITLAB_DB_PORT=5432

analytics/dev/.env.docker-compose-native

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ CELERY_BROKER_URL=redis://localhost:6379/
77
OPENSEARCH_ENDPOINT=http://localhost:9200
88
OPENSEARCH_USERNAME=elastic
99
OPENSEARCH_PASSWORD=elastic
10-
GITLAB_ENDPOINT=http://fakegitlab
11-
GITLAB_TOKEN=glpat-fakegitlab
10+
GITLAB_ENDPOINT=http://localhost:8080/
11+
GITLAB_TOKEN=insecure_token
1212
GITLAB_DB_USER=gitlab
1313
GITLAB_DB_HOST=localhost
1414
GITLAB_DB_PORT=5433

analytics/dev/init-gitlab.sh

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
#!/bin/bash
2+
set -euo pipefail
3+
4+
# Wait for gitlab to be up
5+
echo "Waiting for GitLab..."
6+
until curl -s -f -o /dev/null "http://localhost:8080"
7+
do
8+
sleep 5
9+
done
10+
echo "Done."
11+
12+
# Set root user password + create a personal access token for it
13+
PERSONAL_ACCESS_TOKEN="insecure_token"
14+
docker compose exec gitlab gitlab-rails runner " \
15+
print 'Updating root user password...'; \
16+
user = User.find_by(username: 'root'); \
17+
user.password = user.password_confirmation = 'deadbeef'; \
18+
user.save!; \
19+
puts ' done'; \
20+
print 'Creating personal access token...'; \
21+
token = User.find_by_username('root').personal_access_tokens.create( \
22+
scopes: [:api], \
23+
name: 'Docker admin token', \
24+
expires_at: 365.days.from_now, \
25+
); \
26+
token.set_token('$PERSONAL_ACCESS_TOKEN'); \
27+
token.save!; \
28+
puts ' done';"
29+
30+
# Create a new runner via the GitLab API and save its token
31+
RUNNER_TOKEN=$(docker compose exec gitlab curl \
32+
--silent \
33+
--request POST \
34+
--url "http://localhost/api/v4/user/runners" \
35+
--data "runner_type=instance_type" \
36+
--data "description=test" \
37+
--data "tag_list=test" \
38+
--header "PRIVATE-TOKEN: $PERSONAL_ACCESS_TOKEN" | jq -r '.token')
39+
40+
# Register the containerized gitlab runner using the previously acquired token
41+
docker compose exec gitlab-runner gitlab-runner register \
42+
--non-interactive \
43+
--description "docker-runner" \
44+
--url "http://gitlab/" \
45+
--token "$RUNNER_TOKEN" \
46+
--executor "docker" \
47+
--docker-volumes=/var/run/docker.sock:/var/run/docker.sock \
48+
--docker-image=docker:20-dind
49+
50+
# Create a new project
51+
docker compose exec gitlab curl \
52+
--request POST \
53+
--url "http://localhost/api/v4/projects" \
54+
--header "PRIVATE-TOKEN: $PERSONAL_ACCESS_TOKEN" \
55+
--header "Content-Type: application/json" \
56+
--data '{"name": "spack", "path": "spack"}'
57+
58+
# Push spack github repo to the new project
59+
docker compose exec gitlab bash -c " \
60+
git clone https://github.com/spack/spack.git && \
61+
cd spack && \
62+
git remote add gitlab http://root:deadbeef@localhost/root/spack.git && \
63+
git push -u gitlab develop"

analytics/docker-compose.yml

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,45 @@ services:
4242
POSTGRES_USER: gitlab
4343
POSTGRES_PASSWORD: gitlab
4444

45+
gitlab:
46+
image: zengxs/gitlab:ee
47+
ports:
48+
- "8080:80"
49+
- "8081:443"
50+
environment:
51+
GITLAB_OMNIBUS_CONFIG: |
52+
external_url 'http://gitlab'
53+
gitlab_rails['db_host'] = 'gitlab-db'
54+
gitlab_rails['db_port'] = '5432'
55+
gitlab_rails['db_username'] = 'gitlab'
56+
gitlab_rails['db_password'] = 'gitlab'
57+
depends_on:
58+
- gitlab-db
59+
60+
gitlab-runner:
61+
image: gitlab/gitlab-runner:latest
62+
volumes:
63+
- /var/run/docker.sock:/var/run/docker.sock
64+
depends_on:
65+
- gitlab
66+
- dind
67+
environment:
68+
DOCKER_HOST: tcp://dind:2375
69+
# Use the host's network interface instead of the Docker one.
70+
# Note, gitlab-runner runs jobs inside docker, but is itself deployed
71+
# in a docker container. So the "host" in this case actually refers to the
72+
# `gitlab-runner` docker container defined in this docker-compose.yaml.
73+
DOCKER_NETWORK_MODE: host
74+
75+
dind:
76+
image: docker:20-dind
77+
restart: always
78+
privileged: true
79+
environment:
80+
DOCKER_TLS_CERTDIR: ""
81+
command:
82+
- --storage-driver=overlay2
83+
4584
volumes:
4685
postgres:
4786
gitlab-db:

0 commit comments

Comments
 (0)