forked from itu-devops/itu-minitwit-ci
-
Notifications
You must be signed in to change notification settings - Fork 0
/
.travis.yml
65 lines (57 loc) · 2.26 KB
/
.travis.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
os: linux
dist: bionic
language: python
python:
- 3.7
services:
- docker # required, but travis uses older version of docker :(
before_install:
# Decrypt the git_deploy_key.enc key into /tmp/git_deploy_key
- openssl aes-256-cbc -K $encrypted_56635d5d55b3_key -iv $encrypted_56635d5d55b3_iv -in ssh_keys/do_ssh_key.enc -out /tmp/git_deploy_key -d
# Make sure only the current user can read the private key
- chmod 600 /tmp/git_deploy_key
# Create a script to return the passphrase environment variable to ssh-add
- echo 'echo ${SSH_PASSPHRASE}' > /tmp/askpass && chmod +x /tmp/askpass
# Start the authentication agent
- eval "$(ssh-agent -s)"
# Add the key to the authentication agent
- DISPLAY=":0.0" SSH_ASKPASS="/tmp/askpass" setsid ssh-add /tmp/git_deploy_key </dev/null
install:
- docker --version # document the version travis is using
stages:
- docker_build
- test
- deploy
jobs:
include:
- stage: docker_build
name: "build and push docker"
script:
- echo "LOGIN"
- echo $DOCKER_PASSWORD | docker login -u $DOCKER_USERNAME --password-stdin
- echo "BUILD"
- docker build -t $DOCKER_USERNAME/minitwitimage:latest . -f Dockerfile-minitwit
- docker build -t $DOCKER_USERNAME/mysqlimage:latest . -f Dockerfile-mysql
- docker build -t $DOCKER_USERNAME/flagtoolimage:latest . -f Dockerfile-flagtool
- echo "PUSH"
- docker push $DOCKER_USERNAME/minitwitimage:latest
- docker push $DOCKER_USERNAME/mysqlimage:latest
- docker push $DOCKER_USERNAME/flagtoolimage:latest
- stage: test
name: "run pytest"
install: skip
script:
- docker build -t $DOCKER_USERNAME/minitwittestimage -f Dockerfile-minitwit-tests .
- yes | docker-compose up -d
- docker run -it --rm --network=itu-minitwit-network $DOCKER_USERNAME/minitwittestimage
- stage: deploy
name: "deploy new version"
install: skip
# -o flag to get around "add ip to known hosts prompt"
script: |
ssh -o "StrictHostKeyChecking no" ${MT_USER}@${MT_SERVER} \
"source /root/.bash_profile && \
cd /vagrant && \
docker-compose pull && \
docker-compose up -d && \
docker pull $DOCKER_USERNAME/flagtoolimage:latest"