Skip to content

Commit 62dc231

Browse files
author
matthias_schaub
committed
After Travis build deploy to dev server using Ansible (ssh).
1 parent 1d174d8 commit 62dc231

File tree

8 files changed

+49
-94
lines changed

8 files changed

+49
-94
lines changed

.travis.yml

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,25 @@ python:
99
- "3.6"
1010
services:
1111
- docker
12+
addons:
13+
ssh_known_hosts:
14+
- 35.190.148.87 # Development server
15+
env:
16+
- ANSIBLE_CONFIG=ansible/ansible.cfg
1217

1318
before_install:
14-
- openssl aes-256-cbc -K $encrypted_444bb228fd3f_key -iv $encrypted_444bb228fd3f_iv -in .ci-mapswipe-firebase-adminsdk-80fzw-21ddcd1649.json.enc -out mapswipe_workers/serviceAccountKey.json -d
15-
19+
- openssl aes-256-cbc -K $encrypted_444bb228fd3f_key -iv $encrypted_444bb228fd3f_iv -in travis/ci-mapswipe-firebase-adminsdk-80fzw-21ddcd1649.json.enc -out mapswipe_workers/serviceAccountKey.json -d
1620
# Create a mock file for wal-g setup
1721
- touch postgres/serviceAccountKey.json
1822

1923
install:
2024
- pip install --upgrade pip setuptools
2125
- pip install black flake8 isort
26+
# Install ansible for automated deployment
27+
- sudo apt-get --quiet update
28+
- sudo apt-get --yes install software-properties-common
29+
- sudo apt-add-repository --yes --update ppa:ansible/ansible
30+
- sudo apt-get --yes install ansible
2231

2332
script:
2433
- black --check mapswipe_workers
@@ -29,22 +38,14 @@ script:
2938
- docker-compose run mapswipe_workers python -m unittest discover --verbose --start-directory tests/unittests/
3039
# TODO: - docker-compose run mapswipe_workers python -m unittest discover --verbose --start-directory tests/integration/
3140

32-
# before_deploy:
33-
# # SSH setup to deploy to server after build.
34-
# - apk add openssh-client
35-
# - mkdir -p ~/.ssh
36-
# - chmod 700 ~/.ssh
37-
# - eval "$(ssh-agent -s)"
38-
# - export KEY_FILE=~/.ssh/api_server_ssh_key
39-
# - echo "$DEPLOYMENT_SERVER_PRIVATE_KEY" | tr -d '\r' > $KEY_FILE
40-
# - chmod 600 $KEY_FILE
41-
# - ssh-add $KEY_FILE > /dev/null
42-
# - ssh-keyscan -H "$DEPLOYMENT_SERVER_IP" >> ~/.ssh/known_hosts
43-
# - chmod 644 ~/.ssh/known_hosts
44-
# - ssh -i $KEY_FILE -o StrictHostKeyChecking=no "mapswipe@$DEPLOYMENT_SERVER_IP"
45-
46-
# deploy:
47-
# provider: script
48-
# script: bash scripts/deploy.sh
49-
# on:
50-
# branch: dev
41+
after_success:
42+
# Deploy to development server using Ansible
43+
# SSH setup to deploy to server after build.
44+
# - apk add openssh-client
45+
# - mkdir -p ~/.ssh
46+
# - chmod 700 ~/.ssh
47+
- eval "$(ssh-agent -s)" #start the ssh agent
48+
- openssl aes-256-cbc -K $encrypted_c17fa81e6490_key -iv $encrypted_c17fa81e6490_iv -in travis/ssh-private-key.enc -out travis/ssh-private-key -d
49+
- chmod 600 travis/ssh-private-key
50+
- ssh-add travis/ssh-private-key
51+
- ansible-playbook -i ansible/inventory.yml ansible/playbook.yml # Deploy to dev server

ansible/ansible.cfg

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
[defaults]
2+
INVENTORY = inventory.yml
3+
4+
[ssh_connection]
5+
pipelining = True # Reuse connection. Make execution faster.

ansible/inventory.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
all:
2+
hosts:
3+
dev:
4+
ansible_host: 35.190.148.87
5+
ansible_user: mapswipe
6+
ansible_ssh_private_key_file: ssh-private-key

ansible/playbook.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
---
2+
- name: Deploy MapSwipe Backend
3+
hosts: dev
4+
5+
tasks:
6+
- name: Fetch latest code base from GitHub.
7+
git:
8+
repo: 'https://github.com/mapswipe/python-mapswipe-workers.git'
9+
dest: /home/mapswipe/python-mapswipe-workers
10+
- name: Rebuild and restart Docker container usind Docker-Compose.
11+
script: /home/mapswipe/python-mapswipe-worker/deploy.sh

deploy.sh

Lines changed: 4 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -1,60 +1,8 @@
1-
git pull
2-
if [[ $? = 0 ]]; then
3-
echo "success"
4-
else
5-
echo "failure: $?"
6-
exit
7-
fi
8-
9-
python3 test_config.py
10-
if [[ $? = 0 ]]; then
11-
echo "success"
12-
else
13-
echo "failure: $?"
14-
exit
15-
fi
16-
17-
docker-compose build --no-cache postgres
18-
if [[ $? = 0 ]]; then
19-
echo "success"
20-
else
21-
echo "failure: $?"
22-
exit
23-
fi
24-
25-
docker-compose build --no-cache firebase_deploy
26-
if [[ $? = 0 ]]; then
27-
echo "success"
28-
else
29-
echo "failure: $?"
30-
exit
31-
fi
1+
#!/bin/bash
2+
# This script builds and starts all Docker container for running the Mapswipe ecosystem.
3+
# It is run either manually or by an Ansible Playbook after a successful Travis build.
324

33-
docker-compose build --no-cache mapswipe_workers
34-
if [[ $? = 0 ]]; then
35-
echo "success"
36-
else
37-
echo "failure: $?"
38-
exit
39-
fi
40-
41-
docker-compose build --no-cache manager_dashboard
42-
if [[ $? = 0 ]]; then
43-
echo "success"
44-
else
45-
echo "failure: $?"
46-
exit
47-
fi
48-
49-
docker-compose build --no-cache nginx
50-
if [[ $? = 0 ]]; then
51-
echo "success"
52-
else
53-
echo "failure: $?"
54-
exit
55-
fi
56-
57-
docker-compose build --no-cache api
5+
docker-compose build --no-cache postgres firebase_deploy mapswipe_workers manager_dashboard nginx api
586
if [[ $? = 0 ]]; then
597
echo "success"
608
else
@@ -69,20 +17,3 @@ else
6917
echo "failure: $?"
7018
exit
7119
fi
72-
73-
docker logs firebase_deploy
74-
if [[ $? = 0 ]]; then
75-
echo "success"
76-
else
77-
echo "failure: $?"
78-
exit
79-
fi
80-
81-
docker ps -a
82-
if [[ $? = 0 ]]; then
83-
echo "success"
84-
else
85-
echo "failure: $?"
86-
exit
87-
fi
88-

.ci-mapswipe-firebase-adminsdk-80fzw-21ddcd1649.json.enc renamed to travis/ci-mapswipe-firebase-adminsdk-80fzw-21ddcd1649.json.enc

File renamed without changes.

travis/ssh-private-key.enc

2.53 KB
Binary file not shown.

travis/ssh-public-key

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQD5Q68DO4VLPzIpZY1e1vX1kLC1bjviUsFyR0A7O8SGDtGF7iMQuawPLcgXcH8ymbqGctDB3ALPew5xVGnj/5+OEdf5HC8mwcpaJiFKNSGBaCU3l5Zsr6A0cXStMbXN/OY4fNTlvnUDs6+vP0mPWvEXEtAPT3v6HgWZT/zVzv1VwOTmJUE+yzXt4AcvYxj4GXZA+crZubsb31txqI45cBT4LxmS8Zwebf7VMqY1mA7ENngWN2Vxa5m8js50qCEZ4EDaeqFl+m0XmrVqK/bkxnS8eUtQBn2dGSoBKA808kKb6yuDsDYz89jJEPCsoGk1F4KeamgrXiZVypvVmyFJTc7UMdHKh2fqpeQIJRUoryEKYHQBqYYGDpD0PLEjEGVcc9gON4YvVRKOYDlDTtS+O3vyWCYxm6kIbvK4xH7fF9dLbMgP4qEBrc39NVnN+WYgAXLSBDbfJb8+tbTHoSTvS7WzgzWr55tEFHWzV0p6HYHWIR5x/YW8vsMLvdmMcJZ8FBU= noname

0 commit comments

Comments
 (0)