Skip to content

Commit 7040b4c

Browse files
committed
chore(ci): fix travis tests
1 parent e45a6e2 commit 7040b4c

File tree

6 files changed

+155
-3
lines changed

6 files changed

+155
-3
lines changed

.travis.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,14 @@ env:
88
- TOX_ENV=cli_func_v4
99
install:
1010
- pip install tox
11+
before_script:
12+
## Spin up container
13+
- cd tools/
14+
- docker-compose -f docker-compose.test.yml up -d
15+
- sleep 260
16+
- export PERSONAL_ACCESS_TOKEN=$(docker exec -it gitlab bash -lc 'printf "%q" "${PERSONAL_ACCESS_TOKEN}"')
17+
- export GITLAB_URL=$(docker exec -it gitlab bash -lc 'printf "%q" "${GITLAB_URL}"')
18+
- echo $GITLAB_URL
19+
- echo $PERSONAL_ACCESS_TOKEN
1120
script:
1221
- tox -e $TOX_ENV

tools/build_test_env.sh

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,6 @@ cleanup() {
7676
trap 'exit 1' HUP INT TERM
7777
}
7878

79-
try docker run --name gitlab-test --detach --publish 8080:80 \
80-
--publish 2222:22 pythongitlab/test-python-gitlab:latest >/dev/null
81-
8279
LOGIN='root'
8380
PASSWORD='5iveL!fe'
8481
GITLAB() { gitlab --config-file "$CONFIG" "$@"; }

tools/docker-compose.test.yml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
version: '3'
2+
services:
3+
gitlab:
4+
image: gitlab/gitlab-ce
5+
container_name: gitlab
6+
entrypoint: init/docker-entrypoint
7+
environment:
8+
- EXTERNAL_PORT=8080
9+
- PERSONAL_ACCESS_TOKEN
10+
ports:
11+
- 8080:80
12+
- 8443:443
13+
volumes:
14+
- ./docker-entrypoint:/init/docker-entrypoint
15+
- ./init:/init/init
16+
- ./test.rb:/init/test.rb

tools/docker-entrypoint

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/bin/bash
2+
3+
## Running the init logic for gitlab. See PR# for splitting this wrapper file into two pieces
4+
/bin/bash init/init
5+
6+
echo Sleep for 30 seconds to ensure all services are running
7+
sleep 30
8+
9+
echo Initalize test token and user
10+
PERSONAL_ACCESS_TOKEN="$(gitlab-rails r /init/test.rb)"
11+
GITLAB_URL="http://localhost:$EXTERNAL_PORT"
12+
13+
echo "export PERSONAL_ACCESS_TOKEN=$PERSONAL_ACCESS_TOKEN" >> ~/.profile
14+
echo "export GITLAB_URL=$GITLAB_URL" >> ~/.profile
15+
16+
echo Tail and wait
17+
gitlab-ctl tail&
18+
wait

tools/init

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
#!/bin/bash
2+
set -e
3+
4+
function sigterm_handler() {
5+
echo "SIGTERM signal received, try to gracefully shutdown all services..."
6+
gitlab-ctl stop
7+
}
8+
9+
function failed_pg_upgrade() {
10+
echo 'Upgrading the existing database to 9.6 failed and was reverted.'
11+
echo 'Please check the output, and open an issue at:'
12+
echo 'https://gitlab.com/gitlab-org/omnibus-gitlab/issues'
13+
echo 'If you would like to restart the instance without attempting to'
14+
echo 'upgrade, add the following to your docker command:'
15+
echo '-e GITLAB_SKIP_PG_UPGRADE=true'
16+
exit 1
17+
}
18+
19+
trap "sigterm_handler; exit" TERM
20+
21+
source /RELEASE
22+
echo "Thank you for using GitLab Docker Image!"
23+
echo "Current version: $RELEASE_PACKAGE=$RELEASE_VERSION"
24+
echo ""
25+
if [[ "$PACKAGECLOUD_REPO" == "unstable" ]]; then
26+
echo "You are using UNSTABLE version of $RELEASE_PACKAGE!"
27+
echo ""
28+
fi
29+
echo "Configure GitLab for your system by editing /etc/gitlab/gitlab.rb file"
30+
echo "And restart this container to reload settings."
31+
echo "To do it use docker exec:"
32+
echo
33+
echo " docker exec -it gitlab vim /etc/gitlab/gitlab.rb"
34+
echo " docker restart gitlab"
35+
echo
36+
echo "For a comprehensive list of configuration options please see the Omnibus GitLab readme"
37+
echo "https://gitlab.com/gitlab-org/omnibus-gitlab/blob/master/README.md"
38+
echo
39+
echo "If this container fails to start due to permission problems try to fix it by executing:"
40+
echo
41+
echo " docker exec -it gitlab update-permissions"
42+
echo " docker restart gitlab"
43+
echo
44+
sleep 3s
45+
46+
# Copy gitlab.rb for the first time
47+
if [[ ! -e /etc/gitlab/gitlab.rb ]]; then
48+
echo "Installing gitlab.rb config..."
49+
cp /opt/gitlab/etc/gitlab.rb.template /etc/gitlab/gitlab.rb
50+
chmod 0600 /etc/gitlab/gitlab.rb
51+
fi
52+
53+
# Generate ssh host key for the first time
54+
if [[ ! -f /etc/gitlab/ssh_host_rsa_key ]]; then
55+
echo "Generating ssh_host_rsa_key..."
56+
ssh-keygen -f /etc/gitlab/ssh_host_rsa_key -N '' -t rsa
57+
chmod 0600 /etc/gitlab/ssh_host_rsa_key
58+
fi
59+
if [[ ! -f /etc/gitlab/ssh_host_ecdsa_key ]]; then
60+
echo "Generating ssh_host_ecdsa_key..."
61+
ssh-keygen -f /etc/gitlab/ssh_host_ecdsa_key -N '' -t ecdsa
62+
chmod 0600 /etc/gitlab/ssh_host_ecdsa_key
63+
fi
64+
if [[ ! -f /etc/gitlab/ssh_host_ed25519_key ]]; then
65+
echo "Generating ssh_host_ed25519_key..."
66+
ssh-keygen -f /etc/gitlab/ssh_host_ed25519_key -N '' -t ed25519
67+
chmod 0600 /etc/gitlab/ssh_host_ed25519_key
68+
fi
69+
70+
# Remove all services, the reconfigure will create them
71+
echo "Preparing services..."
72+
rm -f /opt/gitlab/service/*
73+
ln -s /opt/gitlab/sv/sshd /opt/gitlab/service
74+
ln -sf /opt/gitlab/embedded/bin/sv /opt/gitlab/init/sshd
75+
mkdir -p /var/log/gitlab/sshd
76+
77+
# Start service manager
78+
echo "Starting services..."
79+
GITLAB_OMNIBUS_CONFIG= /opt/gitlab/embedded/bin/runsvdir-start &
80+
81+
# Configure gitlab package
82+
# WARNING:
83+
# the preinst script has the database backup
84+
# It will not be executed, because all services are not yet started
85+
# They will be started when `reconfigure` is executed
86+
echo "Configuring GitLab package..."
87+
/var/lib/dpkg/info/${RELEASE_PACKAGE}.preinst upgrade
88+
89+
echo "Configuring GitLab..."
90+
gitlab-ctl reconfigure
91+
92+
# Make sure PostgreSQL is at the latest version.
93+
# If it fails, print a message with a workaround and exit
94+
if [ "${GITLAB_SKIP_PG_UPGRADE}" != true ]; then
95+
gitlab-ctl pg-upgrade -w || failed_pg_upgrade
96+
fi
97+
98+
if [ -n "${GITLAB_POST_RECONFIGURE_SCRIPT+x}" ]; then
99+
echo "Runnning Post Reconfigure Script..."
100+
eval "${GITLAB_POST_RECONFIGURE_SCRIPT}"
101+
fi

tools/test.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/usr/bin/env ruby
2+
u = User.first
3+
u.password_automatically_set = false
4+
u.password = 'password'
5+
u.password_confirmation = 'password'
6+
u.save!
7+
8+
t = PersonalAccessToken.new({ user: u, name: 'node-gitlab', scopes: ['api']})
9+
t.save!
10+
11+
puts t.token

0 commit comments

Comments
 (0)