Skip to content

Commit

Permalink
ci: Use same date for all images
Browse files Browse the repository at this point in the history
Export date to artifact on one task which other tasks are depended.
Then download this artifact on other tasks and use it to set date.
  • Loading branch information
nbyavuz committed Mar 28, 2023
1 parent 56cf16f commit 0e7c02b
Showing 1 changed file with 35 additions and 9 deletions.
44 changes: 35 additions & 9 deletions .cirrus.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,16 @@ env:
# GCP_REGION
# GCP_REPO

# To use same date for the all tasks, download date artifact from
# create_date task and use it. Another method is used at the
# Windows docker-builder task because $CIRRUS_ENV can't
# be updated and this method is not working on PowerShell.
export_date_unix_shell: &export_date_unix_shell
export_date_script: |
ARTIFACT_URL=https://api.cirrus-ci.com/v1/artifact/build/${CIRRUS_BUILD_ID}/create_date/date/date.txt
curl -fsSLO ${ARTIFACT_URL}
DATE=$(cat date.txt)
echo "DATE=${DATE}" | tee -a ${CIRRUS_ENV}
# central definition for the tasks interacting with gcp

Expand Down Expand Up @@ -78,6 +88,24 @@ gcp_docker_auth_win: &gcp_docker_auth_win
gcp_docker_auth_script:
- gcloud auth configure-docker --quiet %GCP_REGION%-docker.pkg.dev

# To export date and to use this date on other tasks, have a minimal task
# that all others depend on.
task:
name: create_date

container:
image: debian:latest
cpu: 0.5
memory: 256Mi

export_date_script: |
DATE=$(date --utc +'%Y-%m-%dt%H-%M-%S')
echo "${DATE}" | tee -a date.txt
date_artifacts:
path: "date.txt"
type: text/plain


task:
matrix:
Expand Down Expand Up @@ -116,9 +144,7 @@ task:
info_script:
- packer --version

export_date_script: |
DATE=$(date --utc +'%Y-%m-%dt%H-%M-%S')
echo "DATE=${DATE}" | tee -a $CIRRUS_ENV
<<: *export_date_unix_shell

build_image_script: |
packer build \
Expand Down Expand Up @@ -178,9 +204,7 @@ task:
info_script:
- packer --version

export_date_script: |
DATE=$(date --utc +'%Y-%m-%dt%H-%M-%S')
echo "DATE=${DATE}" | tee -a $CIRRUS_ENV
<<: *export_date_unix_shell

build_image_script: |
export PACKER_LOG=1
Expand Down Expand Up @@ -275,6 +299,8 @@ task:
- docker buildx use multibuilder
- docker buildx inspect --bootstrap

<<: *export_date_unix_shell

# XXX: would be nicer to split into multiple steps, so that e.g. build vs
# upload time are visible
#
Expand All @@ -287,8 +313,6 @@ task:
#
# Disabled linux/arm64, fails currently due to reasons outside of our control
build_script: |
DATE=$(date --utc +'%Y-%m-%dt%H-%M-%S')
docker buildx build \
--platform linux/amd64 \
--build-arg DATE=$DATE \
Expand Down Expand Up @@ -330,7 +354,9 @@ docker_builder:
# switched to the powershell
- ps: |
echo "gcp_password = `"$(gcloud auth print-access-token)`"" | Out-File -Append -Encoding ASCII ${Env:PKRVARFILE}
$DATE=[datetime]::Utcnow.Tostring("yyyy-MM-dd't'HH-mm-ss")
$ARTIFACT_URL="https://api.cirrus-ci.com/v1/artifact/build/${Env:CIRRUS_BUILD_ID}/create_date/date/date.txt"
curl.exe -fsSLO ${ARTIFACT_URL}
$DATE=$(cat date.txt)
packer build `
-only "*.${Env:CIRRUS_TASK_NAME}" `
Expand Down

0 comments on commit 0e7c02b

Please sign in to comment.