adding deployment of repo docker image
Change-Id: Id2e05050044d3895f07047877295f0e8265c793c
diff --git a/build.gradle b/build.gradle
index 71fedd7..ae02221 100644
--- a/build.gradle
+++ b/build.gradle
@@ -110,11 +110,11 @@
}
task buildRepoImage (dependsOn: copyLocalRepo, type: Exec) {
- commandLine 'docker', 'build', '-t', 'cordproject/mavenrepo', '.'
+ commandLine 'docker', 'build', '-t', 'opencord/mavenrepo', '.'
}
task tagMavenRepoImage (type: Exec) {
- commandLine 'docker', 'tag', 'cordproject/mavenrepo', "$targetReg/mavenrepo:$targetTag"
+ commandLine 'docker', 'tag', 'opencord/mavenrepo', "$targetReg/mavenrepo:$targetTag"
}
task publishMavenRepoImage (type: Exec) {
@@ -122,6 +122,35 @@
commandLine 'docker', 'push', "$targetReg/mavenrepo:$targetTag"
}
+List.metaClass.asParam = { prefix, sep ->
+ if (delegate.size() == 0) {
+ ""
+ }
+ String result = "--" + prefix + "="
+ String p = ""
+ delegate.each {
+ result += p + "${it}"
+ p = sep
+ }
+ result
+}
+
+List.metaClass.p = { value, name ->
+ if (value != null && value != "") {
+ delegate << name + "=" + value
+ } else {
+ delegate
+ }
+}
+
+List.metaClass.p = { spec ->
+ if (spec != null && spec != "") {
+ delegate += spec
+ } else {
+ delegate
+ }
+}
+
// ~~~~~~~~~~~~~~~~~~~ Global tasks ~~~~~~~~~~~~~~~~~~~~~~~
task fetch {
@@ -138,6 +167,44 @@
dependsOn publishMavenRepoImage
}
+task deploy (dependsOn: publishMavenRepoImage, type: Exec) {
+ println "Using deployment config: $deployConfig"
+ File configFile = new File(deployConfig)
+ def yaml = new Yaml()
+ def config = yaml.load(configFile.newReader())
+
+ executable = "ansible-playbook"
+ args = ["-i", config.seedServer.ip + ',']
+
+ if ( config.seedServer.user != null && config.seedServer.user != "" ) {
+ args = args << "--user=$config.seedServer.user"
+ }
+
+ def extraVars = []
+ if (config.seedServer) {
+ extraVars = extraVars.p(config.seedServer.extraVars)
+ .p(config.seedServer.password, "ansible_ssh_pass")
+ .p(config.seedServer.sudoPassword, "ansible_sudo_pass")
+ .p(config.seedServer.domain, "domain")
+ }
+
+ if (config.otherServers) {
+ extraVars = extraVars.p(config.otherServers.location, "prov_location")
+ .p(config.otherServers.rolesPath, "prov_role_path")
+ .p(config.otherServers.role, "prov_role")
+ }
+
+ if (config.docker) {
+ extraVars = extraVars.p(config.docker.registry, "docker_registry")
+ .p(config.docker.imageVersion, "docker_image_version")
+ }
+
+ def skipTags = [].p(config.seedServer.skipTags)
+
+ args = args.p(skipTags.asParam("skip-tags", ",")).p(extraVars.asParam("extra-vars", " ")) << "mavenrepo.yml"
+}
+
+
// Depending on the version of the apps this will either make a release or publish a snapshot
task release (type: Exec) {
workingDir './apps'
diff --git a/mavenrepo.yml b/mavenrepo.yml
new file mode 100644
index 0000000..a3644f2
--- /dev/null
+++ b/mavenrepo.yml
@@ -0,0 +1,4 @@
+- hosts: all
+ serial: 1
+ roles:
+ - mavenrepo
diff --git a/roles/mavenrepo/tasks/main.yml b/roles/mavenrepo/tasks/main.yml
new file mode 100644
index 0000000..7453ca1
--- /dev/null
+++ b/roles/mavenrepo/tasks/main.yml
@@ -0,0 +1,18 @@
+- name: Install compose for mavenrepo
+ become: yes
+ template:
+ src: templates/{{ item }}.j2
+ dest: /etc/maas/{{ item }}
+ owner: maas
+ group: maas
+ mode: 0644
+ with_items:
+ - mavenrepo.yml
+ tags: [repo]
+
+- name: Ensure mavenrepo Running
+ become: yes
+ command: docker-compose -f /etc/maas/{{ item }} up -d
+ with_items:
+ - mavenrepo.yml
+ tags: [repo]
diff --git a/roles/mavenrepo/templates/mavenrepo.yml.j2 b/roles/mavenrepo/templates/mavenrepo.yml.j2
new file mode 100644
index 0000000..b8d8e1e
--- /dev/null
+++ b/roles/mavenrepo/templates/mavenrepo.yml.j2
@@ -0,0 +1,5 @@
+mavenrepo:
+ image: "docker-registry/mavenrepo:{{ docker.image_version }}"
+ container_name: mavenrepo
+ ports:
+ - "8080:80"
diff --git a/roles/mavenrepo/vars/main.yml b/roles/mavenrepo/vars/main.yml
new file mode 100644
index 0000000..7f3b796
--- /dev/null
+++ b/roles/mavenrepo/vars/main.yml
@@ -0,0 +1,3 @@
+docker:
+ registry: "{{ docker_registry | default('opencord') }}"
+ image_version: "{{ docker_image_version | default('latest') }}"