Skip to content

Commit 2b4ef56

Browse files
committed
CI: updating the main container flow
CI: extend with github <> gitlab link CI: hotfix followup CI: hotfixes CI: hotfix for job CI: patch test scripts CI: configure GH token permission CI: configure gitlab test CI: switch to PAT token (CI token expires once job is done) CI: finalize test script
1 parent ab0d45c commit 2b4ef56

File tree

15 files changed

+229
-530
lines changed

15 files changed

+229
-530
lines changed

.github/workflows/start-gitlab.yml

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
name: Start GitLab CI
2+
on:
3+
# Use pull_request_target to run the workflow from the base branch (e.g., main)
4+
# This ensures the trusted workflow logic executes, even for PRs from forks.
5+
# It also grants access to secrets needed for the trigger.
6+
pull_request_target:
7+
types: [opened, synchronize, reopened]
8+
jobs:
9+
trigger-gitlab:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- name: Start Gitlab Pipeline
13+
env:
14+
# Get trigger config from secrets
15+
GL_TRIGGER_TOKEN: ${{ secrets.GL_TRIGGER_TOKEN }}
16+
GL_TRIGGER_URL: ${{ secrets.GL_TRIGGER_URL }}
17+
# Use a specific ref from secrets if provided, otherwise default to the PR's head branch name
18+
GL_TRIGGER_REF: ${{ secrets.GL_TRIGGER_REF || github.event.pull_request.head.ref }}
19+
# --- Variables to pass to GitLab ---
20+
# The commit SHA in the GitHub PR
21+
GITHUB_PR_SHA: ${{ github.event.pull_request.head.sha }}
22+
# The ref (branch name) of the PR head
23+
GITHUB_PR_REF: ${{ github.event.pull_request.head.ref }}
24+
# The repository name (e.g., 'your-org/your-repo')
25+
GITHUB_REPO: ${{ github.repository }}
26+
# The GitHub token for reporting status back
27+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
28+
run: |
29+
# --- Safety Checks ---
30+
# Ensure critical secrets are actually available (they should be with pull_request_target)
31+
if [ -z "$GL_TRIGGER_TOKEN" ]; then
32+
echo "::error::GL_TRIGGER_TOKEN secret is missing or unavailable!"
33+
exit 1
34+
fi
35+
if [ -z "$GITHUB_TOKEN" ]; then
36+
echo "::error::GITHUB_TOKEN is empty. Secrets may not be properly accessed."
37+
exit 1
38+
fi
39+
# Ensure URL is set
40+
if [ -z "$GL_TRIGGER_URL" ]; then
41+
echo "::error::GL_TRIGGER_URL secret is missing or unavailable!"
42+
exit 1
43+
fi
44+
45+
echo "Triggering GitLab pipeline for SHA: ${GITHUB_PR_SHA}"
46+
curl --fail --silent --show-error --request POST \
47+
--form token="${GL_TRIGGER_TOKEN}" \
48+
--form ref="${GL_TRIGGER_REF}" \
49+
--form "variables[GITHUB_PR_SHA]=${GITHUB_PR_SHA}" \
50+
--form "variables[GITHUB_PR_REF]=${GITHUB_PR_REF}" \
51+
--form "variables[GITHUB_REPO]=${GITHUB_REPO}" \
52+
"${GL_TRIGGER_URL}" > /dev/null
53+
echo "GitLab pipeline triggered."

.gitlab-ci.yml

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ variables:
33
DOCKER_TLS_CERTDIR: ""
44
DOCKER_BUILDKIT: 1
55
CI_DISPOSABLE_ENVIRONMENT: "true"
6-
BULLSEYE_IMAGE: debian:bullseye@sha256:4d6ab716de467aad58e91b1b720f0badd7478847ec7a18f66027d0f8a329a43c
76
IMAGE_BASE: blockstream/esplora-base
87
IMAGE: blockstream/esplora
98
DOCKERHUB_ESPLORA_URL: "https://hub.docker.com/v2/repositories/blockstream/esplora/tags/"
@@ -12,15 +11,8 @@ default:
1211
image: docker:27
1312
services:
1413
- name: docker:27-dind
15-
command: ["dockerd", "--host=tcp://0.0.0.0:2375"]
14+
command: ["dockerd", "--host=tcp://0.0.0.0:2375", "--mtu=1450"]
1615
alias: "docker"
17-
before_script:
18-
- docker info
19-
- docker buildx create
20-
--driver=docker-container
21-
--name=buildkit-builder
22-
--use
23-
--platform linux/amd64,linux/arm64
2416
tags:
2517
- cloud
2618
retry:

gitlab/build.yml

Lines changed: 102 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,132 @@
1-
build_base:
1+
.build_esplora_base:
22
stage: build
33
rules:
44
- if: $CI_COMMIT_BRANCH
55
changes:
66
paths:
77
- Dockerfile.deps
88
compare_to: master
9+
before_script:
10+
- docker buildx create
11+
--driver=docker-container
12+
--name=buildkit-builder
13+
--use
14+
--platform linux/${ARCH}
915
script:
16+
- docker pull ${IMAGE_BASE}:latest-${ARCH} || true
1017
- docker buildx build
11-
--platform linux/amd64,linux/arm64
1218
--push
19+
--platform linux/${ARCH}
1320
-f Dockerfile.deps
1421
--build-arg BUILDKIT_INLINE_CACHE=1
15-
--cache-from ${IMAGE_BASE}:latest
16-
-t ${IMAGE_BASE}:$CI_COMMIT_SHA
22+
--cache-from ${IMAGE_BASE}:latest-${ARCH}
23+
-t ${IMAGE_BASE}:latest-${ARCH} .
24+
build_esplora_base_amd64:
25+
extends:
26+
- .build_esplora_base
27+
variables:
28+
ARCH: amd64
29+
build_esplora_base_arm64:
30+
extends:
31+
- .build_esplora_base
32+
variables:
33+
ARCH: arm64
34+
tags:
35+
- cloud-arm
36+
build_and_push_esplora_base:
37+
stage: build
38+
rules:
39+
- if: $CI_COMMIT_BRANCH
40+
changes:
41+
paths:
42+
- Dockerfile.deps
43+
compare_to: master
44+
needs:
45+
- build_esplora_base_amd64
46+
- build_esplora_base_arm64
47+
script:
48+
- docker buildx imagetools create
1749
-t ${IMAGE_BASE}:latest
18-
.
50+
${IMAGE_BASE}:latest-amd64
51+
${IMAGE_BASE}:latest-arm64
1952

20-
test_docker_build_esplora:
53+
.build_esplora_test:
2154
stage: build
55+
only:
56+
- merge_requests
57+
before_script:
58+
- docker buildx create
59+
--driver=docker-container
60+
--name=buildkit-builder
61+
--use
62+
--platform linux/${ARCH}
2263
script:
64+
- docker pull ${IMAGE}:latest-${ARCH} || true
2365
- docker buildx build
24-
--platform linux/amd64,linux/arm64
66+
--platform linux/${ARCH}
2567
--build-arg BUILDKIT_INLINE_CACHE=1
26-
--cache-from ${IMAGE}:latest
68+
--cache-from ${IMAGE}:latest-${ARCH}
2769
-f Dockerfile
2870
-t ${IMAGE} .
71+
build_esplora_test_amd64:
72+
extends:
73+
- .build_esplora_test
74+
variables:
75+
ARCH: amd64
76+
build_esplora_test_arm64:
77+
tags:
78+
- cloud-arm
79+
extends:
80+
- .build_esplora_test
81+
variables:
82+
ARCH: arm64
2983

30-
build_esplora:
84+
.build_esplora_latest:
3185
stage: build
32-
when: manual
86+
only:
87+
- master
88+
except:
89+
- triggers
90+
before_script:
91+
- docker buildx create
92+
--driver=docker-container
93+
--name=buildkit-builder
94+
--use
95+
--platform linux/${ARCH}
3396
script:
97+
- docker pull ${IMAGE}:latest-${ARCH} || true
3498
- curl -s "${DOCKERHUB_ESPLORA_URL}" | grep -q "$CI_COMMIT_SHA" || (
3599
sed -i "s#esplora-base:latest#esplora-base:${BASE_TAG}#" Dockerfile
36100
&& docker buildx build
37-
--platform linux/amd64,linux/arm64
101+
--platform linux/${ARCH}
38102
--push
39103
--build-arg BUILDKIT_INLINE_CACHE=1
40104
--build-arg FOOT_HTML='<!-- '"$CI_COMMIT_SHA"' -->'
41-
--cache-from ${IMAGE}:latest
105+
--cache-from ${IMAGE}:latest-${ARCH}
106+
-t ${IMAGE}:latest-${ARCH} .)
107+
build_esplora_latest_amd64:
108+
extends:
109+
- .build_esplora_latest
110+
variables:
111+
ARCH: amd64
112+
build_esplora_latest_arm64:
113+
tags:
114+
- cloud-arm
115+
extends:
116+
- .build_esplora_latest
117+
variables:
118+
ARCH: arm64
119+
build_and_push_esplora_latest:
120+
stage: build
121+
only:
122+
- master
123+
except:
124+
- triggers
125+
needs:
126+
- build_esplora_latest_amd64
127+
- build_esplora_latest_arm64
128+
script:
129+
- docker buildx imagetools create
42130
-t ${IMAGE}:latest
43-
-t ${IMAGE}:$CI_COMMIT_SHA .)
44-
- if [ $CI_COMMIT_BRANCH == "master" ]; then docker pull ${IMAGE}:$CI_COMMIT_SHA; docker tag ${IMAGE}:$CI_COMMIT_SHA ${IMAGE}:latest; docker push ${IMAGE}:latest; fi
131+
${IMAGE}:latest-amd64
132+
${IMAGE}:latest-arm64

gitlab/test.yml

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
report_github_status:
2+
stage: build
3+
variables:
4+
GIT_STRATEGY: none
5+
ARCH: amd64
6+
rules:
7+
# Only run this job if:
8+
# 1. The pipeline was started by an API trigger (`CI_PIPELINE_SOURCE == "trigger"`)
9+
# 2. The required variables from GitHub Actions are present.
10+
- if: '$CI_PIPELINE_SOURCE == "trigger" && $GITHUB_PR_SHA && $GH_STATUS_TOKEN && $GITHUB_REPO && $GITHUB_PR_REF'
11+
before_script:
12+
# Make sure curl and git are available
13+
- apk add --no-cache curl git
14+
# Report "pending" status to GitHub as soon as the job starts
15+
- |
16+
echo "Reporting pending status to GitHub commit $GITHUB_PR_SHA"
17+
curl --fail --request POST \
18+
--url "https://api.github.com/repos/${GITHUB_REPO}/statuses/${GITHUB_PR_SHA}" \
19+
--header "Authorization: Bearer ${GH_STATUS_TOKEN}" \
20+
--header "Accept: application/vnd.github.v3+json" \
21+
--header "Content-Type: application/json" \
22+
--data @- <<EOF
23+
{
24+
"state": "pending",
25+
"target_url": "${CI_PIPELINE_URL}",
26+
"description": "GitLab CI pipeline is running...",
27+
"context": "ci/gitlab/pipeline-status"
28+
}
29+
EOF
30+
- |
31+
docker buildx create \
32+
--driver=docker-container \
33+
--name=buildkit-builder \
34+
--use \
35+
--platform linux/${ARCH}
36+
script:
37+
- git clone -b "$GITHUB_PR_REF" https://github.com/blockstream/esplora.git .
38+
- docker pull "${IMAGE_BASE}:latest-${ARCH}" || true
39+
- |
40+
docker buildx build \
41+
--push \
42+
--platform "linux/${ARCH}" \
43+
-f Dockerfile.deps \
44+
--build-arg BUILDKIT_INLINE_CACHE=1 \
45+
--cache-from "${IMAGE_BASE}:latest-${ARCH}" \
46+
-t "${IMAGE_BASE}:latest-${ARCH}" .
47+
after_script:
48+
# Report final status ("success" or "failure") to GitHub after the job finishes
49+
# This block runs even if the main 'script' fails
50+
- |
51+
FINAL_STATE="success" # Assume success
52+
DESCRIPTION="GitLab CI pipeline succeeded."
53+
# Check the GitLab CI job status variable
54+
if [ -z "${CI_JOB_STATUS}" ] || [ "${CI_JOB_STATUS}" != "success" ]; then
55+
echo "Job status was $CI_JOB_STATUS, reporting failure."
56+
FINAL_STATE="failure"
57+
DESCRIPTION="GitLab CI pipeline failed."
58+
fi
59+
60+
echo "Reporting $FINAL_STATE status to GitHub commit $GITHUB_PR_SHA"
61+
curl --fail --request POST \
62+
--url "https://api.github.com/repos/${GITHUB_REPO}/statuses/${GITHUB_PR_SHA}" \
63+
--header "Authorization: Bearer ${GH_STATUS_TOKEN}" \
64+
--header "Accept: application/vnd.github.v3+json" \
65+
--header "Content-Type: application/json" \
66+
--data @- << EOF
67+
{
68+
"state": "${FINAL_STATE}",
69+
"target_url": "${CI_PIPELINE_URL}",
70+
"description": "${DESCRIPTION}",
71+
"context": "ci/gitlab/pipeline-status" # Use the same context as 'pending'
72+
}
73+
EOF

terraform/data.tf

Lines changed: 0 additions & 14 deletions
This file was deleted.

terraform/main.tf

Lines changed: 0 additions & 37 deletions
This file was deleted.

0 commit comments

Comments
 (0)