Skip to content

Commit f0b8a40

Browse files
committed
add support for building artifacts with custom GOPROXY
Signed-off-by: Tariq Ibrahim <[email protected]>
1 parent e03ac36 commit f0b8a40

File tree

6 files changed

+65
-10
lines changed

6 files changed

+65
-10
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
name: 'JFrog Artifactory GOPROXY'
2+
description: 'Composite GitHub Action which signs into the JFrog Artifactory and retrieves the URL of the Go Module Proxy'
3+
inputs:
4+
artifactory-endpoint:
5+
description: "The endpoint for OIDC access to Artifactory instance"
6+
required: true
7+
outputs:
8+
goproxy:
9+
description: "The URL to the Go module proxy. Set this value to your GOPROXY environment variable"
10+
value: ${{ steps.get-goproxy.outputs.goproxy-url }}
11+
runs:
12+
using: "composite"
13+
steps:
14+
- name: Setup JFrog CLI
15+
id: jfrog
16+
uses: jfrog/setup-jfrog-cli@v4
17+
env:
18+
JF_URL: https://${{ inputs.artifactory-endpoint }}/
19+
with:
20+
oidc-provider-name: nvgithub
21+
oidc-audience: ${{ inputs.artifactory-endpoint }}
22+
- name: Retrieve the Artifactory GOPROXY
23+
id: get-goproxy
24+
env:
25+
OIDC_USER: ${{ steps.jfrog.outputs.oidc-user }}
26+
OIDC_TOKEN: ${{ steps.jfrog.outputs.oidc-token }}
27+
OIDC_ARTIFACTORY_ENDPOINT: ${{ inputs.artifactory-endpoint }}
28+
run: |
29+
OIDC_USER_ENCODED=$(python3 -c 'import urllib.parse, os; print(urllib.parse.quote_plus(os.environ["OIDC_USER"]))')
30+
export GOPROXY="https://${OIDC_USER_ENCODED}:${OIDC_TOKEN}@${OIDC_ARTIFACTORY_ENDPOINT}/artifactory/api/go/edge-go-remote-virtual"
31+
echo "goproxy-url=$(echo $GOPROXY)" >> $GITHUB_OUTPUT
32+
shell: bash

.github/workflows/ci.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ jobs:
3535
run: echo "version=$(echo $GITHUB_SHA | cut -c1-8)" >> "$GITHUB_OUTPUT"
3636

3737
golang:
38+
secrets: inherit
3839
uses: ./.github/workflows/golang.yaml
3940

4041
image:

.github/workflows/golang.yaml

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,6 @@ name: Golang
1616

1717
on:
1818
workflow_call: {}
19-
pull_request:
20-
types:
21-
- opened
22-
- synchronize
23-
branches:
24-
- main
25-
- release-*
2619

2720
jobs:
2821
check:
@@ -84,7 +77,10 @@ jobs:
8477

8578
build:
8679
name: Build
87-
runs-on: ubuntu-latest
80+
runs-on: linux-amd64-cpu4
81+
permissions:
82+
contents: read
83+
id-token: write
8884
steps:
8985
- name: Checkout code
9086
uses: actions/checkout@v5
@@ -100,4 +96,13 @@ jobs:
10096
with:
10197
go-version: ${{ env.GOLANG_VERSION }}
10298

103-
- run: make build
99+
- name: JFrog Artifactory
100+
id: jfrog-artifactory
101+
uses: ./.github/actions/jfrog-artifactory-action
102+
with:
103+
artifactory-endpoint: ${{ secrets.OIDC_ARTIFACTORY_ENDPOINT }}
104+
105+
- env:
106+
GOPROXY: ${{ steps.jfrog-artifactory.outputs.goproxy-url }}
107+
run: |
108+
make build

.github/workflows/image.yaml

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,11 @@ jobs:
7676
path: ${{ github.workspace }}/dist/*
7777

7878
image:
79-
runs-on: ubuntu-latest
79+
runs-on: linux-amd64-cpu4
80+
permissions:
81+
contents: read
82+
id-token: write
83+
packages: write
8084
strategy:
8185
matrix:
8286
target:
@@ -109,12 +113,19 @@ jobs:
109113
username: ${{ github.actor }}
110114
password: ${{ secrets.GITHUB_TOKEN }}
111115

116+
- name: JFrog Artifactory
117+
id: jfrog-artifactory
118+
uses: ./.github/actions/jfrog-artifactory-action
119+
with:
120+
artifactory-endpoint: ${{ secrets.OIDC_ARTIFACTORY_ENDPOINT }}
121+
112122
- name: Build image
113123
env:
114124
IMAGE_NAME: ghcr.io/nvidia/container-toolkit
115125
VERSION: ${{ inputs.version }}
116126
PUSH_ON_BUILD: "true"
117127
BUILD_MULTI_ARCH_IMAGES: ${{ inputs.build_multi_arch_images }}
128+
GOPROXY: ${{ steps.jfrog-artifactory.outputs.goproxy-url }}
118129
run: |
119130
echo "${VERSION}"
120131
make -f deployments/container/Makefile build-${{ matrix.target }}

deployments/container/Dockerfile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ RUN set -eux; \
4242
ENV GOPATH=/go
4343
ENV PATH=$GOPATH/bin:/usr/local/go/bin:$PATH
4444

45+
ARG GOPROXY="https://proxy.golang.org,direct"
46+
ENV GOPROXY=$GOPROXY
47+
4548
WORKDIR /build
4649
COPY . .
4750

deployments/container/Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ DIST_DIR ?= $(CURDIR)/dist
2727
##### Global variables #####
2828
include $(CURDIR)/versions.mk
2929

30+
GOPROXY ?= https://proxy.golang.org,direct
31+
3032
IMAGE_VERSION := $(VERSION)
3133

3234
IMAGE_TAG ?= $(VERSION)
@@ -88,6 +90,7 @@ $(IMAGE_TARGETS): image-%: $(ARTIFACTS_ROOT)
8890
--build-arg GIT_COMMIT_SHORT="$(GIT_COMMIT_SHORT)" \
8991
--build-arg GIT_BRANCH="$(GIT_BRANCH)" \
9092
--build-arg SOURCE_DATE_EPOCH="$(SOURCE_DATE_EPOCH)" \
93+
--build-arg GOPROXY="$(GOPROXY)" \
9194
-f $(DOCKERFILE) \
9295
$(CURDIR)
9396

0 commit comments

Comments
 (0)