Skip to content

Commit ea9fae5

Browse files
committed
feat: Add GitHub token handling for Docker build and CodeQL installation
1 parent ec96231 commit ea9fae5

File tree

2 files changed

+24
-8
lines changed

2 files changed

+24
-8
lines changed

.github/workflows/build.yml

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -95,12 +95,16 @@ jobs:
9595
# latest / main
9696
type=raw,value=latest,enable=${{ github.ref == format('refs/heads/{0}', 'main') }}
9797
98+
- name: Login to GitHub Container Registry
99+
uses: docker/login-action@v3
100+
with:
101+
registry: ${{ env.REGISTRY }}
102+
username: ${{ github.actor }}
103+
password: ${{ secrets.GITHUB_TOKEN }}
104+
98105
- name: Build Container ${{ github.repository }}
99106
uses: docker/build-push-action@263435318d21b8e681c14492fe198d362a7d2c83 # v6.18.0
100107
id: build
101-
env:
102-
# Secrets for GH CLI
103-
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}
104108
with:
105109
file: "./Dockerfile"
106110
context: .
@@ -109,9 +113,9 @@ jobs:
109113
labels: ${{ steps.meta.outputs.labels }}
110114
# SBOM Settings
111115
sbom: true
112-
# Secrets for GH CLI
113-
secret-envs: |
114-
GH_TOKEN=GITHUB_TOKEN
116+
# Pass GitHub token as a build secret
117+
secrets: |
118+
"github_token=${{ secrets.GITHUB_TOKEN }}"
115119
116120
# Upload Software Bill of Materials (SBOM) to GitHub
117121
- name: Upload SBOM

Dockerfile

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,20 @@ RUN apt-get update && \
3131
apt-get clean && \
3232
rm -rf /var/lib/apt/lists/*
3333

34+
# Define GitHub token as a build ARG
35+
ARG github_token
36+
3437
# Install the CodeQL extension for GitHub CLI
35-
RUN gh extensions install github/gh-codeql && \
36-
gh codeql install-stub
38+
RUN --mount=type=secret,id=github_token \
39+
if [ -f "/run/secrets/github_token" ]; then \
40+
export GITHUB_TOKEN=$(cat /run/secrets/github_token); \
41+
gh auth setup-git; \
42+
gh extensions install github/gh-codeql && \
43+
gh codeql install-stub; \
44+
else \
45+
echo "No GitHub token provided, using public access"; \
46+
gh extensions install github/gh-codeql && \
47+
gh codeql install-stub; \
48+
fi
3749

3850
ENTRYPOINT [ "codeql-extractor-action" ]

0 commit comments

Comments
 (0)