I’m working on a project that automates the creation of a project’s build box, including the setup of GitLab CE with sample projects. I’m facing a variety of challenges
- Question 1 -
Is there a way to initialize the root admin account through the CLI? Per issue 1980 (https://gitlab.com/gitlab-org/gitlab-ce/issues/1980) it looks as if the default login credentials are no longer available. I need this as I’m setting up GitLab as part of the initialization of a build box and wouldn’t have logged in to GitLab yet.
- Question 2 -
I need to initialize SSH keys as part of the startup of my GitLab instance, but I have not found any details on how to do this.
- Scripts -
Here are the scripts of what I’m trying to do:
docker-compose.yml
version: '2'
services:
registry:
restart: always
image: registry:2
ports:
- 5000:5000
networks:
- front-tier
- back-tier
gitlab:
build: ./gitlab
image: mycompany/gitlab
ports:
- "10080:80"
- "10022:22"
networks:
- front-tier
- back-tier
environment:
- TZ=America/Chicago
- GITLAB_TIMEZONE=Chicago
- GITLAB_SECRETS_DB_KEY_BASE=NmVlNmUzM2ZlYmFlYWQ2YjUxNzJmNmE2MG
- GITLAB_HOST=localhost
- GITLAB_PORT=10080
- GITLAB_SSH_PORT=10022
- GITLAB_NOTIFY_ON_BROKEN_BUILDS=true
- GITLAB_NOTIFY_PUSHER=false
- GITLAB_EMAIL=operator@localhost
- GITLAB_EMAIL_REPLY_TO=noreply@localhost
- GITLAB_INCOMING_EMAIL_ADDRESS=reply@localhost
- GITLAB_BACKUPS=daily
- GITLAB_BACKUP_TIME=01:00
- SMTP_ENABLED=false
- SMTP_DOMAIN=localdomain
- SMTP_HOST=localhost
- SMTP_PORT=587
- SMTP_USER=postmaster@localhost
- SMTP_PASS=password
- SMTP_STARTTLS=true
- SMTP_AUTHENTICATION=login
- IMAP_ENABLED=false
- IMAP_HOST=localhost
- IMAP_PORT=993
- IMAP_USER=postmaster@localhost
- IMAP_PASS=password
- IMAP_SSL=true
- IMAP_STARTTLS=false
volumes:
- gitlab-config-data:/etc/gitlab
- gitlab-logs-data:/var/opt/gitlab/postgresql/data
- gitlab-data:/var/opt/gitlab/git-data
restart: always
volumes:
gitlab-config-data:
driver: local
gitlab-logs-data:
driver: local
gitlab-data:
driver: local
networks:
front-tier:
driver: bridge
back-tier:
driver: bridge
Dockerfile
FROM gitlab/gitlab-ce:latest
RUN apt-get update \
&& apt-get install -y sudo
COPY ./run.sh /assets/run.sh
COPY ./data /tmp/config/
COPY ./projects /tmp/projects/
RUN chmod +x /assets/run.sh
CMD "./assets/run.sh"
run.sh
#!/bin/bash
# Initialize configuration files if not already done
if [ ! -f /etc/gitlab/ssh_host_ed25519_key.pub ]; then
cp -r /tmp/config/* /etc/gitlab
chmod 600 /etc/gitlab/ssh_*_key
fi
# Start the app in the background, we need to have postgres running.
/assets/wrapper &
# Wait for it to start up.
sleep 2m
# If no repos exist, pre-populate
if [[ ! $(gitlab-rake gitlab:list_repos) ]]; then
# Configure up git
git config --global user.email "info@nvisia.com"
git config --global user.name "root"
# Work in the tmp folder
cd /tmp/projects
chmod 777 *.tar
# Create group repo directory
mkdir /var/opt/gitlab/git-data/repositories/nvisia
# Create the four project directories
mkdir /var/opt/gitlab/git-data/repositories/nvisia/hello-world-pipeline.git
mkdir /var/opt/gitlab/git-data/repositories/nvisia/hello-world-service.git
mkdir /var/opt/gitlab/git-data/repositories/nvisia/hello-world-ui.git
mkdir /var/opt/gitlab/git-data/repositories/nvisia/hello-world-util.git
# Set ownership to git and rights to folders
chown -R git:git /var/opt/gitlab/git-data/repositories
chmod -R ug+rwX,o-rwx /var/opt/gitlab/git-data/repositories
# Import the bare repos into GitLab
gitlab-rake gitlab:import:repos
gitlab-rake gitlab:import:all_users_to_all_groups
gitlab-rake gitlab:import:all_users_to_all_projects
# Clone each repo, add the files and commit up.
git clone http://root:password@localhost/nvisia/hello-world-pipeline.git
tar -xvf hello-world-pipeline.tar
cd /tmp/projects/hello-world-pipeline
git add .
git commit -m "Initial Project"
git push -u origin master
fi
wait