[minor] build standalone instance into Docker container

This commit is contained in:
Julien Vehent 2017-03-07 11:43:06 -05:00
Родитель e008e5fd93
Коммит 3130486a34
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: A3D652173B763E8F
4 изменённых файлов: 63 добавлений и 14 удалений

Просмотреть файл

@ -1,17 +1,12 @@
language: go language: go
go: go:
- 1.7.3 - 1.8
addons: addons:
postgresql: "9.4" postgresql: "9.4"
notifications: notifications:
irc: irc:
channels: channels:
- "irc.mozilla.org#mig" - "irc.mozilla.org#mig"
email:
recipients:
- ulfr@mozilla.com
on_success: never
on_failure: always
before_install: before_install:
# this is a fix to get rng-tools to work in travis-ci # this is a fix to get rng-tools to work in travis-ci
- sudo apt-get update -qq - sudo apt-get update -qq
@ -33,6 +28,18 @@ script:
- diff client/mig/available_modules.go conf/available_modules.go - diff client/mig/available_modules.go conf/available_modules.go
- sed -i 's,//_,_,' conf/available_modules.go - sed -i 's,//_,_,' conf/available_modules.go
- make - make
- yes | bash tools/standalone_install.sh - docker build -t mozilla/mig .
- ./bin/linux/amd64/mig-agent-latest -i actions/example_v2.json - ./bin/linux/amd64/mig-agent-latest -i actions/example_v2.json
- ./bin/linux/amd64/mig scribe -t all -z -path actions/scribe/usn-2015.json -onlytrue -human - ./bin/linux/amd64/mig scribe -t all -z -path actions/scribe/usn-2015.json -onlytrue -human
# If a TRAVIS_TAG is set, this build follows a git tag --push and should trigger
# a release of a tagged container to dockerhub. Otherwise, we tag as latest.
- |
docker login -e $DOCKER_EMAIL -u $DOCKER_USER -p $DOCKER_PASS
if [ ! -z "$TRAVIS_TAG" ]; then
docker tag app:build mozilla/mig:${TRAVIS_TAG}
docker push mozilla/mig:${TRAVIS_TAG}
else
docker tag app:build mozilla/mig:latest
docker push mozilla/mig:latest
fi
docker logout

22
Dockerfile Normal file
Просмотреть файл

@ -0,0 +1,22 @@
FROM golang:1.8
MAINTAINER Mozilla
RUN apt update && \
apt install sudo && \
echo '%mig ALL=(ALL:ALL) NOPASSWD:ALL' > /etc/sudoers.d/mig && \
addgroup --gid 10001 mig && \
adduser --gid 10001 --uid 10001 \
--home /mig \
--disabled-password mig
ADD . /go/src/mig.ninja/mig
RUN chown mig /go -R
USER mig
RUN cd /go/src/mig.ninja/mig && \
yes | bash ./tools/standalone_install.sh && \
cp /go/src/mig.ninja/mig/tools/standalone_start_all.sh /mig/start.sh && \
chmod +x /mig/start.sh
WORKDIR /mig
CMD /mig/start.sh && /bin/bash

Просмотреть файл

@ -140,6 +140,16 @@ sudo chown mig /usr/local/bin/mig || fail
sudo chmod 555 /usr/local/bin/mig || fail sudo chmod 555 /usr/local/bin/mig || fail
echo -e "\n---- Building Database\n" echo -e "\n---- Building Database\n"
sudo service postgresql restart
# wait for db to start
pgstarted=0
for i in $(seq 1 30); do
echo -n '.'
sleep 1
[ -S /var/run/postgresql/.s.PGSQL.5432 ] && pgstarted=1 && break
done
[ $pgstarted -eq 1 ] || fail
cd database/ cd database/
dbpass=$(cat /dev/urandom | tr -dc _A-Z-a-z-0-9 | head -c${1:-32}) dbpass=$(cat /dev/urandom | tr -dc _A-Z-a-z-0-9 | head -c${1:-32})
sudo su - postgres -c "psql -c 'drop database mig'" sudo su - postgres -c "psql -c 'drop database mig'"
@ -161,10 +171,10 @@ sudo chown mig /var/cache/mig -R || fail
sudo chown mig /etc/mig || fail sudo chown mig /etc/mig || fail
echo -e "\n---- Configuring RabbitMQ\n" echo -e "\n---- Configuring RabbitMQ\n"
(ps faux|grep "/var/lib/rabbitmq"|grep -v grep) 2>&1 1> /dev/null
if [ $? -gt 0 ]; then echo 'NODENAME=rabbit@localhost' > /etc/rabbitmq/rabbitmq-env.conf
sudo service rabbitmq-server restart || fail sudo service rabbitmq-server restart || fail
fi
mqpass=$(cat /dev/urandom | tr -dc _A-Z-a-z-0-9 | head -c${1:-32}) mqpass=$(cat /dev/urandom | tr -dc _A-Z-a-z-0-9 | head -c${1:-32})
sudo rabbitmqctl delete_user admin sudo rabbitmqctl delete_user admin
sudo rabbitmqctl add_user admin $mqpass || fail sudo rabbitmqctl add_user admin $mqpass || fail
@ -226,8 +236,8 @@ echo OK
echo -e "\n---- Starting Scheduler and API in TMUX under mig user\n" echo -e "\n---- Starting Scheduler and API in TMUX under mig user\n"
sudo su mig -c "/usr/bin/tmux new-session -s 'mig' -d" sudo su mig -c "/usr/bin/tmux new-session -s 'mig' -d"
sudo su mig -c "/usr/bin/tmux new-window -t 'mig' -n '0' '/usr/local/bin/mig-scheduler'" sudo su mig -c "/usr/bin/tmux new-window -t 'mig' -n '0' '/usr/local/bin/mig-scheduler'"
sudo su mig -c "/usr/bin/tmux new-window -t 'mig' -n '0' '/usr/local/bin/mig-api'" sudo su mig -c "/usr/bin/tmux new-window -t 'mig' -n '1' '/usr/local/bin/mig-api'"
sudo su mig -c "/usr/bin/tmux new-window -t 'mig' -n '0' '/usr/local/bin/mig_agent_verif_worker'" sudo su mig -c "/usr/bin/tmux new-window -t 'mig' -n '2' '/usr/local/bin/mig_agent_verif_worker'"
echo OK echo OK
# Unset proxy related environment variables from this point on, since we want to ensure we are # Unset proxy related environment variables from this point on, since we want to ensure we are
@ -339,7 +349,7 @@ make mig-agent AGTCONF=conf/mig-agent-conf.go BUILDENV=demo || fail
sudo cp bin/linux/amd64/mig-agent-latest /sbin/mig-agent || fail sudo cp bin/linux/amd64/mig-agent-latest /sbin/mig-agent || fail
sudo chown root /sbin/mig-agent || fail sudo chown root /sbin/mig-agent || fail
sudo chmod 500 /sbin/mig-agent || fail sudo chmod 500 /sbin/mig-agent || fail
sudo /sbin/mig-agent sudo su mig -c "/usr/bin/tmux new-window -t 'mig' -n '2' 'sudo /sbin/mig-agent -d'"
sleep 5 sleep 5
/usr/local/bin/mig -i actions/integration_tests.json /usr/local/bin/mig -i actions/integration_tests.json

Просмотреть файл

@ -0,0 +1,10 @@
#!/usr/bin/env bash
sudo service rabbitmq-server restart
sudo service postgresql restart
sleep 10
sudo tmux -S /tmp/tmux-$(id -u mig)/default kill-session -t mig || echo "OK - No running MIG session found"
tmux new-session -s 'mig' -d
tmux new-window -t 'mig' -n '0' '/usr/local/bin/mig-scheduler'
tmux new-window -t 'mig' -n '1' '/usr/local/bin/mig-api'
tmux new-window -t 'mig' -n '2' 'sudo /sbin/mig-agent -d'
echo 'scheduler, api and agent started in tmux session, use "tmux attach" to open it'