From ed3daf0a1dfc92f3b4698444380004ab54aef208 Mon Sep 17 00:00:00 2001 From: Mike VanDenburgh Date: Fri, 19 Jan 2024 00:48:14 -0500 Subject: [PATCH 1/7] Run GitLab in local dev environment --- analytics/docker-compose.yml | 39 ++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/analytics/docker-compose.yml b/analytics/docker-compose.yml index ddb93934c..a2ce250b3 100644 --- a/analytics/docker-compose.yml +++ b/analytics/docker-compose.yml @@ -42,6 +42,45 @@ services: POSTGRES_USER: gitlab POSTGRES_PASSWORD: gitlab + gitlab: + image: gitlab/gitlab-ee:latest + ports: + - "8080:80" + - "8081:443" + environment: + GITLAB_OMNIBUS_CONFIG: | + external_url 'http://gitlab' + gitlab_rails['db_host'] = 'gitlab-db' + gitlab_rails['db_port'] = '5432' + gitlab_rails['db_username'] = 'gitlab' + gitlab_rails['db_password'] = 'gitlab' + depends_on: + - gitlab-db + + gitlab-runner: + image: gitlab/gitlab-runner:latest + volumes: + - /var/run/docker.sock:/var/run/docker.sock + depends_on: + - gitlab + - dind + environment: + DOCKER_HOST: tcp://dind:2375 + # Use the host's network interface instead of the Docker one. + # Note, gitlab-runner runs jobs inside docker, but is itself deployed + # in a docker container. So the "host" in this case actually refers to the + # `gitlab-runner` docker container defined in this docker-compose.yaml. + DOCKER_NETWORK_MODE: host + + dind: + image: docker:20-dind + restart: always + privileged: true + environment: + DOCKER_TLS_CERTDIR: "" + command: + - --storage-driver=overlay2 + volumes: postgres: gitlab-db: From 3a59af7b3827d73cc88581a5ef5fd39bccee10c3 Mon Sep 17 00:00:00 2001 From: Mike VanDenburgh Date: Fri, 19 Jan 2024 00:49:07 -0500 Subject: [PATCH 2/7] Add script to bootstrap gitlab dev instance --- analytics/dev/init-gitlab.sh | 54 ++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100755 analytics/dev/init-gitlab.sh diff --git a/analytics/dev/init-gitlab.sh b/analytics/dev/init-gitlab.sh new file mode 100755 index 000000000..5976e4956 --- /dev/null +++ b/analytics/dev/init-gitlab.sh @@ -0,0 +1,54 @@ +#!/bin/bash + +# Set root user password + create a personal access token for it +PERSONAL_ACCESS_TOKEN="insecure_token" +docker compose exec gitlab gitlab-rails runner " \ + print 'Updating root user password...'; \ + user = User.find_by(username: 'root'); \ + user.password = user.password_confirmation = 'deadbeef'; \ + user.save!; \ + puts ' done'; \ + print 'Creating personal access token...'; \ + token = User.find_by_username('root').personal_access_tokens.create( \ + scopes: [:api], \ + name: 'Docker admin token', \ + expires_at: 365.days.from_now, \ + ); \ + token.set_token('$PERSONAL_ACCESS_TOKEN'); \ + token.save!; \ + puts ' done';" + +# Create a new runner via the GitLab API and save its token +RUNNER_TOKEN=$(docker compose exec gitlab curl \ + --silent \ + --request POST \ + --url "http://localhost/api/v4/user/runners" \ + --data "runner_type=instance_type" \ + --data "description=test" \ + --data "tag_list=test" \ + --header "PRIVATE-TOKEN: $PERSONAL_ACCESS_TOKEN" | jq -r '.token') + +# Register the containerized gitlab runner using the previously acquired token +docker compose exec gitlab-runner gitlab-runner register \ + --non-interactive \ + --description "docker-runner" \ + --url "http://gitlab/" \ + --token "$RUNNER_TOKEN" \ + --executor "docker" \ + --docker-volumes=/var/run/docker.sock:/var/run/docker.sock \ + --docker-image=docker:20-dind + +# Create a new project +docker compose exec gitlab curl \ + --request POST \ + --url "http://localhost/api/v4/projects" \ + --header "PRIVATE-TOKEN: $PERSONAL_ACCESS_TOKEN" \ + --header "Content-Type: application/json" \ + --data '{"name": "spack", "path": "spack"}' + +# Push spack github repo to the new project +docker compose exec gitlab bash -c " \ + git clone https://github.com/spack/spack.git && \ + cd spack && \ + git remote add gitlab http://root:deadbeef@localhost/root/spack.git && \ + git push -u gitlab develop" From 8dbc05f22927ae2127a8e0f8900a9f74bdc3278c Mon Sep 17 00:00:00 2001 From: Mike VanDenburgh Date: Thu, 25 Jan 2024 12:12:04 -0500 Subject: [PATCH 3/7] Add info to README --- analytics/README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/analytics/README.md b/analytics/README.md index c4ff8c65a..a4bf7fa75 100644 --- a/analytics/README.md +++ b/analytics/README.md @@ -7,6 +7,8 @@ This is the simplest configuration for developers to start with. 1. Run `docker-compose run --rm django ./manage.py migrate` 2. Run `docker-compose run --rm django ./manage.py createsuperuser` and follow the prompts to create your own user +3. Run `dev/init-gitlab.sh` to initialize your GitLab instance root + password, register a runner, and bootstrap a `spack` repo. ### Run Application @@ -40,6 +42,8 @@ but allows developers to run Python code on their native system. 6. Run `source ./dev/export-env.sh` 7. Run `./manage.py migrate` 8. Run `./manage.py createsuperuser` and follow the prompts to create your own user +9. Run `dev/init-gitlab.sh` to initialize your GitLab instance root + password, register a runner, and bootstrap a `spack` repo. ### Run Application 1. Ensure `docker-compose -f ./docker-compose.yml up -d` is still active From 29b772309caf29b6f294cbabd188eda87a2e5dfe Mon Sep 17 00:00:00 2001 From: Mike VanDenburgh Date: Thu, 25 Jan 2024 16:08:09 -0500 Subject: [PATCH 4/7] Update gitlab docker env vars --- analytics/dev/.env.docker-compose | 4 ++-- analytics/dev/.env.docker-compose-native | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/analytics/dev/.env.docker-compose b/analytics/dev/.env.docker-compose index c14ff7ef4..37583733e 100644 --- a/analytics/dev/.env.docker-compose +++ b/analytics/dev/.env.docker-compose @@ -8,8 +8,8 @@ OPENSEARCH_ENDPOINT=http://elasticsearch:9200 OPENSEARCH_USERNAME=elastic OPENSEARCH_PASSWORD=elastic SECRET_KEY=deadbeef -GITLAB_ENDPOINT="http://fakeurl" -GITLAB_TOKEN="bar" +GITLAB_ENDPOINT="http://gitlab/" +GITLAB_TOKEN="insecure_token" GITLAB_DB_USER=gitlab GITLAB_DB_HOST=gitlab-db GITLAB_DB_PORT=5432 diff --git a/analytics/dev/.env.docker-compose-native b/analytics/dev/.env.docker-compose-native index 29aea260f..218f508ad 100644 --- a/analytics/dev/.env.docker-compose-native +++ b/analytics/dev/.env.docker-compose-native @@ -7,8 +7,8 @@ CELERY_BROKER_URL=redis://localhost:6379/ OPENSEARCH_ENDPOINT=http://localhost:9200 OPENSEARCH_USERNAME=elastic OPENSEARCH_PASSWORD=elastic -GITLAB_ENDPOINT=http://fakegitlab -GITLAB_TOKEN=glpat-fakegitlab +GITLAB_ENDPOINT=http://localhost:8080/ +GITLAB_TOKEN=insecure_token GITLAB_DB_USER=gitlab GITLAB_DB_HOST=localhost GITLAB_DB_PORT=5433 From c01fdf7f96b99d55cfedd11937347861ca0fc7a8 Mon Sep 17 00:00:00 2001 From: Mike VanDenburgh <37340715+mvandenburgh@users.noreply.github.com> Date: Fri, 26 Jan 2024 13:23:08 -0500 Subject: [PATCH 5/7] Add wait to init script --- analytics/dev/init-gitlab.sh | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/analytics/dev/init-gitlab.sh b/analytics/dev/init-gitlab.sh index 5976e4956..d6feac271 100755 --- a/analytics/dev/init-gitlab.sh +++ b/analytics/dev/init-gitlab.sh @@ -1,5 +1,13 @@ #!/bin/bash +# Wait for gitlab to be up +echo "Waiting for GitLab..." +until curl -s -f -o /dev/null "http://localhost:8080" +do + sleep 5 +done +echo "Done." + # Set root user password + create a personal access token for it PERSONAL_ACCESS_TOKEN="insecure_token" docker compose exec gitlab gitlab-rails runner " \ From 706678b6b9f619f0752daeb0cb5378e6c5ad6d2e Mon Sep 17 00:00:00 2001 From: Dan LaManna Date: Wed, 7 Feb 2024 23:54:12 -0500 Subject: [PATCH 6/7] Add error handling to init-gitlab.sh --- analytics/dev/init-gitlab.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/analytics/dev/init-gitlab.sh b/analytics/dev/init-gitlab.sh index d6feac271..63838281a 100755 --- a/analytics/dev/init-gitlab.sh +++ b/analytics/dev/init-gitlab.sh @@ -1,4 +1,5 @@ #!/bin/bash +set -euo pipefail # Wait for gitlab to be up echo "Waiting for GitLab..." From 6f673dec568c866d1efe77b89749db1512f29163 Mon Sep 17 00:00:00 2001 From: Dan LaManna Date: Wed, 7 Feb 2024 23:54:51 -0500 Subject: [PATCH 7/7] Use arm64-compatible docker image for gitlab --- analytics/docker-compose.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/analytics/docker-compose.yml b/analytics/docker-compose.yml index a2ce250b3..95883e66d 100644 --- a/analytics/docker-compose.yml +++ b/analytics/docker-compose.yml @@ -43,7 +43,7 @@ services: POSTGRES_PASSWORD: gitlab gitlab: - image: gitlab/gitlab-ee:latest + image: zengxs/gitlab:ee ports: - "8080:80" - "8081:443"