Skip to content

Commit 8634a87

Browse files
committed
Move away from raw github domain to API
Signed-off-by: apostasie <[email protected]>
1 parent 848062e commit 8634a87

File tree

7 files changed

+37
-11
lines changed

7 files changed

+37
-11
lines changed

.github/workflows/ghcr-image-build-and-publish.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,3 +68,5 @@ jobs:
6868
push: ${{ github.event_name != 'pull_request' }}
6969
tags: ${{ steps.meta.outputs.tags }}
7070
labels: ${{ steps.meta.outputs.labels }}
71+
secrets: |
72+
github_token=${{ secrets.GITHUB_TOKEN }}

.github/workflows/job-test-dependencies.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ jobs:
3939
uses: crazy-max/ghaction-github-runtime@3cb05d89e1f492524af3d41a1c98c83bc3025124 # v3.1.0
4040

4141
- name: "Run: build dependencies for the integration test environment image"
42+
env:
43+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
4244
run: |
4345
# Cache is sharded per-architecture
4446
arch=${{ env.RUNNER_ARCH == 'ARM64' && 'arm64' || 'amd64' }}
@@ -49,6 +51,7 @@ jobs:
4951
args=(--build-arg CONTAINERD_VERSION=${{ inputs.containerd-version }})
5052
fi
5153
docker buildx build \
54+
--secret id=github_token,env=GITHUB_TOKEN \
5255
--cache-to type=gha,compression=zstd,mode=max,scope=test-integration-dependencies-"$arch" \
5356
--cache-from type=gha,scope=test-integration-dependencies-"$arch" \
5457
--target build-dependencies "${args[@]}" .

.github/workflows/job-test-in-container.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,8 @@ jobs:
8686
canary::build::integration
8787
- if: ${{ ! inputs.canary }}
8888
name: "Init: prepare test image"
89+
env:
90+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
8991
run: |
9092
buildargs=()
9193
# If the runner is old, use old ubuntu inside the container as well
@@ -104,6 +106,7 @@ jobs:
104106
arch=${{ env.RUNNER_ARCH == 'ARM64' && 'arm64' || 'amd64' }}
105107
docker buildx create --name with-gha --use
106108
docker buildx build \
109+
--secret id=github_token,env=GITHUB_TOKEN \
107110
--output=type=docker \
108111
--cache-from type=gha,scope=test-integration-dependencies-"$arch" \
109112
-t "$target" --target "$target" \

.github/workflows/job-test-in-lima.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,8 @@ jobs:
7979
uses: crazy-max/ghaction-github-runtime@3cb05d89e1f492524af3d41a1c98c83bc3025124 # v3.1.0
8080

8181
- name: "Init: prepare integration tests"
82+
env:
83+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
8284
run: |
8385
set -eux
8486
@@ -88,6 +90,7 @@ jobs:
8890
[ "$TARGET" = "rootless" ] && TARGET=test-integration-rootless || TARGET=test-integration
8991
docker buildx create --name with-gha --use
9092
docker buildx build \
93+
--secret id=github_token,env=GITHUB_TOKEN \
9194
--output=type=docker \
9295
--cache-from type=gha,scope=test-integration-dependencies-amd64 \
9396
-t test-integration --target "${TARGET}" \

Dockerfile

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ ENV DEBIAN_FRONTEND=noninteractive
6161
RUN apt-get update -qq && apt-get install -qq --no-install-recommends \
6262
make \
6363
git \
64+
jq \
6465
curl \
6566
dpkg-dev
6667
ARG TARGETARCH
@@ -75,6 +76,7 @@ RUN xx-apt-get update -qq && xx-apt-get install -qq --no-install-recommends \
7576
pkg-config
7677
RUN git config --global advice.detachedHead false
7778
ADD hack/git-checkout-tag-with-hash.sh /usr/local/bin/
79+
ADD hack/scripts/lib.sh /usr/local/bin/http::helper
7880

7981
FROM build-base AS build-containerd
8082
ARG TARGETARCH
@@ -174,10 +176,11 @@ RUN cd /out/lib/systemd/system && \
174176
echo "" >> buildkit.service && \
175177
echo "# This file was converted from containerd.service, with \`sed -E '${sedcomm}'\`" >> buildkit.service
176178
ARG STARGZ_SNAPSHOTTER_VERSION
177-
RUN STARGZ_SNAPSHOTTER_VERSION=${STARGZ_SNAPSHOTTER_VERSION%%@*}; \
179+
RUN --mount=type=secret,id=github_token,env=GITHUB_TOKEN \
180+
STARGZ_SNAPSHOTTER_VERSION=${STARGZ_SNAPSHOTTER_VERSION%%@*}; \
178181
fname="stargz-snapshotter-${STARGZ_SNAPSHOTTER_VERSION}-${TARGETOS:-linux}-${TARGETARCH:-amd64}.tar.gz" && \
179182
curl -o "${fname}" -fsSL --proto '=https' --tlsv1.2 "https://github.com/containerd/stargz-snapshotter/releases/download/${STARGZ_SNAPSHOTTER_VERSION}/${fname}" && \
180-
curl -o "stargz-snapshotter.service" -fsSL --proto '=https' --tlsv1.2 "https://raw.githubusercontent.com/containerd/stargz-snapshotter/${STARGZ_SNAPSHOTTER_VERSION}/script/config/etc/systemd/system/stargz-snapshotter.service" && \
183+
http::helper github::file containerd/stargz-snapshotter script/config/etc/systemd/system/stargz-snapshotter.service "${STARGZ_SNAPSHOTTER_VERSION}" > "stargz-snapshotter.service" && \
181184
grep "${fname}" "/SHA256SUMS.d/stargz-snapshotter-${STARGZ_SNAPSHOTTER_VERSION}" | sha256sum -c - && \
182185
grep "stargz-snapshotter.service" "/SHA256SUMS.d/stargz-snapshotter-${STARGZ_SNAPSHOTTER_VERSION}" | sha256sum -c - && \
183186
tar xzf "${fname}" -C /out/bin && \
@@ -245,6 +248,10 @@ RUN ROOTLESSKIT_VERSION=${ROOTLESSKIT_VERSION%%@*}; \
245248
ARG GOMODJAIL_VERSION
246249
COPY --from=build-gomodjail /out/${TARGETARCH:-amd64}/* /out/bin/
247250
RUN echo "- gomodjail: ${GOMODJAIL_VERSION}" >> /out/share/doc/nerdctl-full/README.md
251+
ARG CONTAINERIZED_SYSTEMD_VERSION
252+
RUN --mount=type=secret,id=github_token,env=GITHUB_TOKEN \
253+
http::helper github::file AkihiroSuda/containerized-systemd docker-entrypoint.sh "${CONTAINERIZED_SYSTEMD_VERSION}" > /docker-entrypoint.sh && \
254+
chmod +x /docker-entrypoint.sh
248255

249256
RUN echo "" >> /out/share/doc/nerdctl-full/README.md && \
250257
echo "## License" >> /out/share/doc/nerdctl-full/README.md && \
@@ -281,9 +288,7 @@ RUN apt-get update -qq && apt-get install -qq -y --no-install-recommends \
281288
iproute2 iptables \
282289
dbus dbus-user-session systemd systemd-sysv \
283290
fuse3
284-
ARG CONTAINERIZED_SYSTEMD_VERSION
285-
RUN curl -o /docker-entrypoint.sh -fsSL --proto '=https' --tlsv1.2 https://raw.githubusercontent.com/AkihiroSuda/containerized-systemd/${CONTAINERIZED_SYSTEMD_VERSION}/docker-entrypoint.sh && \
286-
chmod +x /docker-entrypoint.sh
291+
COPY --from=build-full /docker-entrypoint.sh /docker-entrypoint.sh
287292
COPY --from=out-full / /usr/local/
288293
RUN perl -pi -e 's/multi-user.target/docker-entrypoint.target/g' /usr/local/lib/systemd/system/*.service && \
289294
systemctl enable containerd buildkit stargz-snapshotter && \

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ TAR_OWNER0_FLAGS=--owner=0 --group=0
253253
TAR_FLATTEN_FLAGS=--transform 's/.*\///g'
254254

255255
define make_artifact_full_linux
256-
$(DOCKER) build --output type=tar,dest=$(CURDIR)/_output/nerdctl-full-$(VERSION_TRIMMED)-linux-$(1).tar --target out-full --platform $(1) --build-arg GO_VERSION -f $(MAKEFILE_DIR)/Dockerfile $(MAKEFILE_DIR)
256+
$(DOCKER) build --secret id=github_token,env=GITHUB_TOKEN --output type=tar,dest=$(CURDIR)/_output/nerdctl-full-$(VERSION_TRIMMED)-linux-$(1).tar --target out-full --platform $(1) --build-arg GO_VERSION -f $(MAKEFILE_DIR)/Dockerfile $(MAKEFILE_DIR)
257257
gzip -9 $(CURDIR)/_output/nerdctl-full-$(VERSION_TRIMMED)-linux-$(1).tar
258258
endef
259259

hack/scripts/lib.sh

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -226,9 +226,10 @@ github::settoken(){
226226
}
227227

228228
github::request(){
229-
local endpoint="$1"
229+
local accept="$1"
230+
local endpoint="$2"
230231
local args=(
231-
"Accept: application/vnd.github+json"
232+
"Accept: $accept"
232233
"X-GitHub-Api-Version: 2022-11-28"
233234
)
234235

@@ -237,21 +238,30 @@ github::request(){
237238
http::get /dev/stdout https://api.github.com/"$endpoint" "${args[@]}"
238239
}
239240

241+
github::file(){
242+
local repo="$1"
243+
local path="$2"
244+
local ref="${3:-main}"
245+
github::request "application/vnd.github.v3.raw" "repos/$repo/contents/$path?ref=$ref"
246+
}
247+
240248
github::tags::latest(){
241249
local repo="$1"
242-
github::request "repos/$repo/tags" | jq -rc .[0].name
250+
github::request "application/vnd.github+json" "repos/$repo/tags" | jq -rc .[0].name
243251
}
244252

245253
github::releases(){
246254
local repo="$1"
247-
github::request "repos/$repo/releases" |
255+
github::request "application/vnd.github+json" "repos/$repo/releases" |
248256
jq -rc .[]
249257
}
250258

251259
github::releases::latest(){
252260
local repo="$1"
253-
github::request "repos/$repo/releases/latest" | jq -rc .
261+
github::request "application/vnd.github+json" "repos/$repo/releases/latest" | jq -rc .
254262
}
255263

256264
log::init
257265
host::require jq tar curl shasum
266+
267+
[[ "${1:-}" != "github"* ]] || "$@"

0 commit comments

Comments
 (0)