From 28852106c784213cf3da6ecd28f113c1057bddf1 Mon Sep 17 00:00:00 2001 From: Sean Arms <67096+lesserwhirls@users.noreply.github.com> Date: Mon, 16 Dec 2024 16:12:13 -0700 Subject: [PATCH] migrate packer config from json to hcl --- .github/workflows/packer.yml | 2 +- packer/thredds-test-env.pkr.hcl | 139 ++++++++++++++++++++++++++++++++ 2 files changed, 140 insertions(+), 1 deletion(-) create mode 100644 packer/thredds-test-env.pkr.hcl diff --git a/.github/workflows/packer.yml b/.github/workflows/packer.yml index 94c933b..af37636 100644 --- a/.github/workflows/packer.yml +++ b/.github/workflows/packer.yml @@ -17,4 +17,4 @@ jobs: with: command: validate working_directory: packer - target: thredds-test-env.json + target: thredds-test-env.pkr.hcl diff --git a/packer/thredds-test-env.pkr.hcl b/packer/thredds-test-env.pkr.hcl new file mode 100644 index 0000000..c032c11 --- /dev/null +++ b/packer/thredds-test-env.pkr.hcl @@ -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",] + } +}