@@ -116,51 +116,50 @@ jobs:
116116 sudo mkdir -p "/etc/docker/certs.d/${REGISTRY_HOST}"
117117 echo "$REGISTRY_CA_CERT" | sudo tee "/etc/docker/certs.d/${REGISTRY_HOST}/ca.crt" > /dev/null
118118
119+ # Store the cert for later injection into BuildKit
120+ echo "$REGISTRY_CA_CERT" > /tmp/registry-ca.crt
121+
119122 echo "✓ CA certificate installed for ${REGISTRY_HOST}"
120123
121124 # BuildKit in docker-container driver runs in an isolated container.
122- # We configure it to trust the registry by providing the buildkitd config
123- # that references certs from the host mounted via buildkitd-flags.
124- - name : Set up Docker Buildx (with CA)
125- if : steps.ca-cert.outputs.has_ca_cert == 'true'
125+ # We set up the builder first, then inject the CA cert into the container.
126+ - name : Set up Docker Buildx
126127 uses : docker/setup-buildx-action@v3
127128 with :
128129 driver : docker-container
129- buildkitd-config-inline : |
130- [registry."${{ inputs.registry_host }}"]
131- insecure = false
132- ca = ["/etc/docker-certs/ca.crt"]
133130 driver-opts : |
134131 image=moby/buildkit:buildx-stable-1
132+ network=host
135133
134+ # Inject CA cert into BuildKit container's trust store
136135 - name : Configure BuildKit CA certificate
137136 if : steps.ca-cert.outputs.has_ca_cert == 'true'
138- env :
139- REGISTRY_HOST : ${{ inputs.registry_host }}
140137 run : |
141138 # Get the BuildKit container name
142139 BUILDKIT_CONTAINER=$(docker ps --filter "name=buildx_buildkit" --format "{{.Names}}" | head -1)
143140
144141 if [[ -z "$BUILDKIT_CONTAINER" ]]; then
145142 echo "ERROR: BuildKit container not found"
143+ docker ps -a
146144 exit 1
147145 fi
148146
149147 echo "Found BuildKit container: ${BUILDKIT_CONTAINER}"
150148
151- # Create the certs directory inside the BuildKit container
152- docker exec "$BUILDKIT_CONTAINER" mkdir -p /etc/docker-certs
153-
154149 # Copy the CA certificate into the BuildKit container
155- docker cp "/etc/docker/certs.d/${REGISTRY_HOST}/ ca.crt" "${BUILDKIT_CONTAINER}:/etc/docker-certs/ ca.crt"
150+ docker cp /tmp/registry- ca.crt "${BUILDKIT_CONTAINER}:/usr/local/share/ca-certificates/registry- ca.crt"
156151
157- # Restart the BuildKit daemon to pick up the config
158- # Note: buildkitd will re-read config on the next build
159- echo "✓ CA certificate copied to BuildKit container"
160-
161- - name : Set up Docker Buildx (without CA)
162- if : steps.ca-cert.outputs.has_ca_cert != 'true'
163- uses : docker/setup-buildx-action@v3
152+ # Update CA certificates inside the BuildKit container
153+ docker exec "$BUILDKIT_CONTAINER" update-ca-certificates 2>/dev/null || \
154+ docker exec "$BUILDKIT_CONTAINER" cat /usr/local/share/ca-certificates/registry-ca.crt >> /etc/ssl/certs/ca-certificates.crt
155+
156+ # Restart buildkitd to pick up the new CA bundle
157+ docker restart "$BUILDKIT_CONTAINER"
158+
159+ # Wait for buildkitd to be ready
160+ sleep 3
161+
162+ echo "✓ CA certificate configured in BuildKit container"
164163
165164 - name : Login to Artifactory
166165 uses : docker/login-action@v3
0 commit comments