From 761bf9cb9c03313c2d378c7e08cda44468c05ac3 Mon Sep 17 00:00:00 2001
From: Jean-Paul Calderone <exarkun@twistedmatrix.com>
Date: Wed, 14 Dec 2022 09:49:50 -0500
Subject: [PATCH 1/7] See if we can get a triggered image build too

---
 .circleci/config.yml | 72 ++++++++++++++++++++++++++++----------------
 1 file changed, 46 insertions(+), 26 deletions(-)

diff --git a/.circleci/config.yml b/.circleci/config.yml
index d7e4f2563..446c6b3a9 100644
--- a/.circleci/config.yml
+++ b/.circleci/config.yml
@@ -11,8 +11,45 @@
 #
 version: 2.1
 
+# A template that can be shared between the two different image-building
+# workflows.
+.images: &IMAGES
+  jobs:
+    # Every job that pushes a Docker image from Docker Hub needs to provide
+    # credentials.  Use this first job to define a yaml anchor that can be
+    # used to supply a CircleCI job context which makes Docker Hub credentials
+    # available in the environment.
+    #
+    # Contexts are managed in the CircleCI web interface:
+    #
+    #  https://app.circleci.com/settings/organization/github/tahoe-lafs/contexts
+    - "build-image-debian-10": &DOCKERHUB_CONTEXT
+        context: "dockerhub-auth"
+    - "build-image-debian-11":
+        <<: *DOCKERHUB_CONTEXT
+    - "build-image-ubuntu-18-04":
+        <<: *DOCKERHUB_CONTEXT
+    - "build-image-ubuntu-20-04":
+        <<: *DOCKERHUB_CONTEXT
+    - "build-image-fedora-35":
+        <<: *DOCKERHUB_CONTEXT
+    - "build-image-oraclelinux-8":
+        <<: *DOCKERHUB_CONTEXT
+    # Restore later as PyPy38
+    #- "build-image-pypy27-buster":
+    #    <<: *DOCKERHUB_CONTEXT
+
+parameters:
+  build-images:
+    default: false
+    type: "boolean"
+  run-tests:
+    default: true
+    type: "boolean"
+
 workflows:
   ci:
+    when: "<< pipeline.parameters.run-tests >>"
     jobs:
       # Start with jobs testing various platforms.
       - "debian-10":
@@ -64,7 +101,15 @@ workflows:
       - "docs":
           {}
 
-  images:
+  triggered-images:
+    <<: *IMAGES
+
+    # Build as part of the workflow but only if requested.
+    when: "<< pipeline.parameters.build-images >>"
+
+  scheduled-images:
+    <<: *IMAGES
+
     # Build the Docker images used by the ci jobs.  This makes the ci jobs
     # faster and takes various spurious failures out of the critical path.
     triggers:
@@ -76,31 +121,6 @@ workflows:
               only:
                 - "master"
 
-    jobs:
-      # Every job that pushes a Docker image from Docker Hub needs to provide
-      # credentials.  Use this first job to define a yaml anchor that can be
-      # used to supply a CircleCI job context which makes Docker Hub
-      # credentials available in the environment.
-      #
-      # Contexts are managed in the CircleCI web interface:
-      #
-      #  https://app.circleci.com/settings/organization/github/tahoe-lafs/contexts
-      - "build-image-debian-10": &DOCKERHUB_CONTEXT
-          context: "dockerhub-auth"
-      - "build-image-debian-11":
-          <<: *DOCKERHUB_CONTEXT
-      - "build-image-ubuntu-18-04":
-          <<: *DOCKERHUB_CONTEXT
-      - "build-image-ubuntu-20-04":
-          <<: *DOCKERHUB_CONTEXT
-      - "build-image-fedora-35":
-          <<: *DOCKERHUB_CONTEXT
-      - "build-image-oraclelinux-8":
-          <<: *DOCKERHUB_CONTEXT
-      # Restore later as PyPy38
-      #- "build-image-pypy27-buster":
-      #    <<: *DOCKERHUB_CONTEXT
-
 
 jobs:
   dockerhub-auth-template:

From 1d248f4bd2d9fd9313cf419f94ec8ebbed31fdd0 Mon Sep 17 00:00:00 2001
From: Jean-Paul Calderone <exarkun@twistedmatrix.com>
Date: Wed, 14 Dec 2022 09:56:16 -0500
Subject: [PATCH 2/7] comments

---
 .circleci/config.yml | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/.circleci/config.yml b/.circleci/config.yml
index 446c6b3a9..b7c6cdbee 100644
--- a/.circleci/config.yml
+++ b/.circleci/config.yml
@@ -40,9 +40,17 @@ version: 2.1
     #    <<: *DOCKERHUB_CONTEXT
 
 parameters:
+  # Control whether the image-building workflow runs as part of this pipeline.
+  # Generally we do not want this to run because we don't need our
+  # dependencies to move around all the time and because building the image
+  # takes a couple minutes.
   build-images:
     default: false
     type: "boolean"
+
+  # Control whether the test-running workflow runs as part of this pipeline.
+  # Generally we do want this to run because running the tests is the primary
+  # purpose of this pipeline.
   run-tests:
     default: true
     type: "boolean"

From d66d928fb4abf7a81dce91fdca2583c32cd64cf9 Mon Sep 17 00:00:00 2001
From: Jean-Paul Calderone <exarkun@twistedmatrix.com>
Date: Wed, 14 Dec 2022 10:07:07 -0500
Subject: [PATCH 3/7] Provide a helper for rebuilding the images

---
 .circleci/rebuild-images.sh | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)
 create mode 100644 .circleci/rebuild-images.sh

diff --git a/.circleci/rebuild-images.sh b/.circleci/rebuild-images.sh
new file mode 100644
index 000000000..7ee17b8ff
--- /dev/null
+++ b/.circleci/rebuild-images.sh
@@ -0,0 +1,20 @@
+#!/usr/bin/env bash
+
+set -euo pipefail
+
+# Get your API token here:
+# https://app.circleci.com/settings/user/tokens
+API_TOKEN=$1
+shift
+
+# Name the branch you want to trigger the build for
+BRANCH=$1
+shift
+
+curl \
+    --verbose \
+    --request POST \
+    --url https://circleci.com/api/v2/project/gh/tahoe-lafs/tahoe-lafs/pipeline \
+    --header 'Circle-Token: $API_TOKEN' \
+    --header 'content-type: application/json' \
+    --data '{"branch":"$BRANCH","parameters":{"build-images":true,"run-tests":false}}'

From 793033caa8004851c7d35f9378101972a84f849f Mon Sep 17 00:00:00 2001
From: Jean-Paul Calderone <exarkun@twistedmatrix.com>
Date: Wed, 14 Dec 2022 12:44:11 -0500
Subject: [PATCH 4/7] Fix quoting on the helper

---
 .circleci/rebuild-images.sh | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
 mode change 100644 => 100755 .circleci/rebuild-images.sh

diff --git a/.circleci/rebuild-images.sh b/.circleci/rebuild-images.sh
old mode 100644
new mode 100755
index 7ee17b8ff..901651905
--- a/.circleci/rebuild-images.sh
+++ b/.circleci/rebuild-images.sh
@@ -15,6 +15,6 @@ curl \
     --verbose \
     --request POST \
     --url https://circleci.com/api/v2/project/gh/tahoe-lafs/tahoe-lafs/pipeline \
-    --header 'Circle-Token: $API_TOKEN' \
-    --header 'content-type: application/json' \
-    --data '{"branch":"$BRANCH","parameters":{"build-images":true,"run-tests":false}}'
+    --header "Circle-Token: $API_TOKEN" \
+    --header "content-type: application/json" \
+    --data '{"branch":"'"$BRANCH"'","parameters":{"build-images":true,"run-tests":false}}'

From f053ef371a2162a9ac9c833694e534c8a0cdfad4 Mon Sep 17 00:00:00 2001
From: Jean-Paul Calderone <exarkun@twistedmatrix.com>
Date: Wed, 14 Dec 2022 12:47:50 -0500
Subject: [PATCH 5/7] Get rid of the scheduled image building workflow.

---
 .circleci/config.yml | 16 +---------------
 1 file changed, 1 insertion(+), 15 deletions(-)

diff --git a/.circleci/config.yml b/.circleci/config.yml
index b7c6cdbee..722ad390f 100644
--- a/.circleci/config.yml
+++ b/.circleci/config.yml
@@ -109,26 +109,12 @@ workflows:
       - "docs":
           {}
 
-  triggered-images:
+  images:
     <<: *IMAGES
 
     # Build as part of the workflow but only if requested.
     when: "<< pipeline.parameters.build-images >>"
 
-  scheduled-images:
-    <<: *IMAGES
-
-    # Build the Docker images used by the ci jobs.  This makes the ci jobs
-    # faster and takes various spurious failures out of the critical path.
-    triggers:
-      # Build once a day
-      - schedule:
-          cron: "0 0 * * *"
-          filters:
-            branches:
-              only:
-                - "master"
-
 
 jobs:
   dockerhub-auth-template:

From 63fd24d0607cf4a9440f4837f58347e1caab6300 Mon Sep 17 00:00:00 2001
From: Jean-Paul Calderone <exarkun@twistedmatrix.com>
Date: Wed, 14 Dec 2022 12:48:53 -0500
Subject: [PATCH 6/7] Note how you can get this parameter set

---
 .circleci/config.yml | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/.circleci/config.yml b/.circleci/config.yml
index 722ad390f..480926825 100644
--- a/.circleci/config.yml
+++ b/.circleci/config.yml
@@ -44,6 +44,10 @@ parameters:
   # Generally we do not want this to run because we don't need our
   # dependencies to move around all the time and because building the image
   # takes a couple minutes.
+  #
+  # An easy way to trigger a pipeline with this set to true is with the
+  # rebuild-images.sh tool in this directory.  You can also do so via the
+  # CircleCI web UI.
   build-images:
     default: false
     type: "boolean"

From 8c8a04fa1bbc0e95b78e487d3734504f50be8120 Mon Sep 17 00:00:00 2001
From: Jean-Paul Calderone <exarkun@twistedmatrix.com>
Date: Wed, 14 Dec 2022 13:24:36 -0500
Subject: [PATCH 7/7] news fragment

---
 newsfragments/3958.minor | 0
 1 file changed, 0 insertions(+), 0 deletions(-)
 create mode 100644 newsfragments/3958.minor

diff --git a/newsfragments/3958.minor b/newsfragments/3958.minor
new file mode 100644
index 000000000..e69de29bb