Skip to content

Commit c06b1bb

Browse files
author
Matt Pryor
authored
Rewrite upstream sync automation to look for latest release (azimuth-cloud#127)
1 parent 41b6862 commit c06b1bb

File tree

5 files changed

+53
-37
lines changed

5 files changed

+53
-37
lines changed

.gitlab-ci.yml.sample

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22

33
default:
4-
image: python:3.9
4+
image: ubuntu:jammy
55

66
variables:
77
# Because we are installing git-crypt as part of the job, we cannot reuse old
@@ -10,12 +10,13 @@ variables:
1010
# Write the Azimuth URL to an envfile in the local directory
1111
AZIMUTH_URL_ENVFILE: ${CI_PROJECT_DIR}/azimuth.env
1212
# Use the pipeline credentials for Terraform
13+
# This assumes that we are using GitLab-managed Terraform state (recommended when available)
1314
TF_HTTP_USERNAME: gitlab-ci-token
1415
TF_HTTP_PASSWORD: $CI_JOB_TOKEN
1516

1617
stages:
1718
# This stage owns the scheduled job that checks for upstream changes
18-
- upstream-merge
19+
- scheduled
1920
# This stage owns the deploy and teardown jobs for dynamic environments
2021
- aio
2122
# This stage owns the deploy job for our staging environment
@@ -24,23 +25,26 @@ stages:
2425
- production
2526

2627
#####
27-
# This job checks to see if there are changes from upstream to be merged
28+
# This job checks to see if there is a new release that needs to be merged
2829
#
29-
# If there are, it will create a new branch containing the changes and a corresponding merge request
30+
# If there is, it will create a new branch containing the changes and a corresponding merge request
3031
#
3132
# It runs as a scheduled job, for which a suitable schedule must be defined, e.g. daily or weekly
3233
#
3334
# This job writes back to the repository and to the merge requests API
3435
# To do this, it needs more power than is granted to the CI token
3536
# So CI variables must be set that contain an access token and the corresponding username
36-
# This can be a Project Access Token (paid feature) or a Personal Access Token (not ideal)
37+
# This can be a Project Access Token (paid feature, recommended if available) or a Personal Access Token (not ideal)
3738
#####
38-
upstream_merge:
39-
stage: upstream-merge
39+
check_for_release:
40+
stage: scheduled
4041
rules:
4142
- if: $CI_PIPELINE_SOURCE == "schedule" && $CI_COMMIT_BRANCH == "main"
4243
variables:
4344
GIT_STRATEGY: none
45+
before_script:
46+
- apt update -y
47+
- apt install -y curl git jq
4448
script:
4549
# Configure git to use the available credentials
4650
- git config --global credential.helper store
@@ -58,7 +62,7 @@ upstream_merge:
5862
source ".mergeenv"
5963
BODY="{
6064
\"id\": ${CI_PROJECT_ID},
61-
\"title\": \"[$UPSTREAM_COMMIT] Merge changes from upstream\",
65+
\"title\": \"Upgrade Azimuth to ${RELEASE_TAG}\",
6266
\"source_branch\": \"${BRANCH_NAME}\",
6367
\"target_branch\": \"main\",
6468
\"remove_source_branch\": true,

bin/ci-exec

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/usr/bin/env bash
22

33
#####
4-
# This script is designed to be run in a CI pipeline in an isolated Ubuntu 20.04 environment
4+
# This script is designed to be run in a CI pipeline in an isolated Ubuntu Jammy environment
55
#####
66

77
set -eo pipefail
@@ -30,7 +30,6 @@ function run_apt {
3030
fi
3131
}
3232

33-
3433
if [ -n "$GIT_CRYPT_KEY_B64" ]; then
3534
# Unlock the repository
3635
run_apt update
@@ -55,7 +54,7 @@ if [ -z "$AZIMUTH_ENVIRONMENT" ]; then
5554
fi
5655

5756
run_apt update
58-
run_apt install -y qemu-utils
57+
run_apt install -y git python3 python3-pip qemu-utils
5958
pip install -U pip
6059
pip install -r requirements.txt
6160

bin/create-merge-branch

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/usr/bin/env bash
22

33
#####
4-
# This script creates a branch that merges the latest upstream changes
4+
# This script creates a branch that merges the latest release
55
#####
66

77
set -e
@@ -18,29 +18,33 @@ if [ -n "$(git status --short)" ]; then
1818
exit 1
1919
fi
2020

21-
if ! git remote show upstream > /dev/null 2>&1; then
22-
echo "[INFO] Adding upstream remote..."
23-
git remote add upstream https://github.com/stackhpc/azimuth-config.git
24-
fi
21+
UPSTREAM_REPO="${UPSTREAM_REPO:-"stackhpc/azimuth-config"}"
22+
echo "[INFO] Using upstream repo - $UPSTREAM_REPO"
23+
24+
# Fetch the tag for the latest release from the upstream repository
25+
RELEASE_TAG="$(curl -fsSL "https://api.github.com/repos/${UPSTREAM_REPO}/releases/latest" | jq -r '.tag_name')"
26+
echo "[INFO] Found latest release tag - $RELEASE_TAG"
2527

28+
# Add the repository as an upstream
29+
echo "[INFO] Adding upstream remote..."
30+
git remote add upstream "https://github.com/${UPSTREAM_REPO}.git"
2631
git remote show upstream
2732

28-
echo "[INFO] Fetching remote branches..."
29-
git fetch upstream
33+
echo "[INFO] Fetching remote tags..."
34+
git remote update
3035

31-
# Use the short sha from the upstream branch to distinguish merge branches
32-
UPSTREAM_COMMIT="$(git rev-parse --short upstream/main)"
33-
BRANCH_NAME="upstream-merge-${UPSTREAM_COMMIT}"
36+
# Use a branch that is named for the release
37+
BRANCH_NAME="upgrade/$RELEASE_TAG"
3438

3539
# Check if the branch already exists on the origin
36-
# If it does, there is nothing more to do as the branch can be rebased from the MR if required
40+
# If it does, there is nothing more to do as the branch can be rebased from the MR
3741
if git show-branch "remotes/origin/$BRANCH_NAME" >/dev/null 2>&1; then
38-
echo "[INFO] Merge branch already created for commit '${UPSTREAM_COMMIT}'"
42+
echo "[INFO] Merge branch already created for $RELEASE_TAG"
3943
exit
4044
fi
4145

42-
echo "[INFO] Attempting to merge from upstream"
43-
git merge --strategy recursive -X theirs --no-commit upstream/main
46+
echo "[INFO] Merging release tag - $RELEASE_TAG"
47+
git merge --strategy recursive -X theirs --no-commit $RELEASE_TAG
4448

4549
# Check if the merge resulted in any changes being staged
4650
if [ -n "$(git status --short)" ]; then
@@ -50,8 +54,8 @@ if [ -n "$(git status --short)" ]; then
5054
echo "[INFO] Checking out temporary branch '$BRANCH_NAME'..."
5155
git checkout -b "$BRANCH_NAME"
5256

53-
echo "[INFO] Committing changes from upstream"
54-
git commit -m "Merging changes from upstream"
57+
echo "[INFO] Committing changes"
58+
git commit -m "Upgrade Azimuth to $RELEASE_TAG"
5559

5660
echo "[INFO] Pushing changes to origin"
5761
git push --set-upstream origin "$BRANCH_NAME"
@@ -63,10 +67,10 @@ if [ -n "$(git status --short)" ]; then
6367
echo "[INFO] Removing temporary branch"
6468
git branch -d "$BRANCH_NAME"
6569

66-
# Write a file containing the branch name and upstream commit
70+
# Write a file containing the branch name and tag
6771
# for automatic PR or MR creation that follows
6872
echo "BRANCH_NAME=\"$BRANCH_NAME\"" > .mergeenv
69-
echo "UPSTREAM_COMMIT=\"$UPSTREAM_COMMIT\"" >> .mergeenv
73+
echo "RELEASE_TAG=\"$RELEASE_TAG\"" >> .mergeenv
7074
else
7175
echo "[INFO] Merge resulted in no changes"
7276
fi

docs/deployment/automation.md

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -157,18 +157,21 @@ azimuth_current_cloud_label: "{{ lookup('env', 'CI_ENVIRONMENT_NAME') }}"
157157
# "Secrets"
158158
# Since the dynamic environments are short-lived, there is not much
159159
# risk in using secrets that are not really secret for ease
160+
admin_dashboard_ingress_basic_auth_password: admin
160161
harbor_admin_password: admin
161-
harbor_secret_key: notsecret0123456
162-
zenith_registrar_subdomain_token_signing_key: notsecret
163-
azimuth_secret_key: notsecret
162+
harbor_secret_key: abcdefghijklmnop
163+
keycloak_admin_password: admin
164+
zenith_registrar_subdomain_token_signing_key: abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789AA
165+
azimuth_secret_key: 9876543210ZYXWVUTSRQPONMLKJIHGFEDCBAzyxwvutsrqponmlkjihgfedcda00
164166
```
165167
166-
### Automated synchronisation of upstream changes
168+
### Automated upgrades
167169
168170
The sample configuration also includes a job that can automatically
169-
[synchronise changes from upstream](../repository/index.md#synchronising-changes-from-upstream).
171+
[propose an Azimuth upgrade](../repository/index.md#upgrading-to-a-new-azimuth-release)
172+
when a new release becomes available.
170173
171-
If the job detects changes, it will create a new branch, merge the changes
174+
If the job detects a new release, it will create a new branch, merge the changes
172175
into it and create an associated
173176
[merge request](https://docs.gitlab.com/ee/user/project/merge_requests/).
174177
If you also have
@@ -177,10 +180,10 @@ enabled, then this will automatically trigger a job to deploy the changes for re
177180
178181
The job will only run for a
179182
[scheduled pipeline](https://docs.gitlab.com/ee/ci/pipelines/schedules.html), so
180-
if you want to have automatic synchronisation of upstream changes you must
183+
to enable automated upgrades you must
181184
[add a pipeline schedule](https://docs.gitlab.com/ee/ci/pipelines/schedules.html#add-a-pipeline-schedule)
182185
for the `main` branch of your configuration repository with a suitable interval
183-
(e.g. daily or weekly).
186+
(e.g. weekly).
184187

185188
Because the job needs to write to the repository and call the merge requests API,
186189
the [CI/CD job token](https://docs.gitlab.com/ee/ci/jobs/ci_job_token.html) is not

docs/repository/index.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,12 @@ component versions, upgraded dependencies and new images.
102102
The available releases, with associated release notes, can be reviewed on the
103103
[Azimuth releases page](https://github.com/stackhpc/azimuth-config/releases).
104104

105+
!!! tip "Automating upgrades"
106+
107+
If you have automated deployments, which is recommended for a production installation,
108+
this process
109+
[can also be automated](../deployment/automation.md#automated-synchronisation-of-upstream-changes).
110+
105111
To upgrade your Azimuth configuration to a new release, use the following steps to create
106112
a new branch containing the upgrade:
107113

0 commit comments

Comments
 (0)