Giter Site home page Giter Site logo

dienstplan-deploy's Introduction

dienstplan-deploy

A collection of ansible playbooks for the dienstplan slack bot to help:

  • provision a server from scratch
  • set up the bot app
  • deploy the app to the server

Install

  • Clone the dienstplan repo, compile the jar as described in the documenation
  • Clone the dienstplan-deploy repo at the same directory level as with dienstplan:
├── dienstplan
└── dienstplan-deploy
  • Checkout to a separate branch if you plan to edit configuration files
cd dienstplan-deploy
git checkout -b your-branch
  • Get Python 3
  • Install Python requirements:
cd dienstplan-deploy
pip install -r requirements.txt
  • Get a server (for a hobby project a DigitalOcean's Ubuntu with 1 GB Memory droplet will be just fine)
  • Set up your ssh keys to the server
  • Set up a domain/subdomain for the app to be resolved to your server's address
  • Get a PosgreSQL 9.4+ server (or provision one with a playbook)
  • Set up Sentry account
  • Set up ansible's hosts file, e.g. in ~/.ansible/hosts:
[digital_ocean]
dienstplan ansible_host=YOUR-SEVER-IP-ADDRESS

Usage

Encrypt / descrypt vault values

See the docs

# encrypt
ansible-vault encrypt_string --vault-password-file ~/.ansible/.dienstplan_pass.txt 'String to encrypt' --name 'variable_name'

# decrypt specific variable
ansible localhost -m ansible.builtin.debug -a var="env_slack_token" -e "@vars/env.yml" --vault-password-file ~/.ansible/.dienstplan_pass.txt

Provision a server

  1. Update vars/server.yml variables, e.g. server_domain_name, server_admin_email (see above how to encrypt/decrypt a variable), copy_local_key
  2. Provision a server with Java, Nginx server, firewall, etc:
ansible-playbook --limit dienstplan playbook-server-init.yml --inventory ~/.ansible/hosts --user root --vault-password-file ~/.ansible/.dienstplan_pass.txt

(optional) Initialize a PostgreSQL database

  1. Make sure DB credentials are set in vars/env.yml
  2. Run the playbook:
# Run all tasks
ansible-playbook --limit dienstplan playbook-psql-init.yml --inventory ~/.ansible/hosts --user root --vault-password-file ~/.ansible/.dienstplan_pass.txt

# Run tasks with selected tags
ansible-playbook -l dienstplan playbook-psql-init.yml --inventory ~/.ansible/hosts -u root --vault-password-file ~/.ansible/.dienstplan_pass.txt --tags "db"

Initialize the app

  1. Update vars/env.yml (encrypt your app's environment variables, e.g. DB credentials, Slack tokens, etc.)
  2. Update vars/app.yml (Set app_version value to the correct version of the app that you've compiled!)
  3. Run the playbook:
# Run all tasks
ansible-playbook --limit dienstplan playbook-app-init.yml --inventory ~/.ansible/hosts --user root --vault-password-file ~/.ansible/.dienstplan_pass.txt

# Run tasks with selected tags
ansible-playbook -l dienstplan playbook-app-init.yml --inventory ~/.ansible/hosts -u root --vault-password-file ~/.ansible/.dienstplan_pass.txt --tags "env"

Deploy the app

  1. Update var/env.yml if needed
  2. Update var/app.yml (do not forget to set the correct version in app_version)
  3. Run the playbook:
ansible-playbook -l dienstplan playbook-app-deploy.yml --inventory ~/.ansible/hosts -u root --vault-password-file ~/.ansible/.dienstplan_pass.txt

Or simply pass in app_version as the command line option:

ansible-playbook --limit dienstplan playbook-app-deploy.yml \
  --inventory ~/.ansible/hosts \
  -u root \
  --vault-password-file ~/.ansible/.dienstplan_pass.txt \
  -e app_version=1.1.109

Gather facts about server

Get info about dienstplan server from the hosts file:

ansible dienstplan --module-name setup --inventory ~/.ansible/hosts --user root

Ping servers

Ping all servers of group digital_ocean from the hosts file:

ansible digital_ocean --inventory ~/.ansible/hosts --module-name ping --user root

Debugging

# Log in
ssh you@your-server

# Become root
sudo -i

# Check app's files
ls -lth /opt/dienstplan/

# Check service unit files
less /etc/systemd/system/dienstplan-server.service

# See service status
systemct status dienstplan-server.service
systemct is-active dienstplan-server.service

# Reload systemd daemon
systemctl daemon-reload

# Restart service
systemct restart dienstplan-server.service

# See service logs
journalctl -u dienstplan-server.service --no-pager --since today --follow

dienstplan-deploy's People

Contributors

pilosus avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar

dienstplan-deploy's Issues

Docker container based deployment

Currently we are using lighweight setup with the systemd service running java -jar.
It would be nice to have docker container based deployments too:

  1. Blue-green deployments with docker-compose and nginx for hobby projects
  2. Simple public cloud lambda (DO, AWS)
  3. Kubernetes service

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.