diff --git a/.gitignore b/.gitignore index f4adbb6..d155dc5 100644 --- a/.gitignore +++ b/.gitignore @@ -350,4 +350,5 @@ MigrationBackup/ .ionide/ # valet files -valet/.env*local +.env*local +credentials_file.yaml \ No newline at end of file diff --git a/gitlab/bootstrap/gitlab.tar.gz b/gitlab/bootstrap/gitlab.tar.gz new file mode 100644 index 0000000..4ad1807 Binary files /dev/null and b/gitlab/bootstrap/gitlab.tar.gz differ diff --git a/gitlab/bootstrap/setup.sh b/gitlab/bootstrap/setup.sh new file mode 100755 index 0000000..b5d55d3 --- /dev/null +++ b/gitlab/bootstrap/setup.sh @@ -0,0 +1,48 @@ +#!/usr/bin/env bash +container_name="gitlab" +tar_file_path="$CODESPACE_VSCODE_FOLDER/gitlab/bootstrap/gitlab.tar.gz" + +if [ ! -d /srv/gitlab ]; then + echo -e "Seeding GitLab data \U1F331" + if [ ! -f $tar_file_path ]; then + echo -e "GitLab data file not found at $tar_file_path.\nPlease verify this file has not been removed\nExiting..." + return + fi + sudo tar -xzf $tar_file_path -C /srv +fi + +echo -e "Checking for GitLab \U1F575" + +if [ "$(docker ps -a | grep $container_name)" ]; then + echo -e "GitLab is running \U1F603" + docker start $container_name +else + echo -e "Starting new GitLab container \U1F4E0" + docker run --detach \ + --hostname 172.17.0.2 \ + --publish 80:80 \ + --name gitlab \ + --restart always \ + --volume /srv/gitlab/config:/etc/gitlab \ + --volume /srv/gitlab/logs:/var/log/gitlab \ + --volume /srv/gitlab/data:/var/opt/gitlab \ + --shm-size 256m \ + gitlab/gitlab-ee:latest + + # updates file permissions to avoid git and server errors + docker exec -it gitlab update-permissions &> /dev/null +fi + +# allow valet to talk to GitLab by removing network isolation between containers +export DOCKER_ARGS="--network=host" +`grep -q "export DOCKER_ARGS=" ~/.bashrc || echo 'export DOCKER_ARGS="--network=host"' >> ~/.bashrc` + +echo -e "Waiting for GitLab to be ready. This might take a while \U23F0" +until $(curl --output /dev/null --silent --head --fail http://localhost); do + printf '.' + sleep 5 +done + +echo -e '\nGitLab is up and running! \U1F680' +echo "Username: root" +docker exec -it $container_name grep 'Password:' /etc/gitlab/initial_root_password \ No newline at end of file diff --git a/gitlab/readme.md b/gitlab/readme.md new file mode 100644 index 0000000..f8ebbc0 --- /dev/null +++ b/gitlab/readme.md @@ -0,0 +1,54 @@ +# Valet labs for GitLab + +This lab bootstraps a Valet environment using GitHub Codespaces and enables you to run the Valet CI/CD migration tool against an isolated GitLab instance running in Docker. + +- [Prerequisites](#prerequisites) +- [Setup Codespace for Labs](#setup-codespace-for-labs) +- [Labs for GitLab](#labs-for-gitlab) + + +## Prerequisites +1. [Valet Labs](https://github.com/valet-customers/labs) template has been used to generate this repository. + +## Setup Codespace for Labs + +1. Start the codespace + - Click the `Code` button down arrow above the repository on the repository's landing page. + - Click the `Codespaces` tab. + - Click `Create codespaces on main` to create the codespace. If you are in another branch then the `main` branch, the codespace button will have the current branch specified. + - Wait a couple minutes, then verify that the codespace starts up. Once it is fully booted up, the terminal should be present. +2. Verify Valet CLI is installed and working. More information on the [GitHub Valet CLI extension](https://github.com/github/gh-valet) + - Run `gh valet version` in the codespace terminal and verify it returns results like below, actual versions will vary. + ``` + gh version 2.14.3 (2022-07-26) + gh valet github/gh-valet v0.1.12 + valet-cli v0.1.0.13392 + ``` + if results do not match try manually installing the valet extension, using the [troubleshooting](#troubleshooting) section. + +3. Run the GitLab setup script. This script will set up GitLab and ensure it is ready to use. In general, this script should be run first if you are starting a new codespace or restarting an existing one. + - from the codespace terminal run `source gitlab/bootstrap/setup.sh`. + +4. Verify you can login to the GitLab Server. + - Click the `PORTS` tab in the codespace terminal window. + - In the row that starts with `80` mouse over the address under the column heading `Local Address`, and click the globe icon. + - Verify a new browser tab opened to the GitLab login screen. + - Login with the username and password printed in the terminal after step 3, if that is not available you can run the command again in the terminal to get it `source gitlab/bootstrap/setup.sh`. + - Verify that you can see the auto populated projects in GitLab, under the `valet` namespace by clicking the `Menu` icon in GitLab, then `Your projects`. + +## Labs for GitLab +Perform the following labs to test-drive Valet +- TBD + +## Troubleshooting +- **GitHub CLI Valet extension is not installed**. More information on the [GitHub Valet CLI extension](https://github.com/github/gh-valet) + - Verify you are in the codespace terminal + - Run `gh extension install github/gh-valet` + - Verify the result of the command is: `✓ Installed extension github/gh-valet` + - If you get a similar error to the following, click the link to authorize the token + ![linktolcickauth](https://user-images.githubusercontent.com/26442605/169588015-9414404f-82b6-4d0f-89d4-5f0e6941b029.png) + - Restart the codespace after clicking the link +- **Port 80 is not being forwarded for GitLab server**. This should be auto detected by codespaces, but can be manually setup by: + - In the codespace terminal click the PORTS tab + - Click the "Add Port" button + - Enter 80 and hit enter