Skip to content

Commit

Permalink
migrate packer config from json to hcl
Browse files Browse the repository at this point in the history
  • Loading branch information
lesserwhirls committed Dec 16, 2024
1 parent e6536c2 commit 2885210
Show file tree
Hide file tree
Showing 2 changed files with 140 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .github/workflows/packer.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ jobs:
with:
command: validate
working_directory: packer
target: thredds-test-env.json
target: thredds-test-env.pkr.hcl
139 changes: 139 additions & 0 deletions packer/thredds-test-env.pkr.hcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
packer {
required_plugins {
ansible = {
source = "github.com/hashicorp/ansible"
version = "~> 1"
}
docker = {
source = "github.com/hashicorp/docker"
version = "~> 1"
}
}
}

locals {
base_docker_image = "ubuntu:20.04"
thredds_test_user = "jenkins"
}

source "docker" "docker-jenkins" {
changes = ["USER ${local.thredds_test_user}",
"ENTRYPOINT [\"/home/${local.thredds_test_user}/jenkins-agent.sh\"]",
]
commit = true
image = "${local.base_docker_image}"
platform = "linux/amd64"
}

source "docker" "docker-export" {
changes = ["USER ${local.thredds_test_user}",
"ENTRYPOINT [\"/bin/bash\"]",
]
export_path = "image.tar"
image = "${local.base_docker_image}"
platform = "linux/amd64"
}

source "docker" "docker-github-action" {
changes = ["USER root", "ENV GITHUB_ACTIONS=\"YEP\"",
"ENTRYPOINT [\"/entrypoint.sh\"]",
]
commit = true
image = "${local.base_docker_image}"
platform = "linux/amd64"
}

source "docker" "docker-github-action-nexus" {
changes = ["USER root", "ENV GITHUB_ACTIONS=\"YEP\"",
"ENTRYPOINT [\"/entrypoint.sh\"]"
]
commit = true
image = "${local.base_docker_image}"
platform = "linux/amd64"
}

build {
sources = ["source.docker.docker-jenkins",
"source.docker.docker-export",
"source.docker.docker-github-action",
"source.docker.docker-github-action-nexus",
]

provisioner "shell" {
script = "provisioners/scripts/bootstrap-common.sh"
}

provisioner "file" {
destination = "/entrypoint.sh"
source = "provisioners/file/entrypoint.sh"
only = ["docker.docker-github-action", "docker.docker-github-action-nexus"]
}

provisioner "ansible-local" {
clean_staging_directory = true
command = "ANSIBLE_CONFIG=/ansible_config/ansible.cfg ANSIBLE_FORCE_COLOR=1 PYTHONUNBUFFERED=1 ansible-playbook"
extra_arguments = ["--extra-vars", "\"thredds_test_user=${local.thredds_test_user}\""]
galaxy_file = "provisioners/ansible/requirements.yml"
group_vars = "provisioners/ansible/group_vars"
playbook_file = "provisioners/ansible/site.yml"
role_paths = ["provisioners/ansible/roles/cleanup",
"provisioners/ansible/roles/general-packages",
"provisioners/ansible/roles/init",
"provisioners/ansible/roles/libnetcdf-and-deps",
"provisioners/ansible/roles/maven",
"provisioners/ansible/roles/miniconda",
"provisioners/ansible/roles/security",
"provisioners/ansible/roles/temurin",
"provisioners/ansible/roles/thredds-test-data-mount-prep",
"provisioners/ansible/roles/zulu",
]
}

provisioner "file" {
destination = "/home/${local.thredds_test_user}/jenkins-agent.sh"
source = "provisioners/file/jenkins-agent.sh"
only = ["docker.docker-jenkins",]
}

provisioner "shell" {
inline = ["dos2unix /home/${local.thredds_test_user}/jenkins-agent.sh",
"chown ${local.thredds_test_user}:${local.thredds_test_user} /home/${local.thredds_test_user}/jenkins-agent.sh",
"chmod 755 /home/${local.thredds_test_user}/jenkins-agent.sh",
]
only = ["docker.docker-jenkins",]
}

provisioner "shell" {
inline = ["wget https://jenkins.unidata.ucar.edu/jnlpJars/agent.jar -P /home/${local.thredds_test_user}",
"chown ${local.thredds_test_user}:${local.thredds_test_user} /home/${local.thredds_test_user}/agent.jar",
]
only = ["docker.docker-jenkins",]
}

provisioner "shell" {
inline = ["dos2unix /entrypoint.sh"]
only = ["docker.docker-github-action",
"docker.docker-github-action-nexus",
]
}

provisioner "shell" {
script = "provisioners/scripts/cleanup.sh"
}

post-processor "docker-tag" {
only = ["docker.docker-jenkins"]
repository = "docker.unidata.ucar.edu/thredds-test-environment"
tags = ["latest",]
}
post-processor "docker-tag" {
only = ["docker.docker-github-action"]
repository = "ghcr.io/unidata/thredds-test-action"
tags = ["v2",]
}
post-processor "docker-tag" {
only = ["docker.docker-github-action-nexus"]
repository = "docker.unidata.ucar.edu/thredds-test-action"
tags = ["v2",]
}
}

0 comments on commit 2885210

Please sign in to comment.