forked from cloudfoundry/uaa
-
Notifications
You must be signed in to change notification settings - Fork 0
/
docker.gradle
99 lines (85 loc) · 3.49 KB
/
docker.gradle
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
/*
To run docker tasks set the following environment variables:
MAINTAINER_EMAIL
DOCKER_REPO_URL
DOCKER_REPO_USER
DOCKER_REPO_USER_PW
DOCKER_CONTAINER_NAME
When pulling the uaa docker image from a registry you can inject the uaa profile and uaa.yml
into the docker container environment.
For example:
docker container run -e CATALINA_OPTS="-Dspring.profiles.active=<desired uaa profile> -DUAA_CONFIG_YAML=<properly escaped uaa.yml>" <image_id>
*/
buildscript {
apply from: file('shared_versions.gradle')
repositories {
maven {
url 'https://plugins.gradle.org/m2/'
}
}
dependencies {
classpath 'com.bmuschko:gradle-docker-plugin:3.0.8'
}
}
apply plugin: com.bmuschko.gradle.docker.DockerRemoteApiPlugin
apply plugin: 'java'
import com.bmuschko.gradle.docker.tasks.image.Dockerfile
import com.bmuschko.gradle.docker.tasks.image.DockerBuildImage
import com.bmuschko.gradle.docker.tasks.image.DockerPullImage
import com.bmuschko.gradle.docker.tasks.image.DockerPushImage
import com.bmuschko.gradle.docker.DockerRegistryCredentials
import com.bmuschko.gradle.docker.tasks.container.DockerCreateContainer
import com.bmuschko.gradle.docker.tasks.container.DockerStartContainer
task createDockerfile(type: Dockerfile) {
dependsOn assemble
destFile = project.file('build/docker/Dockerfile')
from 'tomcat:8.5-jre8'
maintainer 'UAA team "$MAINTAINER_EMAIL"'
instruction 'ENV LOGIN_CONFIG_URL WEB-INF/classes/required_configuration.yml'
instruction 'ENV ARTIFACTORY_READER $ARTIFACTORY_READER'
instruction 'ENV ARTIFACTORY_READER_PW $ARTIFACTORY_READER_PW'
instruction 'ENV CLOUD_FOUNDRY_CONFIG_PATH /uaa'
instruction 'RUN bash -c "rm -r /usr/local/tomcat/webapps/ROOT"'
instruction 'RUN bash -c "rm -r /usr/local/tomcat/webapps/host-manager"'
instruction 'RUN bash -c "rm -r /usr/local/tomcat/webapps/manager"'
instruction 'RUN bash -c "rm -r /usr/local/tomcat/webapps/examples"'
instruction 'RUN bash -c "rm -r /usr/local/tomcat/webapps/docs"'
instruction 'ADD cloudfoundry-identity-uaa-' + version + '.war /usr/local/tomcat/webapps/uaa.war'
instruction 'ADD uaa.yml /uaa/uaa.yml'
instruction 'RUN bash -c "echo $LOGIN_CONFIG_URL"'
instruction 'EXPOSE 8080'
}
task deleteDockerfile() {
delete file('build/docker')
}
task copyContainerFiles(type: Copy) {
dependsOn createDockerfile
from 'uaa/build/libs'
from 'uaa/build/resources/main/tomcat-server.xml'
from 'uaa/build/resources/main/uaa.yml'
into 'build/docker'
}
task buildImage(type: DockerBuildImage) {
dependsOn copyContainerFiles
inputDir = createDockerfile.destFile.parentFile
tag = System.getenv('DOCKER_REPO_URL') + '/' + System.getenv('DOCKER_REPO_USER') + '/uaa:' + version
}
task createUaaContainer(type: DockerCreateContainer) {
dependsOn buildImage
targetImageId { buildImage.getImageId() }
containerName = System.getenv('DOCKER_CONTAINER_NAME')
portBindings = ['8080:8080']
env = ["CATALINA_OPTS='-Dspring.profiles.active=default'"]
}
task startUaaContainer(type: DockerStartContainer) {
dependsOn createUaaContainer
targetContainerId { createUaaContainer.getContainerId() }
}
task pushUaaImage(type: DockerPushImage) {
dependsOn buildImage
imageName = System.getenv('DOCKER_REPO_URL') + '/' + System.getenv('DOCKER_REPO_USER') + '/uaa:' + version
registryCredentials = new DockerRegistryCredentials()
registryCredentials.url = System.getenv('DOCKER_REPO_URL')
registryCredentials.username = System.getenv('DOCKER_REPO_USER')
registryCredentials.password = System.getenv('DOCKER_REPO_USER_PW')
}