-
Notifications
You must be signed in to change notification settings - Fork 17
/
build-jenkins-agent-ubuntu.pkr.hcl
83 lines (71 loc) · 2.77 KB
/
build-jenkins-agent-ubuntu.pkr.hcl
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
build {
source "docker.base" {
name = "ubuntu"
}
source "amazon-ebs.base" {
name = "ubuntu"
ssh_username = "ubuntu"
# Egg-and-chicken: what is the base image to start from (eg. what is my egg)?
source_ami = try(local.images_versions["aws"]["ubuntu"][var.agent_os_version][var.architecture], "N/A")
}
source "azure-arm.base" {
name = "ubuntu"
# List available offers and publishers with the command `az vm image list --output table`
image_offer = "0001-com-ubuntu-server-jammy"
image_publisher = "canonical"
# List available SKUs with the command `az vm image list-skus --offer 0001-com-ubuntu-server-jammy --location eastus --publisher canonical --output table`
image_sku = local.az_instance_image_sku[var.architecture]
image_version = try(local.images_versions["azure"]["ubuntu"][var.agent_os_version][var.architecture], "N/A")
os_type = "Linux"
}
provisioner "shell" {
only = ["docker.ubuntu"]
environment_vars = local.provisioning_env_vars
script = "./provisioning/docker-jenkins-agent.sh"
}
provisioner "file" {
source = "./provisioning/add_auth_key_to_user.sh"
destination = "/tmp/add_auth_key_to_user.sh"
}
provisioner "file" {
source = "./provisioning/get-fileshare-signed-url.sh"
destination = "/tmp/get-fileshare-signed-url.sh"
}
provisioner "file" {
source = "./gpg-keys"
destination = "/tmp/gpg-keys"
}
provisioner "shell" {
environment_vars = local.provisioning_env_vars
execute_command = "chmod +x {{ .Path }}; {{ .Vars }} sudo -E bash '{{ .Path }}'"
script = "./provisioning/ubuntu-provision.sh"
}
provisioner "file" {
source = "./tests/goss-linux.yaml"
destination = "/tmp/goss-linux.yaml"
}
provisioner "file" {
source = "./tests/goss-common.yaml"
destination = "/tmp/goss-common.yaml"
}
provisioner "breakpoint" {
note = "Enable this breakpoint to pause before trying to run goss tests"
disable = true
}
provisioner "shell" {
execute_command = "{{ .Vars }} sudo -E su - jenkins -c \"bash -eu '{{ .Path }}'\""
environment_vars = local.provisioning_env_vars
inline = [
"source /home/jenkins/.asdf/asdf.sh", # Required as this is a non-interactive and non-login `bash`
"goss --version",
"goss --gossfile /tmp/goss-linux.yaml --loglevel DEBUG validate",
"goss --gossfile /tmp/goss-common.yaml --loglevel DEBUG validate",
]
}
post-processor "docker-tag" {
only = ["docker.ubuntu"]
# TODO specify architecture in image name with local.image_name
repository = format("%s/jenkins-agent-%s-%s", var.docker_namespace, var.agent_os_type, var.agent_os_version)
tags = [var.image_version, "latest"]
}
}