diff --git a/Dockerfile.test b/Dockerfile.test deleted file mode 100644 index 790517a5..00000000 --- a/Dockerfile.test +++ /dev/null @@ -1,7 +0,0 @@ -FROM gitlab/gitlab-ce:latest - -COPY docker-entrypoint.sh /usr/local/bin/ - -RUN chmod +x /usr/local/bin/docker-entrypoint.sh - -CMD ["/usr/local/bin/docker-entrypoint.sh"] diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh deleted file mode 100755 index eb528c8e..00000000 --- a/docker-entrypoint.sh +++ /dev/null @@ -1,27 +0,0 @@ -#!/bin/sh -#https://gitlab.com/gitlab-org/omnibus-gitlab/blob/10-8-stable/docker/assets/wrapper - -exec /assets/wrapper - -gitlab-ctl stop - -gitlab-rails console - -# ## Reset default password for root user -# u = User.first -# u.password_automatically_set = false -# u.password = 'password' -# u.password_confirmation = 'password' -# u.save! - -# ## Create access token -# t = PersonalAccessToken.new({ user: u, name: 'node-gitlab', scopes: ['api']}) -# t.save! - -# ## Store access token in an ENV -# ENV['PERSONAL_ACCESS_TOKEN'] = t.token - -# ## Exist rails console -exit - -## Exec any other entry point logic \ No newline at end of file diff --git a/docker-compose.test.yml b/test/docker-compose.test.yml similarity index 62% rename from docker-compose.test.yml rename to test/docker-compose.test.yml index ee26b5ee..66f3f961 100644 --- a/docker-compose.test.yml +++ b/test/docker-compose.test.yml @@ -3,7 +3,7 @@ services: gitlab: image: gitlab/gitlab-ce container_name: gitlab - command: sh -c ./docker-entrypoint.sh + entrypoint: init/docker-entrypoint environment: - GITLAB_URL='http://localhost:8080' - PERSONAL_ACCESS_TOKEN='token' @@ -11,4 +11,6 @@ services: - 8080:80 - 8443:443 volumes: - - ./docker-entrypoint.sh:/docker-entrypoint.sh \ No newline at end of file + - ./docker-entrypoint:/init/docker-entrypoint + - ./init:/init/init + - ./test.rb:/init/test.rb \ No newline at end of file diff --git a/test/docker-entrypoint b/test/docker-entrypoint new file mode 100755 index 00000000..0173f414 --- /dev/null +++ b/test/docker-entrypoint @@ -0,0 +1,14 @@ +#!/bin/bash + +## Running the init logic for gitlab. See PR# for splitting this wrapper file into two pieces +/bin/bash init/init + +echo Sleep for 30 seconds to ensure all services are running +sleep 30 + +echo Initalize test token and user +PERSONAL_ACCESS_TOKEN="$(gitlab-rails r /init/test.rb)" + +echo Tail and wait +gitlab-ctl tail& +wait \ No newline at end of file diff --git a/test/init b/test/init new file mode 100644 index 00000000..75b69065 --- /dev/null +++ b/test/init @@ -0,0 +1,101 @@ +#!/bin/bash +set -e + +function sigterm_handler() { + echo "SIGTERM signal received, try to gracefully shutdown all services..." + gitlab-ctl stop +} + +function failed_pg_upgrade() { + echo 'Upgrading the existing database to 9.6 failed and was reverted.' + echo 'Please check the output, and open an issue at:' + echo 'https://gitlab.com/gitlab-org/omnibus-gitlab/issues' + echo 'If you would like to restart the instance without attempting to' + echo 'upgrade, add the following to your docker command:' + echo '-e GITLAB_SKIP_PG_UPGRADE=true' + exit 1 +} + +trap "sigterm_handler; exit" TERM + +source /RELEASE +echo "Thank you for using GitLab Docker Image!" +echo "Current version: $RELEASE_PACKAGE=$RELEASE_VERSION" +echo "" +if [[ "$PACKAGECLOUD_REPO" == "unstable" ]]; then + echo "You are using UNSTABLE version of $RELEASE_PACKAGE!" + echo "" +fi +echo "Configure GitLab for your system by editing /etc/gitlab/gitlab.rb file" +echo "And restart this container to reload settings." +echo "To do it use docker exec:" +echo +echo " docker exec -it gitlab vim /etc/gitlab/gitlab.rb" +echo " docker restart gitlab" +echo +echo "For a comprehensive list of configuration options please see the Omnibus GitLab readme" +echo "https://gitlab.com/gitlab-org/omnibus-gitlab/blob/master/README.md" +echo +echo "If this container fails to start due to permission problems try to fix it by executing:" +echo +echo " docker exec -it gitlab update-permissions" +echo " docker restart gitlab" +echo +sleep 3s + +# Copy gitlab.rb for the first time +if [[ ! -e /etc/gitlab/gitlab.rb ]]; then + echo "Installing gitlab.rb config..." + cp /opt/gitlab/etc/gitlab.rb.template /etc/gitlab/gitlab.rb + chmod 0600 /etc/gitlab/gitlab.rb +fi + +# Generate ssh host key for the first time +if [[ ! -f /etc/gitlab/ssh_host_rsa_key ]]; then + echo "Generating ssh_host_rsa_key..." + ssh-keygen -f /etc/gitlab/ssh_host_rsa_key -N '' -t rsa + chmod 0600 /etc/gitlab/ssh_host_rsa_key +fi +if [[ ! -f /etc/gitlab/ssh_host_ecdsa_key ]]; then + echo "Generating ssh_host_ecdsa_key..." + ssh-keygen -f /etc/gitlab/ssh_host_ecdsa_key -N '' -t ecdsa + chmod 0600 /etc/gitlab/ssh_host_ecdsa_key +fi +if [[ ! -f /etc/gitlab/ssh_host_ed25519_key ]]; then + echo "Generating ssh_host_ed25519_key..." + ssh-keygen -f /etc/gitlab/ssh_host_ed25519_key -N '' -t ed25519 + chmod 0600 /etc/gitlab/ssh_host_ed25519_key +fi + +# Remove all services, the reconfigure will create them +echo "Preparing services..." +rm -f /opt/gitlab/service/* +ln -s /opt/gitlab/sv/sshd /opt/gitlab/service +ln -sf /opt/gitlab/embedded/bin/sv /opt/gitlab/init/sshd +mkdir -p /var/log/gitlab/sshd + +# Start service manager +echo "Starting services..." +GITLAB_OMNIBUS_CONFIG= /opt/gitlab/embedded/bin/runsvdir-start & + +# Configure gitlab package +# WARNING: +# the preinst script has the database backup +# It will not be executed, because all services are not yet started +# They will be started when `reconfigure` is executed +echo "Configuring GitLab package..." +/var/lib/dpkg/info/${RELEASE_PACKAGE}.preinst upgrade + +echo "Configuring GitLab..." +gitlab-ctl reconfigure + +# Make sure PostgreSQL is at the latest version. +# If it fails, print a message with a workaround and exit +if [ "${GITLAB_SKIP_PG_UPGRADE}" != true ]; then + gitlab-ctl pg-upgrade -w || failed_pg_upgrade +fi + +if [ -n "${GITLAB_POST_RECONFIGURE_SCRIPT+x}" ]; then + echo "Runnning Post Reconfigure Script..." + eval "${GITLAB_POST_RECONFIGURE_SCRIPT}" +fi \ No newline at end of file diff --git a/test/test.rb b/test/test.rb new file mode 100644 index 00000000..23c1947e --- /dev/null +++ b/test/test.rb @@ -0,0 +1,11 @@ +#!/usr/bin/env ruby +u = User.first +u.password_automatically_set = false +u.password = 'password' +u.password_confirmation = 'password' +u.save! + +t = PersonalAccessToken.new({ user: u, name: 'node-gitlab', scopes: ['api']}) +t.save! + +puts t.token \ No newline at end of file diff --git a/tests/bundles/GroupsBundle.js b/test/tests/bundles/GroupsBundle.js similarity index 100% rename from tests/bundles/GroupsBundle.js rename to test/tests/bundles/GroupsBundle.js diff --git a/tests/bundles/ProjectsBundle.js b/test/tests/bundles/ProjectsBundle.js similarity index 100% rename from tests/bundles/ProjectsBundle.js rename to test/tests/bundles/ProjectsBundle.js diff --git a/tests/bundles/UsersBundle.js b/test/tests/bundles/UsersBundle.js similarity index 100% rename from tests/bundles/UsersBundle.js rename to test/tests/bundles/UsersBundle.js diff --git a/tests/infrastructure/BaseService.js b/test/tests/infrastructure/BaseService.js similarity index 100% rename from tests/infrastructure/BaseService.js rename to test/tests/infrastructure/BaseService.js diff --git a/tests/infrastructure/Bundle.js b/test/tests/infrastructure/Bundle.js similarity index 100% rename from tests/infrastructure/Bundle.js rename to test/tests/infrastructure/Bundle.js diff --git a/tests/services/Projects.js b/test/tests/services/Projects.js similarity index 100% rename from tests/services/Projects.js rename to test/tests/services/Projects.js