From b6a03484e13441251ed1e92a8f1e759b22ed0b59 Mon Sep 17 00:00:00 2001 From: Danny Bessems Date: Thu, 9 Mar 2023 12:45:51 +0100 Subject: [PATCH] Add container registry login --- .drone.yml | 22 +++++++++++++------ .../roles/assets/tasks/containerimages.yml | 9 ++++++++ packer/build.pkr.hcl | 2 ++ packer/variables.pkr.hcl | 5 +++++ 4 files changed, 31 insertions(+), 7 deletions(-) diff --git a/.drone.yml b/.drone.yml index ff210d3..c9961ae 100644 --- a/.drone.yml +++ b/.drone.yml @@ -39,30 +39,38 @@ steps: - | packer validate \ -var vm_name=$DRONE_BUILD_NUMBER-${DRONE_COMMIT_SHA:0:10} \ + -var docker_username=$${DOCKER_USERNAME} \ + -var docker_password=$${DOCKER_PASSWORD} \ -var repo_username=$${REPO_USERNAME} \ -var repo_password=$${REPO_PASSWORD} \ - -var vsphere_password=$${VSPHERE_PASSWORD} \ -var ssh_password=$${SSH_PASSWORD} \ + -var vsphere_password=$${VSPHERE_PASSWORD} \ ./packer - | packer build \ -on-error=cleanup -timestamp-ui \ -var vm_name=$DRONE_BUILD_NUMBER-${DRONE_COMMIT_SHA:0:10} \ + -var docker_username=$${DOCKER_USERNAME} \ + -var docker_password=$${DOCKER_PASSWORD} \ -var repo_username=$${REPO_USERNAME} \ -var repo_password=$${REPO_PASSWORD} \ - -var vsphere_password=$${VSPHERE_PASSWORD} \ -var ssh_password=$${SSH_PASSWORD} \ + -var vsphere_password=$${VSPHERE_PASSWORD} \ ./packer environment: - VSPHERE_PASSWORD: - from_secret: vsphere_password - SSH_PASSWORD: - from_secret: ssh_password + DOCKER_USERNAME: + from_secret: docker_username + DOCKER_PASSWORD: + from_secret: docker_password + # PACKER_LOG: 1 REPO_USERNAME: from_secret: repo_username REPO_PASSWORD: from_secret: repo_password - # PACKER_LOG: 1 + SSH_PASSWORD: + from_secret: ssh_password + VSPHERE_PASSWORD: + from_secret: vsphere_password volumes: - name: output path: /output diff --git a/ansible/roles/assets/tasks/containerimages.yml b/ansible/roles/assets/tasks/containerimages.yml index fac5068..74ef9ed 100644 --- a/ansible/roles/assets/tasks/containerimages.yml +++ b/ansible/roles/assets/tasks/containerimages.yml @@ -37,6 +37,15 @@ loop_control: label: "{{ item.source }}" +- name: Log in to container registry + ansible.builtin.shell: + cmd: >- + skopeo login \ + docker.io \ + --username={{ docker_username }} \ + --password={{ docker_password }} + no_log: true + - name: Pull and store containerimages ansible.builtin.shell: cmd: >- diff --git a/packer/build.pkr.hcl b/packer/build.pkr.hcl index 75e0532..781b1be 100644 --- a/packer/build.pkr.hcl +++ b/packer/build.pkr.hcl @@ -37,6 +37,8 @@ build { extra_arguments = [ "--extra-vars", "appliancetype=${source.name}", "--extra-vars", "ansible_ssh_pass=${var.ssh_password}", + "--extra-vars", "docker_username=${var.docker_username}", + "--extra-vars", "docker_password=${var.docker_password}" "--extra-vars", "repo_username=${var.repo_username}", "--extra-vars", "repo_password=${var.repo_password}" ] diff --git a/packer/variables.pkr.hcl b/packer/variables.pkr.hcl index c8d0af5..5321395 100644 --- a/packer/variables.pkr.hcl +++ b/packer/variables.pkr.hcl @@ -28,3 +28,8 @@ local "iso_authenticatedurl" { expression = "https://${var.repo_username}:${var.repo_password}@${var.iso_url}" sensitive = true } + +variable "docker_username" {} +variable "docker_password" { + sensitive = true +}