Forked docker-compose config

This commit is contained in:
Petr Mrázek 2019-02-13 23:45:41 +01:00
commit 1d755899e4
13 changed files with 246 additions and 0 deletions

2
.gitignore vendored Normal file
View file

@ -0,0 +1,2 @@
.env
*.kdev4

82
README.md Normal file
View file

@ -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
```

23
docker-compose.yml Normal file
View file

@ -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

2
env.example Normal file
View file

@ -0,0 +1,2 @@
POSTGRES_PASSWORD=mysecretpass
POSTGRES_USER=postgresuser

34
nginx-tc.conf Normal file
View file

@ -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;
}
}

13
postgres/Dockerfile Normal file
View file

@ -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

22
postgres/backup.sh Normal file
View file

@ -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"

4
postgres/list-backups.sh Normal file
View file

@ -0,0 +1,4 @@
#!/bin/bash
echo "listing available backups"
echo "-------------------------"
ls /backups/

56
postgres/restore.sh Normal file
View file

@ -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 <backup-file>'
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

8
postgres/set-pg-conf.sh Normal file
View file

@ -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

BIN
raw/img/1.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 139 KiB

BIN
raw/img/2.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 86 KiB

BIN
raw/img/3.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 32 KiB