Skip to content

Commit c2ddc9c

Browse files
authored
Add Docker Image CI workflow (#44)
* Add Dockerfile (#43) Signed-off-by: Wilson Wu <[email protected]> * Add workflow for Docker image Signed-off-by: Wilson Wu <[email protected]>
1 parent 37c49fb commit c2ddc9c

File tree

3 files changed

+127
-4
lines changed

3 files changed

+127
-4
lines changed

.github/workflows/main.yml

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,25 @@ on:
99
pull_request:
1010
branches:
1111
- "main"
12+
1213
env:
1314
GOLANG_VERSION: '1.21'
1415

1516
jobs:
17+
init-variable:
18+
runs-on: ubuntu-latest
19+
outputs:
20+
container_tag: ${{ steps.init_variable.outputs.container_tag }}
21+
steps:
22+
- name: checkout
23+
uses: actions/checkout@v3
24+
with:
25+
fetch-depth: 0
26+
- name: output environment variable
27+
id: init_variable
28+
run: |
29+
echo container_tag=$(git describe --tags --abbrev=8) >> $GITHUB_OUTPUT
30+
1631
unit-tests:
1732
name: Unit tests running
1833
runs-on: ubuntu-latest
@@ -29,7 +44,6 @@ jobs:
2944
run: |
3045
go test -v ./...
3146
32-
3347
linting:
3448
name: Go code linting
3549
runs-on: ubuntu-latest
@@ -61,4 +75,4 @@ jobs:
6175

6276
- name: Build creation
6377
run: |
64-
go build -v
78+
go build -v

.github/workflows/release.yml

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
# This workflow will build a golang project
2+
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-go
3+
4+
name: Contour plugin CI
5+
on:
6+
push:
7+
tags:
8+
- '*'
9+
10+
env:
11+
GOLANG_VERSION: '1.21'
12+
13+
jobs:
14+
init-variable:
15+
runs-on: ubuntu-latest
16+
outputs:
17+
container_tag: ${{ steps.init_variable.outputs.container_tag }}
18+
steps:
19+
- name: checkout
20+
uses: actions/checkout@v3
21+
with:
22+
fetch-depth: 0
23+
- name: output environment variable
24+
id: init_variable
25+
run: |
26+
echo container_tag=$(git describe --tags --abbrev=8) >> $GITHUB_OUTPUT
27+
28+
unit-tests:
29+
name: Unit tests running
30+
runs-on: ubuntu-latest
31+
steps:
32+
- name: Set up Go
33+
uses: actions/setup-go@v3
34+
with:
35+
go-version: ${{ env.GOLANG_VERSION }}
36+
37+
- name: Checkout code
38+
uses: actions/[email protected]
39+
40+
- name: Unit tests running
41+
run: |
42+
go test -v ./...
43+
44+
linting:
45+
name: Go code linting
46+
runs-on: ubuntu-latest
47+
steps:
48+
- name: Set up Go
49+
uses: actions/setup-go@v3
50+
with:
51+
go-version: ${{ env.GOLANG_VERSION }}
52+
53+
- name: Checkout code
54+
uses: actions/[email protected]
55+
56+
- name: Run golangci-lint
57+
uses: golangci/golangci-lint-action@v3
58+
with:
59+
args: --verbose --timeout 6m
60+
61+
build:
62+
name: Build creation
63+
runs-on: ubuntu-latest
64+
steps:
65+
- name: Set up Go
66+
uses: actions/setup-go@v3
67+
with:
68+
go-version: ${{ env.GOLANG_VERSION }}
69+
70+
- name: Checkout code
71+
uses: actions/[email protected]
72+
73+
- name: Build creation
74+
run: |
75+
go build -v
76+
77+
image:
78+
needs: [init-variable]
79+
name: Build Docker image
80+
runs-on: ${{ matrix.os }}
81+
strategy:
82+
matrix:
83+
os: [ubuntu-latest]
84+
steps:
85+
- name: Checkout
86+
uses: actions/checkout@v3
87+
with:
88+
fetch-depth: 0
89+
- name: "Login to Docker Registry"
90+
uses: docker/login-action@v3
91+
with:
92+
registry: release.daocloud.io
93+
username: ${{ secrets.DAOCLOUD_REGISTRY_USERNAME }}
94+
password: ${{ secrets.DAOCLOUD_REGISTRY_PWD }}
95+
- name: Use setup-buildx-action
96+
uses: docker/setup-buildx-action@v2
97+
- name: Build Docker image
98+
uses: docker/[email protected]
99+
with:
100+
github-token: ${{ secrets.GITHUB_TOKEN }}
101+
push: true
102+
provenance: false
103+
platforms: linux/amd64,linux/arm64
104+
tags: |
105+
release.daocloud.io/skoala/rollouts-plugin-trafficrouter-contour:${{ needs.init-variable.outputs.container_tag }}
106+
cache-from: type=gha
107+
cache-to: type=gha,mode=max

Dockerfile

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@ WORKDIR /app
77

88
COPY . .
99

10-
RUN CGO_ENABLED=0 GOOS=linux GOARCH=$(TARGETARCH) go build -ldflags "-s -w" -o rollouts-plugin-trafficrouter-contour-linux-$(TARGETARCH) .
10+
RUN CGO_ENABLED=0 GOOS=linux GOARCH=${TARGETARCH} go build -ldflags "-s -w" -o rollouts-plugin-trafficrouter-contour-linux-${TARGETARCH} .
1111

1212
FROM alpine:3.19.0
1313

14-
COPY --from=builder /app/rollouts-plugin-trafficrouter-contour-linux-$(TARGETARCH) /bin/
14+
ARG TARGETARCH
15+
16+
COPY --from=builder /app/rollouts-plugin-trafficrouter-contour-linux-${TARGETARCH} /bin/

0 commit comments

Comments
 (0)