-
Notifications
You must be signed in to change notification settings - Fork 2
Tagserver configuration tool #155
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
renato2099
wants to merge
13
commits into
main
Choose a base branch
from
149_configuration_tool
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
b4dbbe3
Configuration tool
renato2099 8988037
Configure for pyscog
renato2099 39f6644
Configure for running docker image in background
renato2099 38c4766
Add inventory file for server
renato2099 b3c842d
Add capistrano files
renato2099 2293436
Add project name to docker-compose
renato2099 7bcf4fa
Improving scripts
renato2099 2191980
Improving scripts
renato2099 100316d
149: Update tool
renato2099 4532ecf
149: Tweak docker compose
renato2099 3cbdd03
Update deploy branch
renato2099 97b8d8f
Update scripts
renato2099 6fb38ca
Start work on python script for simplyfing tagserver installation
renato2099 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,9 @@ | ||
| FROM ubuntu:20.04 | ||
|
|
||
| RUN apt-get update && apt-get install -y python3.9 && apt-get -y install python3-pip | ||
| RUN update-alternatives --install /usr/bin/python python /usr/bin/python3.9 1 && update-alternatives --set python /usr/bin/python3.9 | ||
| RUN apt-get install -y curl | ||
|
|
||
| ## allows the container to continue running regardless of the PostgreSQL service inside the container | ||
| ENTRYPOINT ["tail", "-f", "/dev/null"] | ||
| ## downside: need to manually start PostgreSQL in the container once the container is running |
This file contains hidden or 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,21 @@ | ||
| Installing tools | ||
| ---------------- | ||
| 1. Ansible | ||
| 2. Capistrano | ||
|
|
||
| Installing server tools | ||
| ----------------------- | ||
| - Modify the server IP where tagbase-server will be deployed. | ||
| - Open the `devops/inventory` file and modify the IPs specified under `prod_server` and `dev_servers` tags. | ||
| - Run the following ansible command | ||
| ``` | ||
| ansible-playbook -i ./inventory tagserver_playbook.yaml | ||
| ``` | ||
|
|
||
| Deploying tagbase-server | ||
| ------------------------ | ||
| - Run the following capistrano to deploy into the staging server | ||
| ``` | ||
| cap staging deploy | ||
| ``` | ||
|
|
This file contains hidden or 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] | ||
| auto_legacy = /usr/local/bin/python3 | ||
|
|
||
|
|
This file contains hidden or 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,38 @@ | ||
| # Load DSL and set up stages | ||
| require "capistrano/setup" | ||
|
|
||
| # Include default deployment tasks | ||
| require "capistrano/deploy" | ||
|
|
||
| # Load the SCM plugin appropriate to your project: | ||
| # | ||
| # require "capistrano/scm/hg" | ||
| # install_plugin Capistrano::SCM::Hg | ||
| # or | ||
| # require "capistrano/scm/svn" | ||
| # install_plugin Capistrano::SCM::Svn | ||
| # or | ||
| require "capistrano/scm/git" | ||
| install_plugin Capistrano::SCM::Git | ||
|
|
||
| # Include tasks from other gems included in your Gemfile | ||
| # | ||
| # For documentation on these, see for example: | ||
| # | ||
| # https://github.com/capistrano/rvm | ||
| # https://github.com/capistrano/rbenv | ||
| # https://github.com/capistrano/chruby | ||
| # https://github.com/capistrano/bundler | ||
| # https://github.com/capistrano/rails | ||
| # https://github.com/capistrano/passenger | ||
| # | ||
| # require "capistrano/rvm" | ||
| # require "capistrano/rbenv" | ||
| # require "capistrano/chruby" | ||
| # require "capistrano/bundler" | ||
| # require "capistrano/rails/assets" | ||
| # require "capistrano/rails/migrations" | ||
| # require "capistrano/passenger" | ||
|
|
||
| # Load custom tasks from `lib/capistrano/tasks` if you have any defined | ||
| Dir.glob("lib/capistrano/tasks/*.rake").each { |r| import r } |
This file contains hidden or 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,5 @@ | ||
| source "https://rubygems.org" | ||
| group :development do | ||
| gem "capistrano", "~> 3.10", require: false | ||
| gem "capistrano-rails", "~> 1.3", require: false | ||
| end |
This file contains hidden or 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,5 @@ | ||
| Installation: | ||
| - Installation instructions https://www.digitalocean.com/community/tutorials/how-to-use-capistrano-to-automate-deployments-getting-started | ||
| - To install capistrano run: `gem install capistrano` | ||
| - Then install capistrano app dependencies: `bundle install` | ||
|
|
This file contains hidden or 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,80 @@ | ||
| # config valid for current version and patch releases of Capistrano | ||
| lock "~> 3.17.1" | ||
|
|
||
| set :application, "tagbase-server" | ||
| set :repo_url, "https://github.com/tagbase/tagbase-server.git" # [email protected]:tagbase/tagbase-server.git" | ||
|
|
||
| # Default branch is :master | ||
| # ask :branch, `git rev-parse --abbrev-ref HEAD`.chomp | ||
|
|
||
| # Default deploy_to directory is /var/www/my_app_name | ||
| set :deploy_to, "/home/ubuntu/tagbase-server" | ||
|
|
||
| # Default value for :format is :airbrussh. | ||
| # set :format, :airbrussh | ||
|
|
||
| # You can configure the Airbrussh format using :format_options. | ||
| # These are the defaults. | ||
| # set :format_options, command_output: true, log_file: "log/capistrano.log", color: :auto, truncate: :auto | ||
|
|
||
| # Default value for :pty is false | ||
| set :pty, true | ||
|
|
||
| # Default value for :linked_files is [] | ||
| # append :linked_files, "config/database.yml", 'config/master.key' | ||
|
|
||
| # Default value for linked_dirs is [] | ||
| # append :linked_dirs, "log", "tmp/pids", "tmp/cache", "tmp/sockets", "tmp/webpacker", "public/system", "vendor", "storage" | ||
|
|
||
| # Default value for default_env is {} | ||
| # set :default_env, { path: "/opt/ruby/bin:$PATH" } | ||
| set :default_env, { 'COMPOSE_PROJECT_NAME': "tagbase" } | ||
|
|
||
| # Default value for local_user is ENV['USER'] | ||
| # set :local_user, -> { `git config user.name`.chomp } | ||
|
|
||
| # Default value for keep_releases is 5 | ||
| # set :keep_releases, 5 | ||
| # | ||
| set :stages, ["staging", "production"] | ||
| set :default_stage, "staging" | ||
|
|
||
|
|
||
| # Uncomment the following to require manually verifying the host key before first deploy. | ||
| # set :ssh_options, verify_host_key: :secure | ||
|
|
||
| namespace :deploy do | ||
|
|
||
| desc 'Create certificates for NGINX' | ||
| task :copy_env_app do | ||
| on roles(:app) do | ||
| execute '(cp /home/ubuntu/tagbase-server/.env /home/ubuntu/tagbase-server/current;)' | ||
| execute '(mkdir -p /home/ubuntu/tagbase-server/current/services/nginx/ssl;)' | ||
| execute '(cd /home/ubuntu/tagbase-server/current/services/nginx/ssl; openssl req -x509 -nodes -newkey rsa:2048 -keyout key.pem -out cert.pem -sha256 -days 365 -subj "/C=GB/ST=London/L=London/O=Alros/OU=IT Department/CN=localhost")' | ||
| end | ||
| end | ||
|
|
||
| desc 'Rebuild dependencies' | ||
| task :rebuild_deps do | ||
| on roles(:app) do | ||
| # Your restart mechanism here, for example: | ||
| execute '(cd /home/ubuntu/tagbase-server/current; docker-compose build --build-arg NGINX_PASS="tagbase" --build-arg NGINX_USER="tagbase" --build-arg PGBOUNCER_PORT=“6432” --build-arg POSTGRES_PASSWORD="tagbase" --build-arg POSTGRES_PORT="5432")' | ||
|
|
||
| #execute "(cd /home/ubuntu/tagbase-server/current; sudo docker-compose down; sudo docker-compose -p'tagbase' up -d)" | ||
| execute "(cd /home/ubuntu/tagbase-server/current; sudo docker-compose down; sudo docker-compose up -d)" | ||
| end | ||
| end | ||
|
|
||
| task :restart_app do | ||
| on roles(:app) do | ||
| # Your restart mechanism here, for example: | ||
| execute "(cd /home/ubuntu/tagbase-server/current; sudo docker-compose down)" | ||
| execute "(cd /home/ubuntu/tagbase-server/current; sudo docker-compose up -d)" | ||
| end | ||
| end | ||
| after :deploy, 'deploy:copy_env_app' | ||
| after :deploy, 'deploy:rebuild_deps' | ||
| after :deploy, 'deploy:restart_app' | ||
| end | ||
|
|
||
|
|
This file contains hidden or 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,63 @@ | ||
| set :branch, "main" | ||
|
|
||
| # server-based syntax | ||
| # ====================== | ||
| # Defines a single server with a list of roles and multiple properties. | ||
| # You can define all roles on a single server, or split them: | ||
|
|
||
| # server "example.com", user: "deploy", roles: %w{app db web}, my_property: :my_value | ||
| # server "example.com", user: "deploy", roles: %w{app web}, other_property: :other_value | ||
| # server "db.example.com", user: "deploy", roles: %w{db} | ||
|
|
||
|
|
||
|
|
||
| # role-based syntax | ||
| # ================== | ||
|
|
||
| # Defines a role with one or multiple servers. The primary server in each | ||
| # group is considered to be the first unless any hosts have the primary | ||
| # property set. Specify the username and a domain or IP for the server. | ||
| # Don't use `:all`, it's a meta role. | ||
|
|
||
| # role :app, %w{[email protected]}, my_property: :my_value | ||
| # role :web, %w{[email protected] [email protected]}, other_property: :other_value | ||
| # role :db, %w{[email protected]} | ||
|
|
||
|
|
||
|
|
||
| # Configuration | ||
| # ============= | ||
| # You can set any configuration variable like in config/deploy.rb | ||
| # These variables are then only loaded and set in this stage. | ||
| # For available Capistrano configuration variables see the documentation page. | ||
| # http://capistranorb.com/documentation/getting-started/configuration/ | ||
| # Feel free to add new variables to customise your setup. | ||
|
|
||
|
|
||
|
|
||
| # Custom SSH Options | ||
| # ================== | ||
| # You may pass any option but keep in mind that net/ssh understands a | ||
| # limited set of options, consult the Net::SSH documentation. | ||
| # http://net-ssh.github.io/net-ssh/classes/Net/SSH.html#method-c-start | ||
| # | ||
| # Global options | ||
| # -------------- | ||
| # set :ssh_options, { | ||
| # keys: %w(/home/user_name/.ssh/id_rsa), | ||
| # forward_agent: false, | ||
| # auth_methods: %w(password) | ||
| # } | ||
| # | ||
| # The server-based syntax can be used to override options: | ||
| # ------------------------------------ | ||
| # server "example.com", | ||
| # user: "user_name", | ||
| # roles: %w{web app}, | ||
| # ssh_options: { | ||
| # user: "user_name", # overrides user setting above | ||
| # keys: %w(/home/user_name/.ssh/id_rsa), | ||
| # forward_agent: false, | ||
| # auth_methods: %w(publickey password) | ||
| # # password: "please use keys" | ||
| # } |
This file contains hidden or 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,67 @@ | ||
| set :branch, "main" #149_configuration_tool" | ||
| set :server_ip, "18.118.1.177"# 3.15.0.82" | ||
|
|
||
| # server-based syntax | ||
| # ====================== | ||
| # Defines a single server with a list of roles and multiple properties. | ||
| # You can define all roles on a single server, or split them: | ||
|
|
||
| # server "example.com", user: "deploy", roles: %w{app db web}, my_property: :my_value | ||
| #server "3.145.103.174", user: "ubuntu", roles: %w{app} | ||
| server fetch(:server_ip), user: "ubuntu", roles: %w{app} | ||
| # server "example.com", user: "deploy", roles: %w{app web}, other_property: :other_value | ||
| # server "db.example.com", user: "deploy", roles: %w{db} | ||
|
|
||
|
|
||
|
|
||
| # role-based syntax | ||
| # ================== | ||
|
|
||
| # Defines a role with one or multiple servers. The primary server in each | ||
| # group is considered to be the first unless any hosts have the primary | ||
| # property set. Specify the username and a domain or IP for the server. | ||
| # Don't use `:all`, it's a meta role. | ||
|
|
||
| #role :app, %w{[email protected]} | ||
| role :app, "ubuntu@#{fetch(:server_ip)}" | ||
| # role :web, %w{[email protected] [email protected]}, other_property: :other_value | ||
| # role :db, %w{[email protected]} | ||
|
|
||
|
|
||
|
|
||
| # Configuration | ||
| # ============= | ||
| # You can set any configuration variable like in config/deploy.rb | ||
| # These variables are then only loaded and set in this stage. | ||
| # For available Capistrano configuration variables see the documentation page. | ||
| # http://capistranorb.com/documentation/getting-started/configuration/ | ||
| # Feel free to add new variables to customise your setup. | ||
|
|
||
|
|
||
|
|
||
| # Custom SSH Options | ||
| # ================== | ||
| # You may pass any option but keep in mind that net/ssh understands a | ||
| # limited set of options, consult the Net::SSH documentation. | ||
| # http://net-ssh.github.io/net-ssh/classes/Net/SSH.html#method-c-start | ||
| # | ||
| # Global options | ||
| # -------------- | ||
| set :ssh_options, { | ||
| keys: %w(/Users/renatomarroquin/Documents/workspace/tagbase/tagbase-server/devops/keys/devserver-keypair.pem), | ||
| forward_agent: false, | ||
| #auth_methods: %w(password) | ||
| } | ||
| # | ||
| # The server-based syntax can be used to override options: | ||
| # ------------------------------------ | ||
| # server "example.com", | ||
| # user: "user_name", | ||
| # roles: %w{web app}, | ||
| # ssh_options: { | ||
| # user: "user_name", # overrides user setting above | ||
| # keys: %w(/home/user_name/.ssh/id_rsa), | ||
| # forward_agent: false, | ||
| # auth_methods: %w(publickey password) | ||
| # # password: "please use keys" | ||
| # } |
This file contains hidden or 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,55 @@ | ||
| import os | ||
| import subprocess | ||
| import argparse | ||
|
|
||
|
|
||
| def handle_args(): | ||
| parser = argparse.ArgumentParser() | ||
| parser.add_argument('--tagbase-server-home', type=str) | ||
| parser.add_argument('--installation-user', type=str) | ||
| parser.add_argument('--prod-servers', type=str, nargs='*') | ||
| parser.add_argument('--dev-servers', type=str, nargs='*') | ||
| parser.add_argument('--dev-servers-sshkey-path', type=str) | ||
| parser.add_argument('--prod-servers-sshkey-path', type=str) | ||
| return vars(parser.parse_args()) | ||
|
|
||
|
|
||
| def log_tb(msg): | ||
| print("[TAGBASE] {}".format(msg)) | ||
|
|
||
|
|
||
| def create_ansible_servers_file(inventory_file_path, prod_servers, dev_servers, installation_user, dev_servers_sshkey_path, prod_servers_sshkey_path): | ||
| with open(inventory_file_path, 'w') as inv_file: | ||
| if prod_servers != None: | ||
| inv_file.write("[prod_servers]\n") | ||
| for prod_server in prod_servers: | ||
| inv_file.write("{}\n".format(prod_server)) | ||
| inv_file.write("[prod_servers:vars]\n") | ||
| inv_file.write("ansible_user={}\n".format(installation_user)) | ||
| inv_file.write("ansible_ssh_private_key_file={}\n".format(prod_servers_sshkey_path)) | ||
|
|
||
| if dev_servers != None: | ||
| inv_file.write("[dev_servers]\n") | ||
| for dev_server in dev_servers: | ||
| inv_file.write("{}\n".format(dev_server)) | ||
| inv_file.write("[dev_servers:vars]\n") | ||
| inv_file.write("ansible_user={}\n".format(installation_user)) | ||
| inv_file.write("ansible_ssh_private_key_file={}\n".format(dev_servers_sshkey_path)) | ||
|
|
||
| log_tb("Completed writing {}".format(inventory_file_path)) | ||
|
|
||
|
|
||
| def run_ansible_inventory_file(tagserver_home, inventory_file_path): | ||
| playbook_file_path = "{}/tagserver_playbook.yaml".format(tagserver_home) | ||
| ansible_cmd = "ansible-playbook -i {} {} -v".format(inventory_file_path, playbook_file_path) | ||
| subprocess.run(ansible_cmd, shell=True) | ||
| log_tb("Completed configuring servers") | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| args = handle_args() | ||
| tagbase_server_home = args['tagbase_server_home'] | ||
| tagbase_server_devops_home = '{}/{}'.format(tagbase_server_home, 'tagbase-server/devops') | ||
| inventory_file_path = '{}/inventory_2'.format(tagbase_server_devops_home) | ||
| create_ansible_servers_file(inventory_file_path, args['prod_servers'], args['dev_servers'], args['installation_user'], args['dev_servers_sshkey_path'], args['prod_servers_sshkey_path']) | ||
| #run_ansible_inventory_file(tagserver_home, inventory_file_path) |
This file contains hidden or 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,13 @@ | ||
| #[prod_servers] | ||
| #one.example.com | ||
| #ansible_env.TAGBASE_DEV_SERVER | ||
|
|
||
| [dev_servers] | ||
| 18.118.107.90 | ||
|
|
||
| #one.example.com | ||
|
|
||
| [dev_servers:vars] | ||
| ansible_user=ubuntu | ||
| ansible_ssh_private_key_file=/Users/renatomarroquin/Documents/workspace/tagbase/devserver-keypair.pem | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this also needs to be factored out