Commit e6d091da by Heechul Kim

Added git tag creation

parent 7a670a30
...@@ -26,6 +26,7 @@ from porch.config import FILE_LOG ...@@ -26,6 +26,7 @@ from porch.config import FILE_LOG
from porch.config import APP_ROOT from porch.config import APP_ROOT
from porch.config import PORCH_USER from porch.config import PORCH_USER
from porch.config import PORCHSHELL from porch.config import PORCHSHELL
from porch.config import PROXY_URL, PROXY_PORT
logging.config.fileConfig('logging.conf') logging.config.fileConfig('logging.conf')
log = logging.getLogger('porch') log = logging.getLogger('porch')
...@@ -353,7 +354,7 @@ def _bg_file_distribute(data, s_logfile): ...@@ -353,7 +354,7 @@ def _bg_file_distribute(data, s_logfile):
return True return True
def create_tag(data): def tag_app(data):
"""Create tag """Create tag
``` ```
{ {
...@@ -363,4 +364,58 @@ def create_tag(data): ...@@ -363,4 +364,58 @@ def create_tag(data):
``` ```
""" """
t_ret = (False, '') t_ret = (False, '')
# Get app info.
s_rsc = '{}/app/{}'.format(etcdc.prefix, data['name'])
try:
r = etcdc.read(s_rsc)
except etcd.EtcdKeyNotFound as e:
log.error(e)
return (False, e)
d = ast.literal_eval(r.value)
# Get repo.
s_play_dir = PLAY_DIR + '/' + d['name'] + datetime.now().isoformat()
o_repo = Repo.clone_from(
'file://' + GIT_DIR + '/' + d['repo'],
s_play_dir,
depth=1
)
# render site.yml
data['proxy_url'] = PROXY_URL
data['proxy_port'] = PROXY_PORT
s_out = render_template('{}_site.j2'.format(d['name']), d=data)
try:
with open(s_play_dir + '/site.yml', 'w') as f:
f.write(s_out)
except:
s_msg = 'Fail to create ansible site.yml file.'
return (False, s_msg)
# render role's main.yml
s_out = render_template('{}_main.j2'.format(d['name']), d=data)
try:
s_main = s_play_dir + '/roles/{}/tasks/main.yml'.format(d['name'])
with open(s_main, 'w') as f:
f.write(s_out)
except:
s_msg = 'Fail to create ansible main.yml file.'
return (False, s_msg)
try:
# git add modified files.
o_repo.git.add(update=True)
# git commit files
o_repo.index.commit('commit for the new tag {}'.format(data['tag']))
# git tag
newtag = o_repo.create_tag(data['tag'])
# git push tag
o_repo.remotes.origin.push(newtag)
except Exception as e:
s_msg = 'Fail to push git tag {}: {}'.format(data['tag'], e)
log.error(s_msg)
return (False, s_msg)
return (True, 'Succeed to create a tag {}'.format(data['tag']))
...@@ -15,6 +15,7 @@ from porch.api.app.serializers import appPostSerializer ...@@ -15,6 +15,7 @@ from porch.api.app.serializers import appPostSerializer
from porch.api.app.serializers import appPatchSerializer from porch.api.app.serializers import appPatchSerializer
from porch.api.app.serializers import appPlaySerializer from porch.api.app.serializers import appPlaySerializer
from porch.api.app.serializers import appFileDistributeSerializer from porch.api.app.serializers import appFileDistributeSerializer
from porch.api.app.serializers import appTagSerializer
from porch.config import MY_IP from porch.config import MY_IP
...@@ -27,6 +28,7 @@ from porch.api.app.bizlogic import get_app_log ...@@ -27,6 +28,7 @@ from porch.api.app.bizlogic import get_app_log
from porch.api.app.bizlogic import file_container_app from porch.api.app.bizlogic import file_container_app
from porch.api.app.bizlogic import close_file_container from porch.api.app.bizlogic import close_file_container
from porch.api.app.bizlogic import file_distribute_app from porch.api.app.bizlogic import file_distribute_app
from porch.api.app.bizlogic import tag_app
log = logging.getLogger('porch') log = logging.getLogger('porch')
...@@ -180,3 +182,19 @@ class AppFileDistribute(Resource): ...@@ -180,3 +182,19 @@ class AppFileDistribute(Resource):
return s_msg, 200 return s_msg, 200
@ns.route('/<string:name>/tag')
@ns.response(404, 'App not found.')
class AppTag(Resource):
@ns.expect(appTagSerializer)
@jwt_required
def post(self, name):
"""the catalog file distributer."""
data = request.json
data['name'] = name
(b_ret, s_msg) = tag_app(data)
if not b_ret:
d_msg = {'error': s_msg}
return d_msg, 400
return s_msg, 200
...@@ -31,4 +31,7 @@ appFileDistributeSerializer = api.model('FileDistributeApp', { ...@@ -31,4 +31,7 @@ appFileDistributeSerializer = api.model('FileDistributeApp', {
'name': fields.String(required=True, description='app name'), 'name': fields.String(required=True, description='app name'),
'machines': fields.List(fields.String), 'machines': fields.List(fields.String),
}) })
appTagSerializer = api.model('TagApp', {
'tag': fields.String(required=True, description='app tag'),
})
---
# This playbook deploys BIND
- name: Ensure the 'Developemnt tools' package group installed.
yum:
name: "@Development tools"
state: present
- name: Ensure the openssl-devel package installed
yum:
name: openssl-devel
state: present
- name: Get bind source tarball from ftp://ftp.isc.org.
get_url:
url: ftp://ftp.isc.org/isc/bind9/{{ d['tag'] }}/bind-{{ d['tag'] }}.tar.gz
dest: /tmp/bind-{{ d['tag'] }}.tar.gz
- name: untar the source tarball to managed node's /tmp.
unarchive:
src: /tmp/bind-{{ d['tag'] }}.tar.gz
dest: /tmp
remote_src: True
- name: configure bind.
shell: ./configure --prefix=/usr/local/bind-{{ d['tag'] }} --sysconfdir=/etc --enable-querytrace --with-tuning=large --enable-threads --enable-full-report
args:
chdir: /tmp/bind-{{ d['tag'] }}
- name: make bind.
shell: make -j {{ ansible_processor_vcpus }}
args:
chdir: /tmp/bind-{{ d['tag'] }}
- name: make install bind.
shell: make install
args:
chdir: /tmp/bind-{{ d['tag'] }}
- name: Clean untarred source
file:
path: /tmp/bind-{{ d['tag'] }}
state: absent
- name: Create named user.
user:
name: named
shell: /sbin/nologin
createhome: no
- name: Check if named is running.
command: pidof named
register: is_named_running
ignore_errors: True
- name: kill named process
shell: kill -9 $(pidof named)
when: is_named_running.rc == 0
- name: Delete /usr/sbin/named.
file:
path: /usr/sbin/named
state: absent
ignore_errors: True
- name: Delete /usr/sbin/rndc.
file:
path: /usr/sbin/rndc
state: absent
ignore_errors: True
- name: Symlink named.
file:
src: /usr/local/bind-{{ d['tag'] }}/sbin/named
dest: /usr/sbin/named
state: link
- name: Symlink rndc.
file:
src: /usr/local/bind-{{ d['tag'] }}/sbin/rndc
dest: /usr/sbin/rndc
state: link
- name: Check to see if /etc/named.conf exists.
stat:
path: /etc/named.conf
register: st
- name: Touch /etc/named.conf if not exist.
file:
path: /etc/named.conf
state: touch
when: st.stat.exists == False
- name: Make directory /data/nis
file:
path: /data/nis
state: directory
mode: 0755
- name: Make directory /data/named/log
file:
path: /data/named/log
state: directory
mode: 0755
- name: Change ownership of /data to named:named
command: chown -R named:named /data
- name: Copy named.service systemd file.
copy:
src: named.service
dest: /etc/systemd/system/named.service
- name: Reload systemd.
command: systemctl daemon-reload
- name: Enable named service
command: systemctl enable named.service
- name: Run named service
command: systemctl start named.service
...
---
# This playbook deploys BIND
- name: Install bind
hosts: all
roles:
- bind
environment:
http_proxy: http://{{ d['proxy_url'] }}:{{ d['proxy_port'] }}
...
...@@ -152,17 +152,17 @@ export default { ...@@ -152,17 +152,17 @@ export default {
'Authorization': `Bearer ${token}` 'Authorization': `Bearer ${token}`
} }
} }
self.$http.patch(url, data, headers).then(response => { self.$http.post(url, data, headers).then(response => {
// close dialog // close dialog
close(() => { close(() => {
Toast.create.positive({ Toast.create.positive({
html: `애플리케이션 ${name} 태그 생성 완료`, html: `애플리케이션 ${name} 태그 생성 완료`,
timeout: 5000 timeout: 3000
}) })
}) })
self.loadData() self.loadData()
}, response => { }, response => {
let err = `애플리케이션 ${name} 태그 실패` let err = `애플리케이션 ${name} 태그 실패: ` + response.body
Toast.create.negative({ Toast.create.negative({
html: err, html: err,
timeout: 3000 timeout: 3000
......
...@@ -136,11 +136,11 @@ export default { ...@@ -136,11 +136,11 @@ export default {
const url = API_URL + '/machine/os' const url = API_URL + '/machine/os'
this.$http.post(url, this.form, headers).then(response => { this.$http.post(url, this.form, headers).then(response => {
console.log(response.body) console.log(response.body)
this.$router.push('/log')
}, response => { }, response => {
Toast.create.negative('서버 OS 배포 실패') console.log(response.statusText)
return // Toast.create.negative('서버 OS 배포 실패')
}) })
this.$router.push('/log')
}, },
toggle: function () { toggle: function () {
let selected = [] let selected = []
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment