Skip to content

Commit c500bc4

Browse files
authored
Adding support for GHCR custom domains for using Github Enterprise (#339)
1 parent 1bb710d commit c500bc4

File tree

16 files changed

+161
-96
lines changed

16 files changed

+161
-96
lines changed

.dockerignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
bin
2+
coverage.out
3+
*.md
4+
.git

.github/workflows/build-test.yaml

Lines changed: 57 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@ name: Test & Build
22
on:
33
pull_request:
44
branches:
5-
- 'main'
6-
paths:
7-
- "!README.md"
5+
- "main"
86

97
concurrency:
108
group: ${{ github.workflow }}-${{ github.ref }}
@@ -13,9 +11,9 @@ concurrency:
1311
jobs:
1412
lint:
1513
permissions:
16-
contents: read # for actions/checkout to fetch code
17-
pull-requests: read # for golangci/golangci-lint-action to fetch pull requests
18-
checks: write # for golangci/golangci-lint-action to annotate Pull Requests
14+
contents: read # for actions/checkout to fetch code
15+
pull-requests: read # for golangci/golangci-lint-action to fetch pull requests
16+
checks: write # for golangci/golangci-lint-action to annotate Pull Requests
1917
name: Lint Go code
2018
runs-on: ubuntu-latest
2119
steps:
@@ -26,7 +24,7 @@ jobs:
2624
with:
2725
go-version-file: go.mod
2826
- name: Run golangci-lint
29-
uses: golangci/golangci-lint-action@2226d7cb06a077cd73e56eedd38eecad18e5d837 # v6.5.0
27+
uses: golangci/golangci-lint-action@2226d7cb06a077cd73e56eedd38eecad18e5d837 # v6.5.0
3028
with:
3129
version: v1.54
3230
args: --timeout 10m --exclude SA5011 --verbose --issues-exit-code=0
@@ -39,40 +37,41 @@ jobs:
3937
- id: govulncheck
4038
uses: golang/govulncheck-action@v1
4139
with:
42-
go-version-file: go.mod
43-
go-package: ./...
40+
go-version-file: go.mod
41+
go-package: ./...
4442

4543
test:
4644
name: Run unit tests for Go packages
4745
runs-on: ubuntu-latest
4846
steps:
49-
- name: Checkout code
50-
uses: actions/checkout@v4 # v3.5.3
51-
- name: Setup Go
52-
uses: actions/setup-go@v5
53-
with:
54-
go-version-file: go.mod
47+
- name: Checkout code
48+
uses: actions/checkout@v4 # v3.5.3
49+
- name: Setup Go
50+
uses: actions/setup-go@v5
51+
with:
52+
go-version-file: go.mod
5553

56-
- name: Download and required packages
57-
run: |
58-
make deps
54+
- name: Download and required packages
55+
run: |
56+
make deps
5957
60-
- name: Run all unit tests
61-
run: make test
58+
- name: Run all unit tests
59+
run: make test
6260

63-
- name: check test coverage
64-
uses: vladopajic/go-test-coverage@v2
65-
with:
66-
config: ./.testcoverage.yml
61+
- name: check test coverage
62+
uses: vladopajic/go-test-coverage@v2
63+
with:
64+
config: ./.testcoverage.yml
6765

68-
- name: Trigger Coverage update
69-
uses: ./coverage-badge.yaml
66+
- name: Trigger Coverage update
67+
uses: ./.github/workflows/coverage-badge.yaml
68+
continue-on-error: true
7069

71-
- name: Generate code coverage artifacts
72-
uses: actions/upload-artifact@v4
73-
with:
74-
name: code-coverage
75-
path: coverage.out
70+
- name: Generate code coverage artifacts
71+
uses: actions/upload-artifact@v4
72+
with:
73+
name: code-coverage
74+
path: coverage.out
7675

7776
build:
7877
needs:
@@ -87,33 +86,33 @@ jobs:
8786
- linux/arm64
8887
name: Build Images
8988
steps:
90-
- name: Checkout code
91-
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
92-
- name: Set up QEMU
93-
uses: docker/setup-qemu-action@v3
89+
- name: Checkout code
90+
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
91+
- name: Set up QEMU
92+
uses: docker/setup-qemu-action@v3
9493

95-
- name: Set up Docker Buildx
96-
uses: docker/setup-buildx-action@v3
97-
with:
98-
platforms: ${{ matrix.platform }}
94+
- name: Set up Docker Buildx
95+
uses: docker/setup-buildx-action@v3
96+
with:
97+
platforms: ${{ matrix.platform }}
9998

100-
- name: Build Images
101-
uses: docker/build-push-action@v6
102-
with:
103-
context: .
104-
platforms: ${{ matrix.platform }}
105-
load: true
106-
push: false
107-
tags: quay.io/jetstack/version-checker:${{github.sha}}
108-
cache-from: type=gha
109-
cache-to: type=gha,mode=max
99+
- name: Build Images
100+
uses: docker/build-push-action@v6
101+
with:
102+
context: .
103+
platforms: ${{ matrix.platform }}
104+
load: true
105+
push: false
106+
tags: quay.io/jetstack/version-checker:${{github.sha}}
107+
cache-from: type=gha
108+
cache-to: type=gha,mode=max
110109

111-
- name: Run Trivy vulnerability scanner
112-
uses: aquasecurity/[email protected]
113-
with:
114-
image-ref: 'quay.io/jetstack/version-checker:${{github.sha}}'
115-
format: 'table'
116-
exit-code: '1'
117-
ignore-unfixed: true
118-
vuln-type: 'os,library'
119-
severity: 'CRITICAL,HIGH'
110+
- name: Run Trivy vulnerability scanner
111+
uses: aquasecurity/[email protected]
112+
with:
113+
image-ref: "quay.io/jetstack/version-checker:${{github.sha}}"
114+
format: "table"
115+
exit-code: "1"
116+
ignore-unfixed: true
117+
vuln-type: "os,library"
118+
severity: "CRITICAL,HIGH"

.github/workflows/release.yaml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ concurrency:
1212
cancel-in-progress: true
1313

1414
jobs:
15-
prepair-release:
15+
prepare-release:
1616
# Don't push back to a tag!
1717
if: ${{ !startsWith(github.ref, 'refs/tags/') }}
1818
name: Prepair release
@@ -108,7 +108,6 @@ jobs:
108108
get_diff: false
109109
allow_no_diff: false
110110

111-
112111
helm-release:
113112
runs-on: ubuntu-latest
114113
steps:
@@ -158,7 +157,7 @@ jobs:
158157
- name: Set up Docker Buildx
159158
uses: docker/setup-buildx-action@v3
160159
with:
161-
platforms: ${{ matrix.platform }}
160+
platforms: linux/amd64,linux/arm64
162161

163162
- name: Login to Docker Hub
164163
uses: docker/login-action@v3

cmd/app/options.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ const (
3737
envGCRAccessToken = "GCR_TOKEN"
3838

3939
envGHCRAccessToken = "GHCR_TOKEN"
40+
envGHCRHostname = "GHCR_HOSTNAME"
4041

4142
envQuayToken = "QUAY_TOKEN"
4243

@@ -207,6 +208,12 @@ func (o *Options) addAuthFlags(fs *pflag.FlagSet) {
207208
"Personal Access token for read access to GHCR releases (%s_%s).",
208209
envPrefix, envGHCRAccessToken,
209210
))
211+
fs.StringVar(&o.Client.GHCR.Hostname,
212+
"gchr-hostname", "",
213+
fmt.Sprintf(
214+
"Override hostname for Github Enterprise instances (%s_%s).",
215+
envPrefix, envGHCRHostname,
216+
))
210217
///
211218

212219
/// Quay
@@ -291,6 +298,7 @@ func (o *Options) complete() {
291298
{envGCRAccessToken, &o.Client.GCR.Token},
292299

293300
{envGHCRAccessToken, &o.Client.GHCR.Token},
301+
{envGHCRHostname, &o.Client.GHCR.Hostname},
294302

295303
{envQuayToken, &o.Client.Quay.Token},
296304
} {

deploy/charts/version-checker/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ A Helm chart for version-checker
3434
| extraVolumeMounts | list | `[]` | Allow for extra Volume Mounts to version-checkers container |
3535
| extraVolumes | list | `[]` | Allow for extra Volumes to be associated to the pod |
3636
| gcr.token | string | `nil` | Access token for read access to private GCR registries |
37+
| ghcr.hostname | string | `nil` | Hostname for Github Enterprise to override the default ghcr domains. |
3738
| ghcr.token | string | `nil` | Personal Access token for read access to GHCR releases |
3839
| image.imagePullSecret | string | `nil` | Pull secrects - name of existing secret |
3940
| image.pullPolicy | string | `"IfNotPresent"` | Set the Image Pull Policy |

deploy/charts/version-checker/templates/secret.yaml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
{{- if or .Values.acr.refreshToken .Values.acr.username .Values.acr.password .Values.docker.token .Values.ecr.accessKeyID .Values.ecr.secretAccessKey .Values.ecr.sessionToken .Values.docker.username .Values.docker.password .Values.gcr.token .Values.ghcr.token .Values.quay.token (not (eq (len .Values.selfhosted) 0)) }}
1+
{{- if or .Values.acr.refreshToken .Values.acr.username .Values.acr.password .Values.docker.token .Values.ecr.accessKeyID .Values.ecr.secretAccessKey .Values.ecr.sessionToken .Values.docker.username .Values.docker.password .Values.gcr.token .Values.ghcr.token .Values.ghcr.hostname .Values.quay.token (not (eq (len .Values.selfhosted) 0)) }}
2+
---
23
apiVersion: v1
34
data:
45
# ACR
@@ -43,6 +44,9 @@ data:
4344
{{- if .Values.ghcr.token }}
4445
ghcr.token: {{ .Values.ghcr.token | b64enc }}
4546
{{- end}}
47+
{{- if .Values.ghcr.hostname }}
48+
ghcr.hostname: {{ .Values.ghcr.hostname | b64enc }}
49+
{{- end}}
4650

4751
# Quay
4852
{{- if .Values.quay.token }}

deploy/charts/version-checker/values.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,8 @@ gcr:
8888
ghcr:
8989
# -- (string) Personal Access token for read access to GHCR releases
9090
token:
91+
# -- (string) Hostname for Github Enterprise to override the default ghcr domains.
92+
hostname:
9193

9294
# Quay.io Registry Credentials Configuration
9395
quay:

go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@ require (
3232
github.com/aws/aws-sdk-go-v2/credentials v1.17.59
3333
github.com/aws/aws-sdk-go-v2/service/ecr v1.41.0
3434
github.com/gofri/go-github-ratelimit v1.1.0
35-
github.com/google/go-cmp v0.6.0
35+
github.com/google/go-cmp v0.7.0
3636
github.com/google/go-containerregistry v0.20.3
37-
github.com/google/go-github/v62 v62.0.0
37+
github.com/google/go-github/v70 v70.0.0
3838
github.com/jarcoal/httpmock v1.3.1
3939
github.com/stretchr/testify v1.10.0
4040
)

go.sum

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -101,12 +101,12 @@ github.com/google/gnostic-models v0.6.9 h1:MU/8wDLif2qCXZmzncUQ/BOfxWfthHi63Kqpo
101101
github.com/google/gnostic-models v0.6.9/go.mod h1:CiWsm0s6BSQd1hRn8/QmxqB6BesYcbSZxsz9b0KuDBw=
102102
github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
103103
github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
104-
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
105-
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
104+
github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8=
105+
github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU=
106106
github.com/google/go-containerregistry v0.20.3 h1:oNx7IdTI936V8CQRveCjaxOiegWwvM7kqkbXTpyiovI=
107107
github.com/google/go-containerregistry v0.20.3/go.mod h1:w00pIgBRDVUDFM6bq+Qx8lwNWK+cxgCuX1vd3PIBDNI=
108-
github.com/google/go-github/v62 v62.0.0 h1:/6mGCaRywZz9MuHyw9gD1CwsbmBX8GWsbFkwMmHdhl4=
109-
github.com/google/go-github/v62 v62.0.0/go.mod h1:EMxeUqGJq2xRu9DYBMwel/mr7kZrzUOfQmmpYrZn2a4=
108+
github.com/google/go-github/v70 v70.0.0 h1:/tqCp5KPrcvqCc7vIvYyFYTiCGrYvaWoYMGHSQbo55o=
109+
github.com/google/go-github/v70 v70.0.0/go.mod h1:xBUZgo8MI3lUL/hwxl3hlceJW1U8MVnXP3zUyI+rhQY=
110110
github.com/google/go-querystring v1.1.0 h1:AnCroh3fv4ZBgVIf1Iwtovgjaw/GiKJo8M8yD/fhyJ8=
111111
github.com/google/go-querystring v1.1.0/go.mod h1:Kcdr2DB4koayq7X8pmAG4sNG59So17icRSOU623lUBU=
112112
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=

pkg/client/docker/docker.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ func (c *Client) doRequest(ctx context.Context, url string) (*TagResponse, error
138138

139139
resp, err := c.Do(req)
140140
if err != nil {
141-
return nil, fmt.Errorf("failed to get docker image: %s", err)
141+
return nil, fmt.Errorf("failed to get %q image: %s", c.Name(), err)
142142
}
143143
defer resp.Body.Close()
144144

0 commit comments

Comments
 (0)