Skip to content

Commit

Permalink
update sample app 0.0.12
Browse files Browse the repository at this point in the history
  • Loading branch information
Benoit Moussaud committed Apr 29, 2020
1 parent 8652931 commit 0bdd44e
Show file tree
Hide file tree
Showing 16 changed files with 426 additions and 0 deletions.
31 changes: 31 additions & 0 deletions xebialabs/application.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,36 @@ spec:
children:
- name: 0.0.0
type: udm.DeploymentPackage
- name: 0.0.12
type: udm.DeploymentPackage
orchestrator:
- parallel-by-container
deployables:
- name: tomcat
type: ansible.RolesSpec
includeDevOpsAsCodeTask: True
scanPlaceholders: False
file: !file "artifacts/provision-calculator/0.0.12/roles_frontend"
tags:
- frontend
roles:
- tomcat8
variables:
public_key_path: /Users/bmoussaud/.ssh/demo_keypairs/id_rsa.pub
- name: bdd
type: ansible.RolesSpec
scanPlaceholders: True
includeDevOpsAsCodeTask: True
file: !file "artifacts/provision-calculator/0.0.12/roles_backend"
variables:
mysql_root_password: '{{database_root_password}}'
database_name: '{{database_name}}'
database_username: '{{database_username}}'
database_password: '{{database_password}}'
tags:
- backend
roles:
- mysql
- name: 0.0.13
type: udm.DeploymentPackage
orchestrator:
Expand Down Expand Up @@ -35,6 +65,7 @@ spec:
tags:
- backend
roles:
- pre
- geerlingguy.mysql
- devopsascode
galaxyRoles:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# This will configure a default manager-gui and admin-gui user:

mysql_root_password: password
cng_password: cng_password
database_name: petdatabase
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[client]
port=3306
socket=/var/run/mysqld/mysqld.sock
user=root
password={{mysql_root_password}}
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
#
# The MySQL database server configuration file.
#
# You can copy this to one of:
# - "/etc/mysql/my.cnf" to set global options,
# - "~/.my.cnf" to set user-specific options.
#
# One can use all long options that the program supports.
# Run program with --help to get a list of available options and with
# --print-defaults to see which it would actually understand and use.
#
# For explanations see
# http://dev.mysql.com/doc/mysql/en/server-system-variables.html

# This will be passed to all mysql clients
# It has been reported that passwords should be enclosed with ticks/quotes
# escpecially if they contain "#" chars...
# Remember to edit /etc/mysql/debian.cnf when changing the socket location.

# Here is entries for some specific programs
# The following values assume you have at least 32M ram

[mysqld_safe]
socket = /var/run/mysqld/mysqld.sock
nice = 0

[mysqld]
#
# * Basic Settings
#
user = mysql
pid-file = /var/run/mysqld/mysqld.pid
socket = /var/run/mysqld/mysqld.sock
port = 3306
basedir = /usr
datadir = /var/lib/mysql
tmpdir = /tmp
lc-messages-dir = /usr/share/mysql
skip-external-locking
#
# Instead of skip-networking the default is now to listen only on
# localhost which is more compatible and is not less secure.
bind-address = 0.0.0.0
#
# * Fine Tuning
#
key_buffer_size = 16M
max_allowed_packet = 16M
thread_stack = 192K
thread_cache_size = 8
# This replaces the startup script and checks MyISAM tables if needed
# the first time they are touched
myisam-recover-options = BACKUP
#max_connections = 100
#table_open_cache = 64
#thread_concurrency = 10
#
# * Query Cache Configuration
#
query_cache_limit = 1M
query_cache_size = 16M
#
# * Logging and Replication
#
# Both location gets rotated by the cronjob.
# Be aware that this log type is a performance killer.
# As of 5.1 you can enable the log at runtime!
#general_log_file = /var/log/mysql/mysql.log
#general_log = 1
#
# Error log - should be very few entries.
#
log_error = /var/log/mysql/error.log
#
# Here you can see queries with especially long duration
#slow_query_log = 1
#slow_query_log_file = /var/log/mysql/mysql-slow.log
#long_query_time = 2
#log-queries-not-using-indexes
#
# The following can be used as easy to replay backup logs or for replication.
# note: if you are setting up a replication slave, see README.Debian about
# other settings you may need to change.
#server-id = 1
#log_bin = /var/log/mysql/mysql-bin.log
expire_logs_days = 10
max_binlog_size = 100M
#binlog_do_db = include_database_name
#binlog_ignore_db = include_database_name
#
# * InnoDB
#
# InnoDB is enabled by default with a 10MB datafile in /var/lib/mysql/.
# Read the manual for more InnoDB related options. There are many!
#
# * Security Features
#
# Read the manual, too, if you want chroot!
# chroot = /var/lib/mysql/
#
# For generating SSL certificates I recommend the OpenSSL GUI "tinyca".
#
# ssl-ca=/etc/mysql/cacert.pem
# ssl-cert=/etc/mysql/server-cert.pem
# ssl-key=/etc/mysql/server-key.pem
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
- name: restart mysql
service: name=mysql state=restarted
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
---
- name: Install mysql server
apt:
name: ['python3-pip','mysql-server', 'python-mysqldb']
update_cache: yes

- name: Install Python Package PyMySQL
pip:
name: PyMySQL

- name: Start the MySQL service
service: name=mysql state=started enabled=yes

- name: Copy my.cnf file with root password credentials
template: src=templates/my.cnf.j2 dest=/root/.my.cnf owner=root mode=0600

- name: Copy my.cnf file with root password credentials in /etc/mysql/mysql.cnf
template: src=templates/my.cnf.j2 dest=/etc/mysql/mysql.cnf owner=root mode=0600

- name: Create a new database with name '{{database_name}}'
mysql_db:
name: '{{database_name}}'
state: present

- name: Update mysql root password for all root accounts
mysql_user: name=root host={{item}} password={{mysql_root_password}}
with_items:
- 127.0.0.1
- ::1
- localhost

- name: Create cng_user user for {{database_name}}
mysql_user: user="{{database_username}}" host="%" password={{database_password}} priv={{database_name}}.*:ALL,GRANT

- name: Copy configuration file
copy: src=mysqld.cnf dest=/etc/mysql/mysql.conf.d owner=root mode=0640
notify: restart mysql

- name: Generate the Devops-As-Code
template: src=xldeploy.yaml.j2 dest=/tmp/digital.ai_xldeploy.yaml mode=0755

- name: Fetch the Devops-As-Code yaml file on the master
fetch:
src: /tmp/digital.ai_xldeploy.yaml
dest: "{{ devops_as_code_directory }}"
flat: no
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[client]
port=3306
socket=/var/run/mysqld/mysqld.sock
user=root
password={{mysql_root_password}}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
apiVersion: xl-deploy/v1
kind: Infrastructure
spec:
- name: {{container.id}}/{{database_name}}-mysql
type: sql.MySqlClient
username: {{database_username}}
password: {{database_password}}
mySqlHome: /usr
databaseName: {{database_name}}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
mysql_databases:
- name: //database_name//
encoding: latin1
collation: latin1_general_ci
mysql_users:
- name: "//database_username//"
host: "%"
password: "//database_password//"
priv: "//database_name//.*:ALL"
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# This will configure a default manager-gui and admin-gui user:

admin_username: admin
admin_password: password
public_key_path: /home/jcla/.ssh/id_rsa.pub
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<Context antiResourceLocking="false" privileged="true" >
<!--
<Valve className="org.apache.catalina.valves.RemoteAddrValve"
allow="127\.\d+\.\d+\.\d+|::1|0:0:0:0:0:0:0:1|10.0.2.2" />
-->
</Context>
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
[Unit]
Description=Apache Tomcat Web Application Container
After=network.target

[Service]
Type=forking

Environment=JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk-amd64/jre
Environment=CATALINA_PID=/opt/apache-tomcat-8.5.8/temp/tomcat.pid
Environment=CATALINA_HOME=/opt/apache-tomcat-8.5.8
Environment=CATALINA_BASE=/opt/apache-tomcat-8.5.8
Environment='CATALINA_OPTS=-Xms512M -Xmx1024M -server -XX:+UseParallelGC'
Environment='JAVA_OPTS=-Djava.awt.headless=true -Djava.security.egd=file:/dev/./urandom'

ExecStart=/opt/apache-tomcat-8.5.8/bin/startup.sh
ExecStop=/opt/apache-tomcat-8.5.8/bin/shutdown.sh

User=tomcat
Group=tomcat
UMask=0007
RestartSec=10
Restart=always

[Install]
WantedBy=multi-user.target
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
- name: restart tomcat
service: name=tomcat state=restarted
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
---
- name: Install Java 1.8
apt: name=openjdk-8-jdk update_cache=yes

- name: add group "tomcat"
group: name=tomcat state=present

- name: allow 'tomcat' group to have passwordless sudo
lineinfile:
dest: /etc/sudoers
state: present
regexp: '^%tomcat'
line: '%tomcat ALL=(ALL) NOPASSWD: ALL'
validate: 'visudo -cf %s'

- name: add user "tomcat"
user: name=tomcat groups=tomcat append=yes state=present home=/home/tomcat createhome=yes

- name: create .ssh for "tomcat" user
file: path=/home/tomcat/.ssh owner=tomcat group=tomcat state=directory mode=0700

- name: set authorized key taken from file for tomcat user
authorized_key:
user: tomcat
state: present
key: "{{ item }}"
with_file:
- "{{ public_key_path }}"

- name: Download Tomcat
get_url: url=http://archive.apache.org/dist/tomcat/tomcat-8/v8.5.8/bin/apache-tomcat-8.5.8.tar.gz dest=/opt/apache-tomcat-8.5.8.tar.gz

- name: Extract archive
command: chdir=/tmp /bin/tar xvf /opt/apache-tomcat-8.5.8.tar.gz -C /opt/ creates=/opt/apache-tomcat-8.5.8

- name: Change ownership of Tomcat installation
file: path=/opt/apache-tomcat-8.5.8 owner=tomcat group=tomcat state=directory recurse=yes

- name: Install Tomcat init script
copy: src=tomcat.service dest=/etc/systemd/system/tomcat.service mode=0755

- name: Install context.xml in host-manager
copy: src=context.xml dest=/opt/apache-tomcat-8.5.8/webapps/host-manager/META-INF/context.xml mode=0640
notify: restart tomcat

- name: Install context.xml in manager
copy: src=context.xml dest=/opt/apache-tomcat-8.5.8/webapps/manager/META-INF/context.xml mode=0640
notify: restart tomcat

- name: systemd daemon-reload
shell: systemctl daemon-reload

- name: tomcat-8-start
service: name=tomcat state=started enabled=yes

- name: Configure Tomcat users
template: src=tomcat-users.xml.j2 dest=/opt/apache-tomcat-8.5.8/conf/tomcat-users.xml
notify: restart tomcat

- name: Generate the Devops-As-Code
template: src=xldeploy.yaml.j2 dest=/tmp/digital.ai_xldeploy.yaml mode=0755

- name: Fetch the Devops-As-Code yaml file on the master
fetch:
src: /tmp/digital.ai_xldeploy.yaml
dest: "{{ devops_as_code_directory }}"
flat: no



Loading

0 comments on commit 0bdd44e

Please sign in to comment.