initial commit, it works!
This commit is contained in:
commit
d8757a3016
1
.dockerignore
Normal file
1
.dockerignore
Normal file
@ -0,0 +1 @@
|
|||||||
|
chantry-perl.tar.bz2
|
5
.gitignore
vendored
Normal file
5
.gitignore
vendored
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
/chantry-website
|
||||||
|
/chantry-ts
|
||||||
|
/hosts
|
||||||
|
/chantry-perl.tar.bz2
|
||||||
|
/users.sql
|
14
Dockerfile
Normal file
14
Dockerfile
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
FROM ubuntu:15.10
|
||||||
|
|
||||||
|
RUN apt-get update && apt-get -y install runit postgresql libpq-dev curl redis-server
|
||||||
|
RUN apt-get update && apt-get -y build-dep perl
|
||||||
|
|
||||||
|
RUN curl -sL https://deb.nodesource.com/setup_5.x | bash -
|
||||||
|
RUN apt-get install -y nodejs
|
||||||
|
|
||||||
|
RUN npm install -g coffee-script
|
||||||
|
|
||||||
|
WORKDIR /app
|
||||||
|
COPY . /app
|
||||||
|
|
||||||
|
CMD /app/run
|
55
README.md
Normal file
55
README.md
Normal file
@ -0,0 +1,55 @@
|
|||||||
|
Run chantry's Twilight Struggle server in Docker. Very nice!
|
||||||
|
|
||||||
|
# Setup
|
||||||
|
|
||||||
|
Clone the `chantry-website` and `chantry-ts` repos from https://bitbucket.org/arry/chantry-website.
|
||||||
|
|
||||||
|
## Bugfix
|
||||||
|
|
||||||
|
You may have to make a small modification to `chantry-website/main/lib/Chantry/WebApp.pm`
|
||||||
|
and `chantry-website/main/templates/games/play.html.tt` if you're unable to
|
||||||
|
load the `ts` module in the browser. Find these lines and change `${game_code}.js`
|
||||||
|
to `${game_code}_bundle.js`:
|
||||||
|
|
||||||
|
```
|
||||||
|
# chantry-website/main/lib/Chantry/WebApp.pm
|
||||||
|
$self->asset("${game_code}.js" => (
|
||||||
|
|
||||||
|
# chantry-website/main/templates/games/play.html.tt
|
||||||
|
[% additional_page_js = "${game_code}.js" %]
|
||||||
|
```
|
||||||
|
|
||||||
|
# Local hacking
|
||||||
|
|
||||||
|
`docker-compose build && docker-compose up`.
|
||||||
|
|
||||||
|
# Deploying
|
||||||
|
|
||||||
|
`REPO=your.docker.registry ./docker-build` will build the app and Perl/PostgreSQL
|
||||||
|
container, push the app container to the registry, and export the data container
|
||||||
|
to a `.tar.bz2` file. You can then use the Ansible playbook to do the deploy to
|
||||||
|
a remote Docker host:
|
||||||
|
|
||||||
|
```
|
||||||
|
REPO=your.docker.registry \
|
||||||
|
EXTERNAL_HOST=www.deployed.location \
|
||||||
|
EXTERNAL_PORT=45678 \
|
||||||
|
ansible-playbook playbook.yml -e with_perl=1 -i hosts
|
||||||
|
```
|
||||||
|
|
||||||
|
Set `with_perl=0` to not push a new Perl/PostgreSQL data container.
|
||||||
|
|
||||||
|
## Adding users
|
||||||
|
|
||||||
|
Generate passwords with `docker exec -i chantry create_pw $password`.
|
||||||
|
Add them to a SQL file (let's say `users.sql`) with this format:
|
||||||
|
|
||||||
|
``` sql
|
||||||
|
INSERT INTO chantry.users (username, password_hash, email)
|
||||||
|
VALUES ('john', 'password-from-create_pw', 'john@example.com');
|
||||||
|
```
|
||||||
|
|
||||||
|
Pipe that file into PostgreSQL:
|
||||||
|
|
||||||
|
`docker exec -i chantry add_users < ./users.sql`
|
||||||
|
|
3
add_users
Executable file
3
add_users
Executable file
@ -0,0 +1,3 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
cat | chpst -u postgres:postgres psql -d chantry -a
|
9
create_pw
Executable file
9
create_pw
Executable file
@ -0,0 +1,9 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
PERL_VERSION=5.22.1
|
||||||
|
|
||||||
|
export PERLBREW_ROOT=/usr/local/perlbrew
|
||||||
|
export PATH=$PERLBREW_ROOT/bin:$PATH
|
||||||
|
|
||||||
|
cd /app/chantry-website/main
|
||||||
|
perlbrew exec --with perl-$PERL_VERSION perl script/bcrypt.pl $1
|
24
docker-build
Executable file
24
docker-build
Executable file
@ -0,0 +1,24 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
set -x
|
||||||
|
set -e
|
||||||
|
|
||||||
|
if [ $(docker ps -a | grep chantry-perl | wc -l) -eq 0 ]; then
|
||||||
|
docker run -v /usr/local/perlbrew -v /var/lib/postgresql/9.4/main --name chantry-perl busybox true
|
||||||
|
else
|
||||||
|
echo "You've got a chantry-perl container already. If you want to rebuild it,"
|
||||||
|
echo "docker rm chantry-perl, then run this script again."
|
||||||
|
fi
|
||||||
|
|
||||||
|
docker build -t $REPO/chantry/app .
|
||||||
|
|
||||||
|
docker run --rm -it --volumes-from chantry-perl busybox rm -f /usr/local/perlbrew/done
|
||||||
|
docker run --rm -it --volumes-from chantry-perl $REPO/chantry/app
|
||||||
|
|
||||||
|
docker push $REPO/chantry/app
|
||||||
|
|
||||||
|
if [ -z $SKIP_PERL ]; then
|
||||||
|
docker run --rm -it --volumes-from chantry-perl \
|
||||||
|
-v $PWD:/backup \
|
||||||
|
busybox tar jcvf /backup/chantry-perl.tar.bz2 /usr/local/perlbrew /var/lib/postgresql/9.4/main
|
||||||
|
fi
|
14
docker-compose.yml
Normal file
14
docker-compose.yml
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
app:
|
||||||
|
build: .
|
||||||
|
container_name: chantry
|
||||||
|
volumes_from:
|
||||||
|
- perl
|
||||||
|
ports:
|
||||||
|
- "3000:3010"
|
||||||
|
environment:
|
||||||
|
EXTERNAL_HOST: '192.168.99.100'
|
||||||
|
perl:
|
||||||
|
image: busybox
|
||||||
|
volumes:
|
||||||
|
- /usr/local/perlbrew
|
||||||
|
- /var/lib/postgresql/9.4/main
|
51
playbook.yml
Normal file
51
playbook.yml
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
- hosts: all
|
||||||
|
become: true
|
||||||
|
become_method: sudo
|
||||||
|
vars:
|
||||||
|
with_perl: "0"
|
||||||
|
tasks:
|
||||||
|
- name: copy up chantry-perl.tar.bz2
|
||||||
|
when: with_perl == "1"
|
||||||
|
copy:
|
||||||
|
src: ./chantry-perl.tar.bz2
|
||||||
|
dest: /tmp/chantry-perl.tar.bz2
|
||||||
|
|
||||||
|
- name: remove existing perl container
|
||||||
|
when: with_perl == "1"
|
||||||
|
command: bash -c 'docker rm chantry-perl ; docker rmi chantry/perl:latest ; true'
|
||||||
|
|
||||||
|
- name: use new perl container
|
||||||
|
when: with_perl == "1"
|
||||||
|
docker:
|
||||||
|
name: chantry-perl
|
||||||
|
image: busybox
|
||||||
|
command: "true"
|
||||||
|
state: present
|
||||||
|
volumes:
|
||||||
|
- /usr/local/perlbrew
|
||||||
|
- /var/lib/postgresql/9.4/main
|
||||||
|
|
||||||
|
- name: import new perl container
|
||||||
|
when: with_perl == "1"
|
||||||
|
command: bash -c 'docker run --rm --volumes-from chantry-perl -v /tmp:/backup busybox tar jxvf /backup/chantry-perl.tar.bz2'
|
||||||
|
|
||||||
|
- name: remove tmp file
|
||||||
|
when: with_perl == "1"
|
||||||
|
file:
|
||||||
|
path: /tmp/chantry-perl.tar.bz2
|
||||||
|
state: absent
|
||||||
|
|
||||||
|
- name: run chantry
|
||||||
|
docker:
|
||||||
|
name: chantry-app
|
||||||
|
image: "{{ lookup('env','REPO') }}/chantry/app:latest"
|
||||||
|
pull: always
|
||||||
|
net: 'host'
|
||||||
|
volumes_from:
|
||||||
|
- 'chantry-perl'
|
||||||
|
ports:
|
||||||
|
- "0.0.0.0:{{ lookup('env','EXTERNAL_PORT') }}:3010"
|
||||||
|
env:
|
||||||
|
EXTERNAL_HOST: "{{ lookup('env','EXTERNAL_HOST') }}:{{ lookup('env','EXTERNAL_PORT')}}"
|
||||||
|
restart_policy: always
|
||||||
|
state: reloaded
|
50
run
Executable file
50
run
Executable file
@ -0,0 +1,50 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
set -x
|
||||||
|
set -e
|
||||||
|
|
||||||
|
PERL_VERSION=5.22.1
|
||||||
|
|
||||||
|
export PERLBREW_ROOT=/usr/local/perlbrew
|
||||||
|
export PATH=$PERLBREW_ROOT/bin:$PATH
|
||||||
|
export CHANTRY_GAME_DIRS=/app/chantry-ts
|
||||||
|
export CHANTRY_WEBSITE_DIRS=/app/chantry-ts
|
||||||
|
|
||||||
|
function as_postgres() {
|
||||||
|
chpst -u postgres:postgres $*
|
||||||
|
}
|
||||||
|
|
||||||
|
chown -R postgres:postgres /app
|
||||||
|
|
||||||
|
#su -c "/usr/lib/postgresql/9.4/bin/postgres -d 3 -D /var/lib/postgresql/9.4/main -c config_file=/etc/postgresql/9.4/main/postgresql.conf 2>&1" postgres
|
||||||
|
if [ ! -f /usr/local/perlbrew/done ]; then
|
||||||
|
curl -L http://install.perlbrew.pl | bash
|
||||||
|
|
||||||
|
perlbrew install perl-$PERL_VERSION || true
|
||||||
|
perlbrew install-cpanm
|
||||||
|
perlbrew exec --with perl-$PERL_VERSION cpanm -f --notest --skip-installed < chantry-website/main/deplist.txt
|
||||||
|
|
||||||
|
chown -R postgres:postgres /var/lib/postgresql/9.4/main
|
||||||
|
as_postgres '/usr/lib/postgresql/9.4/bin/initdb -D /var/lib/postgresql/9.4/main' || true
|
||||||
|
|
||||||
|
/etc/init.d/postgresql stop
|
||||||
|
/etc/init.d/postgresql start
|
||||||
|
|
||||||
|
as_postgres "createdb -O postgres chantry" || true
|
||||||
|
cd chantry-website/main/sqitch
|
||||||
|
as_postgres "/usr/local/perlbrew/bin/perlbrew exec --with perl-$PERL_VERSION sqitch deploy"
|
||||||
|
|
||||||
|
touch /usr/local/perlbrew/done
|
||||||
|
else
|
||||||
|
/etc/init.d/postgresql stop
|
||||||
|
/etc/init.d/postgresql start
|
||||||
|
|
||||||
|
sed -e "s#ws://localhost:3000#ws://${EXTERNAL_HOST}#" < /app/chantry-website/main/chantry-web_app.conf.example > /app/chantry-website/main/chantry-web_app.conf
|
||||||
|
|
||||||
|
cd chantry-website/main
|
||||||
|
|
||||||
|
redis-server &
|
||||||
|
|
||||||
|
chpst -u postgres:postgres /usr/local/perlbrew/bin/perlbrew exec --with perl-$PERL_VERSION .local/start_server &
|
||||||
|
chpst -u postgres:postgres /usr/local/perlbrew/bin/perlbrew exec --with perl-$PERL_VERSION .local/start_worker
|
||||||
|
fi
|
Loading…
Reference in New Issue
Block a user