commit 1d755899e466da399fc10718574a9555415bbe52 Author: Petr Mrázek Date: Wed Feb 13 23:45:41 2019 +0100 Forked docker-compose config diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..6a7968b --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +.env +*.kdev4 \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..a882a38 --- /dev/null +++ b/README.md @@ -0,0 +1,82 @@ +# MultiMC TeamCity bootstrapping docker thing! +Docker compose config to create working [TeamCity](https://www.jetbrains.com/teamcity/) server with PostgreSQL + +Based on [Egregors/teamcity-docker-compose](https://github.com/Egregors/teamcity-docker-compose) and modified for ... purposes. + +Original license is GPL 3, but this is not interesting for actual redistribution. Go to the original source instead. + +## Configuration + +* Copy `env.example` as `.env`. +* Set a decent Postgres username and password variables in `.env` +* Don't push `.env`, obviously. + +## Startup + +Build images first: + +``` +cd teamcity-docker-compose +docker-compose build +``` + +Then start the service: + +``` +docker-compose up +``` + +After initialisation Web Interface will be available on `https://teamcity.multimc.org/`, provided everything is set up correctly on CF and deth001. + +### Setup DB + +Open `https://teamcity.multimc.org/` + +Set PostgreSQL as database type, upload [JDBC driver](https://jdbc.postgresql.org/download/postgresql-42.2.4.jar) into + `/opt/teamcity/data/lib/jdbc/` then click «Refresh JDBC drivers» + +![Alt text](raw/img/1.png?raw=true) + +Configure DB connection: + +![Alt text](raw/img/2.png?raw=true) + +Authorize your Agent: + +![Alt text](raw/img/3.png?raw=true) + +## Backup / restore + +You may use JetBrains way to [backup](https://confluence.jetbrains.com/display/TCD10/TeamCity+Data+Backup) +or [restore](https://confluence.jetbrains.com/display/TCD10/Restoring+TeamCity+Data+from+Backup) your server + + +## Update + +If you see a notice that a new version is available, you may update your TeamCity that way: + +``` +# build new version +docker-compose build --pull --no-cache + +# stop and remove old containers +docker-compose stop +docker-compose rm + +# create and up new containers +docker-compose up -d +``` + +After an update, you need to reauthorize your agents. + +### Updating maintenance + +Sometimes, during update you may get «maintenance is required» message instead of login page. +It's ok! To login in a maintenance mode you need to enter an authentication token. You may find it in the logs: +`docker-compose logs -f` + +Try to find something like this: + +``` +teamcity-server_1 | [TeamCity] Administrator can login from web UI using authentication token: 8755994969038184734 +``` diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..521ee16 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,23 @@ +version: '2' + +services: + + postgres: + build: ./postgres + volumes: + - "/opt/teamcity/pg_data:/var/lib/postgresql/data" + - "/opt/teamcity/pg_backup:/backups" + env_file: .env + restart: always + + server: + image: jetbrains/teamcity-server:latest + volumes: + - "/opt/teamcity/data:/data/teamcity_server/datadir" + - "/opt/teamcity/logs:/opt/teamcity/logs" + ports: + - 8111:8111 + depends_on: + - postgres + env_file: .env + restart: always diff --git a/env.example b/env.example new file mode 100644 index 0000000..c405bad --- /dev/null +++ b/env.example @@ -0,0 +1,2 @@ +POSTGRES_PASSWORD=mysecretpass +POSTGRES_USER=postgresuser diff --git a/nginx-tc.conf b/nginx-tc.conf new file mode 100644 index 0000000..f3d38da --- /dev/null +++ b/nginx-tc.conf @@ -0,0 +1,34 @@ +# Nginx vhost configuration for TeamCity + +map $http_upgrade $connection_upgrade { # WebSocket support + default upgrade; + '' ''; +} + +server { + server_name teamcity.multimc.org; + listen 80; + + location / { + proxy_pass http://localhost:8111; + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-for $remote_addr; + proxy_set_header X-Forwarded-Proto http; + + proxy_set_header X-Forwarded-Host $http_host; # necessary for proper absolute redirects and TeamCity CSRF check + proxy_set_header Upgrade $http_upgrade; # WebSocket support + proxy_set_header Connection $connection_upgrade; # WebSocket support + + proxy_max_temp_file_size 0; + + proxy_connect_timeout 240; + proxy_send_timeout 300; + proxy_read_timeout 1200; + + proxy_buffer_size 512k; + proxy_buffers 32 4m; + proxy_busy_buffers_size 25m; + proxy_temp_file_write_size 10m; + } +} diff --git a/postgres/Dockerfile b/postgres/Dockerfile new file mode 100644 index 0000000..dbb6712 --- /dev/null +++ b/postgres/Dockerfile @@ -0,0 +1,13 @@ +FROM postgres:9.5 + +# Add backup scripts +ADD backup.sh /usr/local/bin/backup +ADD restore.sh /usr/local/bin/restore +ADD list-backups.sh /usr/local/bin/list-backups + +# Make them executable +RUN chmod +x /usr/local/bin/restore +RUN chmod +x /usr/local/bin/list-backups +RUN chmod +x /usr/local/bin/backup + +COPY set-pg-conf.sh /docker-entrypoint-initdb.d/set-config.sh \ No newline at end of file diff --git a/postgres/backup.sh b/postgres/backup.sh new file mode 100644 index 0000000..97c95e1 --- /dev/null +++ b/postgres/backup.sh @@ -0,0 +1,22 @@ +#!/bin/bash +# stop on errors +set -e + +# we might run into trouble when using the default `postgres` user, e.g. when dropping the postgres +# database in restore.sh. Check that something else is used here +if [ "$POSTGRES_USER" == "postgres" ] +then + echo "creating a backup as the postgres user is not supported, make sure to set the POSTGRES_USER environment variable" + exit 1 +fi + +# export the postgres password so that subsequent commands don't ask for it +export PGPASSWORD=$POSTGRES_PASSWORD + +echo "creating backup" +echo "---------------" + +FILENAME=backup_$(date +'%Y_%m_%dT%H_%M_%S').sql +pg_dump -h postgres -U $POSTGRES_USER >> /backups/$FILENAME + +echo "successfully created backup $FILENAME" diff --git a/postgres/list-backups.sh b/postgres/list-backups.sh new file mode 100644 index 0000000..75972b7 --- /dev/null +++ b/postgres/list-backups.sh @@ -0,0 +1,4 @@ +#!/bin/bash +echo "listing available backups" +echo "-------------------------" +ls /backups/ diff --git a/postgres/restore.sh b/postgres/restore.sh new file mode 100644 index 0000000..7500828 --- /dev/null +++ b/postgres/restore.sh @@ -0,0 +1,56 @@ +#!/bin/bash + +# stop on errors +set -e + +# we might run into trouble when using the default `postgres` user, e.g. when dropping the postgres +# database in restore.sh. Check that something else is used here +if [ "$POSTGRES_USER" == "postgres" ] +then + echo "restoring as the postgres user is not supported, make sure to set the POSTGRES_USER environment variable" + exit 1 +fi + +# export the postgres password so that subsequent commands don't ask for it +export PGPASSWORD=$POSTGRES_PASSWORD + +# check that we have an argument for a filename candidate +if [[ $# -eq 0 ]] ; then + echo 'usage:' + echo ' docker-compose run postgres restore ' + echo '' + echo 'to get a list of available backups, run:' + echo ' docker-compose run postgres list-backups' + exit 1 +fi + +# set the backupfile variable +BACKUPFILE=/backups/$1 + +# check that the file exists +if ! [ -f $BACKUPFILE ]; then + echo "backup file not found" + echo 'to get a list of available backups, run:' + echo ' docker-compose run postgres list-backups' + exit 1 +fi + +echo "beginning restore from $1" +echo "-------------------------" + +# delete the db +# deleting the db can fail. Spit out a comment if this happens but continue since the db +# is created in the next step +echo "deleting old database $POSTGRES_USER" +if dropdb -h postgres -U $POSTGRES_USER $POSTGRES_USER +then echo "deleted $POSTGRES_USER database" +else echo "database $POSTGRES_USER does not exist, continue" +fi + +# create a new database +echo "creating new database $POSTGRES_USER" +createdb -h postgres -U $POSTGRES_USER $POSTGRES_USER -O $POSTGRES_USER + +# restore the database +echo "restoring database $POSTGRES_USER" +psql -h postgres -U $POSTGRES_USER < $BACKUPFILE diff --git a/postgres/set-pg-conf.sh b/postgres/set-pg-conf.sh new file mode 100644 index 0000000..86ca33f --- /dev/null +++ b/postgres/set-pg-conf.sh @@ -0,0 +1,8 @@ +#!/bin/bash + +# Set recommended for TeamCity settings +# https://confluence.jetbrains.com/pages/viewpage.action?pageId=74847395#HowTo...-ConfigureNewlyInstalledPostgreSQLServer +PG_CONF=/var/lib/postgresql/data/postgresql.conf + +grep -q -F 'synchronous_commit=off' $PG_CONF || echo 'synchronous_commit=off' >> $PG_CONF +grep -q -F 'shared_buffers=512MB' $PG_CONF || echo 'shared_buffers=512MB' >> $PG_CONF \ No newline at end of file diff --git a/raw/img/1.png b/raw/img/1.png new file mode 100644 index 0000000..059961f Binary files /dev/null and b/raw/img/1.png differ diff --git a/raw/img/2.png b/raw/img/2.png new file mode 100644 index 0000000..4fc1752 Binary files /dev/null and b/raw/img/2.png differ diff --git a/raw/img/3.png b/raw/img/3.png new file mode 100644 index 0000000..3e8a0e0 Binary files /dev/null and b/raw/img/3.png differ