-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add automatic deployment scripts (#362)
* Add ansible scripts to deploy Nanocloud * Add a script and a new docker-compose file to deploy several PR * Fix directory detection so users can run this script from anywhere * Restore branch "master" after deploying a PR * Change guacamole.properties to call right backend * Create a new frontend volum for each PullRequest. * Add configuration file
- Loading branch information
1 parent
be7b215
commit b8ac4b0
Showing
11 changed files
with
277 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
# Nanocloud deployments | ||
|
||
This directory is a collection of tools to deploy Nanocloud. | ||
|
||
## Install with ansible | ||
|
||
### Dependencies | ||
|
||
You need ansible 1.9 or above to use this installation | ||
|
||
Install dependencies | ||
|
||
``` | ||
ansible-galaxy install franklinkim.docker | ||
ansible-galaxy install franklinkim.docker-compose | ||
``` | ||
|
||
> Note: You may need to have root privilege to install those dependencies. You | ||
> won't need it to run deployment. | ||
### Configure | ||
|
||
Configure where *ansible* will deploy your installation by modifying the | ||
*ansible_hosts* file. | ||
|
||
``` | ||
[nanocloud] | ||
api ansible_host=127.0.0.1 ansible_user=user | ||
``` | ||
|
||
In this file, you can specify several servers and give name to them to deploy | ||
multiple instances of Nanocloud: | ||
|
||
``` | ||
[nanocloud] | ||
api-instance1 ansible_host=10.0.0.2 ansible_user=user1 | ||
api-customerX ansible_host=10.0.0.3 ansible_user=user2 | ||
``` | ||
|
||
Use the file *deployments/roles/nanocloud/files/nanocloud/config.env* to | ||
override configuration variable like you should normally do with the *config.env* | ||
file | ||
|
||
### Run | ||
|
||
Run Playbook | ||
|
||
``` | ||
ansible-playbook nanocloud.yml | ||
``` | ||
|
||
## Run multiple instance on a same host | ||
|
||
The script *deploy-pr.sh* is here to help you deploy a specific Github Pull Request | ||
on any environment in parallel. | ||
|
||
You can deploy several PR on a single machine. Each deployment will have its | ||
own *database*, *frontend*, *backend* and *guacamole-client*. | ||
|
||
To use it, run the following command: | ||
|
||
``` | ||
./deployments/deploy-pr.sh ${PR_NUMBER} | ||
``` | ||
|
||
And if the remote is not called *origin* you can specify another name: | ||
|
||
``` | ||
./deployments/deploy-pr.sh 175 base | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
[defaults] | ||
hostfile = ansible_hosts | ||
remote_user = user | ||
host_key_checking = False |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
[nanocloud] | ||
api ansible_host=127.0.0.1 ansible_user=user |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
#!/bin/bash | ||
|
||
# Nanocloud turns any traditional software into a cloud solution, without | ||
# changing or redeveloping existing source code. | ||
# | ||
# Copyright (C) 2016 Nanocloud Software | ||
# | ||
# This file is part of Nanocloud. | ||
# | ||
# Nanocloud is free software; you can redistribute it and/or modify | ||
# it under the terms of the GNU Affero General Public License as | ||
# published by the Free Software Foundation, either version 3 of the | ||
# License, or (at your option) any later version. | ||
# | ||
# Nanocloud is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU Affero General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU Affero General | ||
# Public License | ||
# along with this program. If not, see | ||
# <http://www.gnu.org/licenses/>. | ||
|
||
# Detect where is the absolute path to repository | ||
NANOCLOUD_DEPLOY_SCRIPT="$(readlink -e "${0}")" | ||
NANOCLOUD_DEPLOY_DIR=$(dirname "${NANOCLOUD_DEPLOY_SCRIPT}") | ||
NANOCLOUD_REPO_DIR=$(dirname "${NANOCLOUD_DEPLOY_DIR}") | ||
|
||
PR_NUMBER=${1} | ||
REMOTE_NAME=${2:-"origin"} | ||
|
||
BRANCH_NAME="PR-${PR_NUMBER}" | ||
DOCKER_COMPOSE_YML="docker-compose-${PR_NUMBER}.yml" | ||
|
||
cd "${NANOCLOUD_REPO_DIR}" || exit 1 | ||
|
||
# Fetch pull request | ||
git fetch "${REMOTE_NAME}" "pull/${PR_NUMBER}/head:${BRANCH_NAME}" | ||
git checkout "${BRANCH_NAME}" | ||
|
||
# Custom configurations | ||
cp proxy/nginx.conf proxy/nginx.pr.conf | ||
sed -i "s/backend:/backend-42${PR_NUMBER}:/" "proxy/nginx.pr.conf" | ||
sed -i "s/guacamole-client:/guacamole-client-42${PR_NUMBER}:/" "proxy/nginx.pr.conf" | ||
|
||
cp docker-compose-pr.yml "${DOCKER_COMPOSE_YML}" | ||
sed -i "s/PRPORTS/42${PR_NUMBER}/" "${DOCKER_COMPOSE_YML}" | ||
|
||
cp guacamole-client/guac_home/guacamole.properties guacamole-client/guac_home/guacamole.properties.backup | ||
sed -i "s/noauthlogged-server-url: backend/noauthlogged-server-url: backend-42${PR_NUMBER}/" "guacamole-client/guac_home/guacamole.properties" | ||
|
||
cp config/connections.js backupConnection.js | ||
sed -i "s/host: 'postgres'/host: 'postgres-42${PR_NUMBER}'/" "config/connections.js" | ||
|
||
# Build and run containers | ||
docker-compose build | ||
docker-compose up -d storage guacd | ||
docker-compose -f "${DOCKER_COMPOSE_YML}" up -d | ||
|
||
# Erase custom configurations | ||
mv backupConnection.js config/connections.js | ||
mv guacamole-client/guac_home/guacamole.properties.backup guacamole-client/guac_home/guacamole.properties | ||
rm -rf proxy/nginx.pr.conf | ||
rm -rf "${DOCKER_COMPOSE_YML}" | ||
git checkout master |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
repository: Nanocloud | ||
branch: master | ||
#pull_request: XXX |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
--- | ||
|
||
- hosts: all | ||
remote_user: debian | ||
become: yes | ||
vars: | ||
repository: Nanocloud | ||
#pull_request: XX | ||
branch: master | ||
roles: | ||
- common | ||
- franklinkim.docker | ||
- franklinkim.docker-compose | ||
- nanocloud |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
- src: franklinkim.docker | ||
- src: franklinkim.docker-compose |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
- name: Update APT repositories | ||
apt: update_cache=yes |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
- name: Install git | ||
apt: name=git state=present | ||
|
||
- name: Clone nanocloud | ||
git: | ||
repo: git://github.com/{{repository}}/nanocloud | ||
dest: /nanocloud | ||
force: yes | ||
|
||
- name: Copy custom configuration | ||
copy: src=roles/nanocloud/files/nanocloud/config.env dest=/nanocloud/config.env owner=root group=root mode=0644 | ||
|
||
- name: Deploy Pull Request {{pull_request}} | ||
command: /nanocloud/deployments/deploy-pr.sh {{pull_request}} | ||
when: pull_request is defined | ||
|
||
- name: Checkout specific branch | ||
command: git checkout {{branch|default(master)}} | ||
args: | ||
chdir: /nanocloud | ||
when: | ||
- pull_request is undefined | ||
|
||
- name: Docker compose build | ||
command: docker-compose build | ||
args: | ||
chdir: /nanocloud | ||
when: | ||
- pull_request is undefined | ||
|
||
- name: Docker compose build development containers | ||
command: docker-compose -f docker-compose-dev.yml up -d | ||
args: | ||
chdir: /nanocloud | ||
when: | ||
- pull_request is undefined | ||
|
||
- name: Docker compose up | ||
command: docker-compose -f docker-compose-dev.yml up -d | ||
args: | ||
chdir: /nanocloud | ||
when: | ||
- pull_request is undefined |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
version: '2' | ||
|
||
services: | ||
backend-PRPORTS: | ||
build: | ||
context: ./ | ||
dockerfile: Dockerfile | ||
image: nanocloud/backend | ||
volumes: | ||
- static-PRPORTS:/opt/back/assets/dist | ||
env_file: | ||
- config.env | ||
networks: | ||
- nanocloud | ||
depends_on: | ||
- postgres-PRPORTS | ||
restart: always | ||
container_name: backend-PRPORTS | ||
|
||
frontend-PRPORTS: | ||
build: | ||
context: ./assets | ||
dockerfile: Dockerfile | ||
image: nanocloud/frontend | ||
volumes: | ||
- static-PRPORTS:/opt/dist | ||
networks: | ||
- nanocloud | ||
container_name: frontend-PRPORTS | ||
|
||
proxy-PRPORTS: | ||
build: ./proxy | ||
image: nanocloud/proxy | ||
ports: | ||
- PRPORTS:443 | ||
depends_on: | ||
- backend-PRPORTS | ||
volumes: | ||
- ./proxy/nginx.pr.conf:/etc/nginx/conf.d/default.conf:ro | ||
networks: | ||
- nanocloud | ||
restart: always | ||
container_name: proxy-PRPORTS | ||
|
||
postgres-PRPORTS: | ||
image: postgres:9.5.3 | ||
environment: | ||
- PGDATA=/var/lib/postgresql/data/pgdata | ||
- POSTGRES_USER=nanocloud | ||
networks: | ||
- nanocloud | ||
restart: always | ||
container_name: postgres-PRPORTS | ||
|
||
guacamole-client-PRPORTS: | ||
build: ./guacamole-client | ||
image: nanocloud/guacamole-client | ||
networks: | ||
- nanocloud | ||
restart: always | ||
container_name: guacamole-client-PRPORTS | ||
|
||
networks: | ||
nanocloud: | ||
driver: bridge | ||
|
||
volumes: | ||
static-PRPORTS: | ||
driver: local | ||
plaza: | ||
driver: local |