From 7df2303deacaa7efb864c0621a2a28a1858fb00a Mon Sep 17 00:00:00 2001 From: jalr Date: Sun, 18 Mar 2018 01:14:16 +0100 Subject: [PATCH] Fix CI environment variable passing; write CI vars to /etc/environment --- Makefile | 3 ++- packer/ansible/inventories/qemu | 3 +++ packer/debian-stretch.json | 15 ++++++++------- packer/initramfs/labsync | 2 +- 4 files changed, 14 insertions(+), 9 deletions(-) create mode 100644 packer/ansible/inventories/qemu diff --git a/Makefile b/Makefile index 5498308..dbba462 100644 --- a/Makefile +++ b/Makefile @@ -16,7 +16,6 @@ qemu_disk = tmp/qemu-disk.img qemu_target ?= debian-stretch qemu_kernel = $(qemu_target).linux qemu_torrent = $(qemu_target).torrent - qemu_initramfs = $(shell \ if [ -e $(qemu_target).initramfs.dev ] && [ `date -r $(qemu_target).initramfs.dev +%s` -gt `date -r $(qemu_target).initramfs +%s` ]; then \ echo "$(qemu_target).initramfs.dev"; \ @@ -24,6 +23,7 @@ else \ echo "$(qemu_target).initramfs"; \ fi \ ) +ci_environment=$(shell env | sed -n 's/^\(CI_.*\)=.*/-e \1/p') .PHONY: default default: dockerimg images/debian-stretch.squashfs @@ -51,6 +51,7 @@ images/debian-stretch.squashfs: images -e "group=`id -g`" \ -e "ANNOUNCE=$(ANNOUNCE)" \ -e "WEBSEED=$(WEBSEED)" \ + $(ci_environment) \ "$(DOCKER_IMAGE)" \ debian-stretch diff --git a/packer/ansible/inventories/qemu b/packer/ansible/inventories/qemu new file mode 100644 index 0000000..90ce6ad --- /dev/null +++ b/packer/ansible/inventories/qemu @@ -0,0 +1,3 @@ +[default] +qemumachine ansible_host=10.2.2.10 +spielkiste ansible_host=10.105.255.154 diff --git a/packer/debian-stretch.json b/packer/debian-stretch.json index 297b144..55a3aea 100644 --- a/packer/debian-stretch.json +++ b/packer/debian-stretch.json @@ -7,7 +7,7 @@ "ci_commit_ref_slug": "{{env `CI_COMMIT_REF_SLUG`}}", "ci_job_name": "{{env `CI_JOB_NAME`}}", "ci_job_stage": "{{env `CI_JOB_STAGE`}}", - "ci_repository_url": "{{env `CI_REPOSITORY_URL`}}", + "ci_project_url": "{{env `CI_PROJECT_URL`}}", "ci_pipeline_triggered": "{{env `PIPELINE_TRIGGERED`}}", "ci_job_manual": "{{env `CI_JOB_MANUAL`}}" }, @@ -32,7 +32,13 @@ { "type": "shell", "inline": [ - "sed -i 's/@@CI_REPOSITORY_URL@@/{{user `ci_repository_url`}}/' /etc/initramfs-tools/scripts/labsync" + "echo \"LABSYNC_JOB_ID='{{user `ci_job_id`}}'\" >> /etc/environment", + "echo \"LABSYNC_COMMIT_SHA='{{user `ci_commit_sha`}}'\" >> /etc/environment", + "echo \"LABSYNC_COMMIT_TAG='{{user `ci_commit_tag`}}'\" >> /etc/environment", + "echo \"LABSYNC_COMMIT_REF_NAME='{{user `ci_commit_ref_name`}}'\" >> /etc/environment", + "echo \"LABSYNC_COMMIT_REF_SLUG='{{user `ci_commit_ref_slug`}}'\" >> /etc/environment", + "echo \"LABSYNC_PROJECT_URL='{{user `ci_project_url`}}'\" >> /etc/environment", + "sed -i 's#@@PROJECT_URL@@#{{user `ci_project_url`}}#' /etc/initramfs-tools/scripts/labsync" ] }, { @@ -44,11 +50,6 @@ "type": "shell", "inline": [ "set -x", - "echo \"job: {{user `ci_job_id`}}\" > /.build-info", - "echo \"commit: {{user `ci_commit_sha`}}\" >> /.build-info", - "echo \"commit tag: {{user `ci_commit_tag`}}\" >> /.build-info", - "echo \"commit ref name: {{user `ci_commit_ref_name`}}\" >> /.build-info", - "echo \"commit ref slug: {{user `ci_commit_ref_slug`}}\" >> /.build-info", "apt-get update", "apt-get -y dist-upgrade", "rmdir /boot && ln -s /usr/local/boot /boot", diff --git a/packer/initramfs/labsync b/packer/initramfs/labsync index df7f3c7..a52ea91 100755 --- a/packer/initramfs/labsync +++ b/packer/initramfs/labsync @@ -58,7 +58,7 @@ Starting "mm "mm"# ##m#" "mmm" "# # # "#mm" m" "" -@@CI_REPOSITORY_URL@@ +@@PROJECT_URL@@ EOM }