Skip to content

Commit 2944663

Browse files
authored
Preparation for including other languages (#18)
* Separated java specific files from others * Separate jave specific files and variables * Added copyright to files and continued split * Made config repo conditional to use image * Made commit config repo conditional to use image
1 parent 8f81a57 commit 2944663

19 files changed

Lines changed: 618 additions & 693 deletions

‎config-repo.tf‎

Lines changed: 33 additions & 212 deletions
Original file line numberDiff line numberDiff line change
@@ -23,19 +23,6 @@ resource "local_file" "dockerfile" {
2323
content = data.template_file.dockerfile.rendered
2424
}
2525

26-
# creates the server.xml
27-
resource "local_file" "server_xml" {
28-
filename = "${path.module}/server.xml"
29-
content = data.template_file.server_xml[0].rendered
30-
count = (var.application_type == "WAR") ? 1 : 0
31-
}
32-
33-
# create catalina.sh
34-
resource "local_file" "catalina" {
35-
filename = "${path.module}/catalina.sh"
36-
content = data.template_file.catalina_sh[0].rendered
37-
count = (var.application_type == "WAR") ? 1 : 0
38-
}
3926

4027
# creates the OCI config file
4128
resource "local_file" "wallet" {
@@ -57,14 +44,30 @@ resource "local_file" "deploy_image" {
5744
count = var.nb_copies
5845
}
5946

47+
# Repository used to store deployment shell script
48+
resource "oci_artifacts_repository" "application_repository" {
49+
compartment_id = var.compartment_id
50+
is_immutable = true
51+
repository_type = "GENERIC"
52+
display_name = "${local.application_name}-repository"
53+
}
54+
55+
resource "oci_generic_artifacts_content_artifact_by_path" "update_container_instance_script" {
56+
depends_on = [
57+
oci_artifacts_repository.application_repository
58+
]
59+
60+
artifact_path = local.deploy_artifact_path
61+
repository_id = oci_artifacts_repository.application_repository.id
62+
version = local.deploy_artifact_version
63+
source = "${path.module}/update_container_instance.sh"
64+
}
6065

61-
# Update the config repo with the required bits in the WAR case:
62-
resource "null_resource" "create_config_repo_war" {
66+
# Update the config repo with the required bits:
67+
resource "null_resource" "create_config_repo" {
6368
depends_on = [
6469
oci_devops_repository.config_repo,
6570
local_file.dockerfile,
66-
# local_file.api_key_pem,
67-
# local_file.oci_config,
6871
local_file.wallet,
6972
local_file.self_signed_certificate,
7073
local_file.oci_build_config,
@@ -92,190 +95,37 @@ resource "null_resource" "create_config_repo_war" {
9295
working_dir = "${path.module}"
9396
}
9497

95-
# copy Dockerfile to app directory
96-
provisioner "local-exec" {
97-
command = "cp Dockerfile ./${local.config_repo_name}/Dockerfile"
98-
on_failure = fail
99-
working_dir = "${path.module}"
100-
}
101-
102-
# copy server.xml to app directory
103-
provisioner "local-exec" {
104-
command = "cp server.xml ./${local.config_repo_name}/server.xml"
105-
on_failure = fail
106-
working_dir = "${path.module}"
107-
}
108-
109-
# copy catalina.sh to app directory
110-
provisioner "local-exec" {
111-
command = "cp catalina.sh ./${local.config_repo_name}/catalina.sh"
112-
on_failure = fail
113-
working_dir = "${path.module}"
114-
}
115-
116-
# copy wallet to app directory
117-
provisioner "local-exec" {
118-
command = "cat wallet.zip.b64 | base64 --decode > ./${local.config_repo_name}/wallet.zip"
119-
on_failure = fail
120-
working_dir = "${path.module}"
121-
}
122-
12398
# copy config to app directory
12499
provisioner "local-exec" {
125100
command = "cp build_spec.yaml ./${local.config_repo_name}/build_spec.yaml"
126101
on_failure = fail
127102
working_dir = "${path.module}"
128103
}
129104

130-
provisioner "local-exec" {
131-
command = "openssl pkcs12 -export -in certificate.pem -inkey private-key.pem -name self_signed -password \"pass:${random_password.keystore_password.result}\" > server.p12"
132-
on_failure = fail
133-
working_dir = "${path.module}"
134-
}
135-
136-
provisioner "local-exec" {
137-
command = "keytool -importkeystore -noprompt -srckeystore server.p12 -destkeystore self.keystore -srcstoretype pkcs12 -alias self_signed -srcstorepass \"${random_password.keystore_password.result}\" -deststorepass \"${random_password.keystore_password.result}\""
138-
on_failure = fail
139-
working_dir = "${path.module}"
140-
}
141-
142-
# copy keystore
143-
provisioner "local-exec" {
144-
command = "cp self.keystore ./${local.config_repo_name}/self.keystore"
145-
on_failure = fail
146-
working_dir = "${path.module}"
147-
}
148-
149-
# add wallet to git
150-
provisioner "local-exec" {
151-
command = "git add wallet.zip"
152-
on_failure = fail
153-
working_dir = "${path.module}/${local.config_repo_name}"
154-
}
155-
156105
# add build.yaml to git
157106
provisioner "local-exec" {
158107
command = "git add build_spec.yaml"
159108
on_failure = fail
160109
working_dir = "${path.module}/${local.config_repo_name}"
161110
}
162111

163-
# add Dockerfile to git
164-
provisioner "local-exec" {
165-
command = "git add Dockerfile"
166-
on_failure = fail
167-
working_dir = "${path.module}/${local.config_repo_name}"
168-
}
169-
170-
# add catalina.sh to git
171-
provisioner "local-exec" {
172-
command = "git add catalina.sh"
173-
on_failure = fail
174-
working_dir = "${path.module}/${local.config_repo_name}"
175-
}
176-
177-
# add server.xml to git
178-
provisioner "local-exec" {
179-
command = "git add server.xml"
180-
on_failure = fail
181-
working_dir = "${path.module}/${local.config_repo_name}"
182-
}
183-
184-
# add keystore to git
185-
provisioner "local-exec" {
186-
command = "git add ./self.keystore"
187-
on_failure = fail
188-
working_dir = "${path.module}/${local.config_repo_name}"
189-
}
190-
191-
# Commit changes
192-
provisioner "local-exec" {
193-
command = "git commit -m \"Initial commit by Terraform script\""
194-
on_failure = fail
195-
working_dir = "${path.module}/${local.config_repo_name}"
196-
}
197-
198-
# Push changes
199-
provisioner "local-exec" {
200-
command = "git push"
201-
on_failure = fail
202-
working_dir = "${path.module}/${local.config_repo_name}"
203-
}
204-
205-
count = (var.application_type == "WAR") ? 1 : 0
206-
207-
}
208-
209-
# Update the config repo with the required bits in the JAR case:
210-
resource "null_resource" "create_config_repo_jar" {
211-
depends_on = [
212-
oci_devops_repository.config_repo,
213-
local_file.dockerfile,
214-
# local_file.api_key_pem,
215-
# local_file.oci_config,
216-
local_file.wallet,
217-
local_file.self_signed_certificate,
218-
local_file.oci_build_config,
219-
random_password.wallet_password
220-
]
221-
222-
# clone new repository
223-
provisioner "local-exec" {
224-
command = "git clone ${local.config_repo_url}"
225-
on_failure = fail
226-
working_dir = "${path.module}"
227-
}
228-
229-
# clone new repository
230-
provisioner "local-exec" {
231-
command = "git config --global user.email \"${local.login}\""
232-
on_failure = fail
233-
working_dir = "${path.module}"
234-
}
235-
236-
# clone new repository
237-
provisioner "local-exec" {
238-
command = "git config --global user.name \"${local.service-username}\""
239-
on_failure = fail
240-
working_dir = "${path.module}"
241-
}
242-
243112
# copy Dockerfile to app directory
244113
provisioner "local-exec" {
245114
command = "cp Dockerfile ./${local.config_repo_name}/Dockerfile"
246115
on_failure = fail
247116
working_dir = "${path.module}"
248117
}
249118

250-
# copy wallet to app directory
251-
provisioner "local-exec" {
252-
command = "cat wallet.zip.b64 | base64 --decode > ./${local.config_repo_name}/wallet.zip"
253-
on_failure = fail
254-
working_dir = "${path.module}"
255-
}
256-
257-
# copy config to app directory
258-
provisioner "local-exec" {
259-
command = "cp build_spec.yaml ./${local.config_repo_name}/build_spec.yaml"
260-
on_failure = fail
261-
working_dir = "${path.module}"
262-
}
263-
264-
provisioner "local-exec" {
265-
command = "openssl pkcs12 -export -in certificate.pem -inkey private-key.pem -name self_signed -password \"pass:${random_password.keystore_password.result}\" > server.p12"
266-
on_failure = fail
267-
working_dir = "${path.module}"
268-
}
269-
119+
# add Dockerfile to git
270120
provisioner "local-exec" {
271-
command = "keytool -importkeystore -noprompt -srckeystore server.p12 -destkeystore self.keystore -srcstoretype pkcs12 -alias self_signed -srcstorepass \"${random_password.keystore_password.result}\" -deststorepass \"${random_password.keystore_password.result}\""
121+
command = "git add Dockerfile"
272122
on_failure = fail
273-
working_dir = "${path.module}"
123+
working_dir = "${path.module}/${local.config_repo_name}"
274124
}
275125

276-
# copy keystore
126+
# copy wallet to app directory
277127
provisioner "local-exec" {
278-
command = "cp self.keystore ./${local.config_repo_name}/self.keystore"
128+
command = "cat wallet.zip.b64 | base64 --decode > ./${local.config_repo_name}/wallet.zip"
279129
on_failure = fail
280130
working_dir = "${path.module}"
281131
}
@@ -287,27 +137,19 @@ resource "null_resource" "create_config_repo_jar" {
287137
working_dir = "${path.module}/${local.config_repo_name}"
288138
}
289139

290-
# add build.yaml to git
291140
provisioner "local-exec" {
292-
command = "git add build_spec.yaml"
141+
command = "openssl pkcs12 -export -in certificate.pem -inkey private-key.pem -name self_signed -password \"pass:${random_password.keystore_password.result}\" > server.p12"
293142
on_failure = fail
294-
working_dir = "${path.module}/${local.config_repo_name}"
143+
working_dir = "${path.module}"
295144
}
296145

297-
# add Dockerfile to git
298-
provisioner "local-exec" {
299-
command = "git add Dockerfile"
300-
on_failure = fail
301-
working_dir = "${path.module}/${local.config_repo_name}"
302-
}
146+
count = (local.use-image ? 0 : 1)
147+
}
303148

304-
# add keystore to git
305-
provisioner "local-exec" {
306-
command = "git add ./self.keystore"
307-
on_failure = fail
308-
working_dir = "${path.module}/${local.config_repo_name}"
309-
}
149+
resource "null_resource" "commit_config_repo" {
310150

151+
depends_on = [ null_resource.language_specific_files ]
152+
311153
# Commit changes
312154
provisioner "local-exec" {
313155
command = "git commit -m \"Initial commit by Terraform script\""
@@ -322,26 +164,5 @@ resource "null_resource" "create_config_repo_jar" {
322164
working_dir = "${path.module}/${local.config_repo_name}"
323165
}
324166

325-
count = (var.application_type == "JAR") ? 1 : 0
326-
327-
}
328-
329-
330-
# Repository used to store deployment shell script
331-
resource "oci_artifacts_repository" "application_repository" {
332-
compartment_id = var.compartment_id
333-
is_immutable = true
334-
repository_type = "GENERIC"
335-
display_name = "${local.application_name}-repository"
336-
}
337-
338-
resource "oci_generic_artifacts_content_artifact_by_path" "update_container_instance_script" {
339-
depends_on = [
340-
oci_artifacts_repository.application_repository
341-
]
342-
343-
artifact_path = local.deploy_artifact_path
344-
repository_id = oci_artifacts_repository.application_repository.id
345-
version = local.deploy_artifact_version
346-
source = "${path.module}/update_container_instance.sh"
167+
count = (local.use-image ? 0 : 1)
347168
}

‎datasources.tf‎

Lines changed: 0 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -38,44 +38,6 @@ data "oci_database_autonomous_database" "autonomous_database" {
3838
autonomous_database_id = var.autonomous_database
3939
}
4040

41-
# dockerfile used to create image
42-
data "template_file" "dockerfile" {
43-
template = "${var.application_type == "JAR" ? file("${path.module}/Dockerfile-jar.template") : file("${path.module}/Dockerfile-war.template")}"
44-
vars = {
45-
namespace = "${local.namespace}"
46-
bucket_name = "${local.bucket_name}"
47-
keystore_password = random_password.keystore_password.result
48-
application_name = var.application_name
49-
private_data_key = data.oci_apm_data_keys.private_key.data_keys[0].value
50-
endpoint = oci_apm_apm_domain.app_apm_domain.data_upload_endpoint
51-
port_property = var.port_property
52-
vm_options = (var.vm_options != null && var.vm_options != "" ? format("\"%s\", ", replace(var.vm_options, " " , "\", \"")) : "")
53-
program_arguments = (var.program_arguments != null && var.program_arguments != "" ? format(", \"%s\" ", replace(trimspace(var.program_arguments), " ", "\", \"")): "")
54-
keystore_property = var.keystore_property
55-
key_alias_property = var.key_alias_property
56-
keystore_password_property = var.keystore_password_property
57-
keystore_type_property = var.keystore_type_property,
58-
exposed_port = var.exposed_port
59-
}
60-
}
61-
62-
data "template_file" "server_xml" {
63-
template = file("${path.module}/server.xml.template")
64-
vars = {
65-
keystore_password = random_password.keystore_password.result
66-
exposed_port = var.exposed_port
67-
}
68-
count = (var.application_type == "WAR") ? 1 : 0
69-
}
70-
71-
data "template_file" "catalina_sh" {
72-
template = file("${path.module}/catalina.sh.template")
73-
vars = {
74-
vm_options = var.vm_options
75-
}
76-
count = (var.application_type == "WAR") ? 1 : 0
77-
}
78-
7941
# oci config file
8042
data "template_file" "oci_config" {
8143
template = "${file("${path.module}/config")}"
@@ -95,35 +57,6 @@ data "oci_artifacts_generic_artifact" "app_artifact" {
9557
count = local.use-artifact ? 1 : 0
9658
}
9759

98-
# build spec file
99-
data "template_file" "oci_build_config" {
100-
depends_on = [
101-
oci_vault_secret.auth_token_secret
102-
]
103-
template = "${(local.use-repository ? file("${path.module}/build-repo.yaml.template") : file("${path.module}/build-artifact.yaml.template"))}"
104-
vars = {
105-
image_remote_tag = "${local.image-remote-tag}"
106-
image_latest_tag = "${local.image-latest-tag}"
107-
image_tag = "${local.image-name}"
108-
container_registry_repo = "${local.container-registry-repo}"
109-
login = local.login_container
110-
build_command = var.build_command
111-
artifact_location = var.artifact_location
112-
artifact_path = (local.use-artifact ? data.oci_artifacts_generic_artifact.app_artifact[0].artifact_path : "")
113-
artifact_version = (local.use-artifact ? data.oci_artifacts_generic_artifact.app_artifact[0].version : "")
114-
oci_token = local.auth_token_secret
115-
repo_name = (local.use-repository ? data.oci_devops_repository.devops_repository[0].name : "")
116-
config_repo_name = local.config_repo_name
117-
artifactId = (local.use-artifact ? var.artifact_id : "")
118-
registryId = (local.use-artifact ? var.registry_id : "")
119-
fileName = (var.application_type == "WAR" ? "app.war" : "app.jar")
120-
db_username = local.username
121-
db_connection_url = local.connection_str
122-
db_user_password = oci_vault_secret.db_user_password.id
123-
wallet_password = oci_vault_secret.db_wallet_password.id
124-
}
125-
}
126-
12760
# build spec file
12861
data "template_file" "oci_deploy_config" {
12962
depends_on = [

0 commit comments

Comments
 (0)