Skip to content

Commit 35d21c6

Browse files
Merge pull request #2 from stakater/add-pipeline
Add pipeline
2 parents a602760 + cfce646 commit 35d21c6

File tree

10 files changed

+434
-45
lines changed

10 files changed

+434
-45
lines changed

.github/workflows/pull_request.yml

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
name: Pull Request
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- master
7+
8+
env:
9+
DOCKER_FILE_PATH: Dockerfile
10+
GOLANG_VERSION: 1.14
11+
KUBERNETES_VERSION: "1.18.0"
12+
KIND_VERSION: "0.7.0"
13+
14+
jobs:
15+
build:
16+
runs-on: ubuntu-latest
17+
name: Build
18+
if: "! contains(toJSON(github.event.commits.*.message), '[skip-ci]')"
19+
steps:
20+
- name: Check out code
21+
uses: actions/checkout@v2
22+
23+
- name: Set up Go
24+
id: go
25+
uses: actions/setup-go@v2
26+
with:
27+
go-version: ${{ env.GOLANG_VERSION }}
28+
29+
- name: Lint
30+
run: |
31+
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.26.0
32+
golangci-lint run --timeout=10m ./...
33+
34+
- name: Install kubectl
35+
run: |
36+
curl -LO "https://storage.googleapis.com/kubernetes-release/release/v${KUBERNETES_VERSION}/bin/linux/amd64/kubectl"
37+
sudo install ./kubectl /usr/local/bin/ && rm kubectl
38+
kubectl version --short --client
39+
kubectl version --short --client | grep -q ${KUBERNETES_VERSION}
40+
41+
- name: Install Kind
42+
run: |
43+
curl -L -o kind https://github.com/kubernetes-sigs/kind/releases/download/v${KIND_VERSION}/kind-linux-amd64
44+
sudo install ./kind /usr/local/bin && rm kind
45+
kind version
46+
kind version | grep -q ${KIND_VERSION}
47+
48+
- name: Create Kind Cluster
49+
run: |
50+
kind create cluster
51+
52+
- name: Set up Cluster
53+
run: |
54+
kubectl cluster-info
55+
kubectl create namespace test
56+
57+
- name: Test
58+
run: make test OPERATOR_NAMESPACE=test USE_EXISTING_CLUSTER=true
59+
60+
- name: Generate Tag
61+
id: generate_tag
62+
run: |
63+
sha=${{ github.event.pull_request.head.sha }}
64+
tag="SNAPSHOT-PR-${{ github.event.pull_request.number }}-${sha:0:8}"
65+
echo "##[set-output name=GIT_TAG;]$(echo ${tag})"
66+
67+
- name: Build and push Docker images
68+
uses: docker/build-push-action@v1
69+
with:
70+
username: ${{ secrets.STAKATER_DOCKERHUB_USERNAME }}
71+
password: ${{ secrets.STAKATER_DOCKERHUB_PASSWORD }}
72+
repository: ${{ env.GITHUB_REPOSITORY }}
73+
add_git_labels: true
74+
dockerfile: ${{ env.DOCKER_FILE_PATH }}
75+
tags: ${{ steps.generate_tag.outputs.GIT_TAG }}
76+
77+
78+
- name: Comment on PR
79+
uses: thollander/actions-comment-pull-request@master
80+
with:
81+
message: '@${{ github.actor }} Image is available for testing. `docker pull ${{ github.repository }}:${{ steps.generate_tag.outputs.GIT_TAG }}`'
82+
GITHUB_TOKEN: ${{ secrets.STAKATER_GITHUB_TOKEN }}
83+
84+
- name: Notify Failure
85+
if: failure()
86+
uses: thollander/actions-comment-pull-request@master
87+
with:
88+
message: '@${{ github.actor }} Yikes! You better fix it before anyone else finds out! [Build](https://github.com/${{ github.repository }}/commit/${{ github.event.pull_request.head.sha }}/checks) has Failed!'
89+
GITHUB_TOKEN: ${{ secrets.STAKATER_GITHUB_TOKEN }}
90+
91+
- name: Notify Slack
92+
uses: 8398a7/action-slack@v3
93+
if: always() # Pick up events even if the job fails or is canceled.
94+
with:
95+
status: ${{ job.status }}
96+
fields: repo,author,action,eventName,ref,workflow
97+
env:
98+
GITHUB_TOKEN: ${{ secrets.STAKATER_GITHUB_TOKEN }}
99+
SLACK_WEBHOOK_URL: ${{ secrets.STAKATER_DELIVERY_SLACK_WEBHOOK }}

.github/workflows/push.yml

Lines changed: 154 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,154 @@
1+
name: Push
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
8+
env:
9+
DOCKER_FILE_PATH: Dockerfile
10+
GOLANG_VERSION: 1.14
11+
OPERATOR_SDK_VERSION: "1.0.0"
12+
KUSTOMIZE_VERSION: "3.5.4"
13+
KUBERNETES_VERSION: "1.18.0"
14+
KIND_VERSION: "0.7.0"
15+
16+
jobs:
17+
build:
18+
name: Build
19+
if: "! contains(toJSON(github.event.commits.*.message), '[skip-ci]')"
20+
runs-on: ubuntu-latest
21+
22+
steps:
23+
- name: Check out code
24+
uses: actions/checkout@v2
25+
with:
26+
persist-credentials: false # otherwise, the token used is the GITHUB_TOKEN, instead of your personal token
27+
fetch-depth: 0 # otherwise, you will fail to push refs to dest repo
28+
29+
- name: Set up Go
30+
id: go
31+
uses: actions/setup-go@v2
32+
with:
33+
go-version: ${{ env.GOLANG_VERSION }}
34+
35+
- name: Lint
36+
run: |
37+
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.26.0
38+
golangci-lint run --timeout=10m ./...
39+
40+
- name: Install kubectl
41+
run: |
42+
curl -LO "https://storage.googleapis.com/kubernetes-release/release/v${KUBERNETES_VERSION}/bin/linux/amd64/kubectl"
43+
sudo install ./kubectl /usr/local/bin/ && rm kubectl
44+
kubectl version --short --client
45+
kubectl version --short --client | grep -q ${KUBERNETES_VERSION}
46+
47+
- name: Install Kind
48+
run: |
49+
curl -L -o kind https://github.com/kubernetes-sigs/kind/releases/download/v${KIND_VERSION}/kind-linux-amd64
50+
sudo install ./kind /usr/local/bin && rm kind
51+
kind version
52+
kind version | grep -q ${KIND_VERSION}
53+
54+
- name: Create Kind Cluster
55+
run: |
56+
kind create cluster
57+
58+
- name: Set up Cluster
59+
run: |
60+
kubectl cluster-info
61+
kubectl create namespace test
62+
echo "${{ secrets.SECRET_KUBERNETES_RESOURCES }}"> kube.yaml
63+
kubectl apply -f kube.yaml
64+
rm -f kube.yaml
65+
66+
- name: Test
67+
run: make test OPERATOR_NAMESPACE=test USE_EXISTING_CLUSTER=true
68+
69+
- name: Generate Tag
70+
id: generate_tag
71+
uses: anothrNick/[email protected]
72+
env:
73+
GITHUB_TOKEN: ${{ secrets.STAKATER_GITHUB_TOKEN }}
74+
WITH_V: true
75+
DEFAULT_BUMP: patch
76+
DRY_RUN: true
77+
78+
- name: Build and push Docker images
79+
uses: docker/build-push-action@v1
80+
with:
81+
username: ${{ secrets.STAKATER_DOCKERHUB_USERNAME }}
82+
password: ${{ secrets.STAKATER_DOCKERHUB_PASSWORD }}
83+
repository: ${{ env.GITHUB_REPOSITORY }}
84+
add_git_labels: true
85+
dockerfile: ${{ env.DOCKER_FILE_PATH }}
86+
tags: ${{ steps.generate_tag.outputs.new_tag }}
87+
88+
89+
##############################
90+
## Add steps to generate required artifacts for a release here(helm chart, operator manifest etc.)
91+
##############################
92+
93+
# Generate tag for operator without "v"
94+
- name: Generate Operator Tag
95+
id: generate_operator_tag
96+
uses: anothrNick/[email protected]
97+
env:
98+
GITHUB_TOKEN: ${{ secrets.STAKATER_GITHUB_TOKEN }}
99+
WITH_V: false
100+
DEFAULT_BUMP: patch
101+
DRY_RUN: true
102+
103+
# Install operator-sdk
104+
- name: Install operator-sdk
105+
env:
106+
OPERATOR_SDK_VERSION: ${{ env.OPERATOR_SDK_VERSION }}
107+
run: |
108+
curl -fL -o /tmp/operator-sdk "https://github.com/operator-framework/operator-sdk/releases/download/v${OPERATOR_SDK_VERSION}/operator-sdk-v${OPERATOR_SDK_VERSION}-x86_64-linux-gnu"
109+
sudo install /tmp/operator-sdk /usr/local/bin && rm -f /tmp/operator-sdk
110+
operator-sdk version
111+
operator-sdk version | grep -q "${OPERATOR_SDK_VERSION}"
112+
113+
# Install kustomize
114+
- uses: imranismail/setup-kustomize@v1
115+
with:
116+
kustomize-version: ${{ env.KUSTOMIZE_VERSION }}
117+
118+
- name: Generate Bundle
119+
env:
120+
VERSION: ${{ steps.generate_operator_tag.outputs.new_tag }}
121+
run: make bundle
122+
123+
- name: Generate Package Manifests
124+
env:
125+
VERSION: ${{ steps.generate_operator_tag.outputs.new_tag }}
126+
run: make packagemanifests
127+
128+
# Commit back changes
129+
- name: Commit files
130+
run: |
131+
git config --local user.email "[email protected]"
132+
git config --local user.name "stakater-user"
133+
git commit -m "[skip-ci] Update artifacts" -a
134+
- name: Push changes
135+
uses: ad-m/github-push-action@master
136+
with:
137+
github_token: ${{ secrets.STAKATER_GITHUB_TOKEN }}
138+
139+
- name: Push Latest Tag
140+
uses: anothrNick/[email protected]
141+
env:
142+
GITHUB_TOKEN: ${{ secrets.STAKATER_GITHUB_TOKEN }}
143+
WITH_V: true
144+
DEFAULT_BUMP: patch
145+
146+
- name: Notify Slack
147+
uses: 8398a7/action-slack@v3
148+
if: always() # Pick up events even if the job fails or is canceled.
149+
with:
150+
status: ${{ job.status }}
151+
fields: repo,author,action,eventName,ref,workflow
152+
env:
153+
GITHUB_TOKEN: ${{ secrets.STAKATER_GITHUB_TOKEN }}
154+
SLACK_WEBHOOK_URL: ${{ secrets.STAKATER_DELIVERY_SLACK_WEBHOOK }}

.github/workflows/release.yml

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
name: Release Go project
2+
3+
on:
4+
push:
5+
tags:
6+
- "v*"
7+
8+
env:
9+
GOLANG_VERSION: 1.14
10+
11+
jobs:
12+
build:
13+
name: GoReleaser build
14+
runs-on: ubuntu-latest
15+
16+
steps:
17+
- name: Check out code
18+
uses: actions/checkout@v2
19+
with:
20+
fetch-depth: 0 # See: https://goreleaser.com/ci/actions/
21+
22+
- name: Set up Go 1.x
23+
uses: actions/setup-go@v2
24+
with:
25+
go-version: ${{ env.GOLANG_VERSION }}
26+
id: go
27+
28+
- name: Run GoReleaser
29+
uses: goreleaser/goreleaser-action@master
30+
with:
31+
version: latest
32+
args: release --rm-dist
33+
env:
34+
GITHUB_TOKEN: ${{ secrets.STAKATER_GITHUB_TOKEN }}
35+
36+
- name: Notify Slack
37+
uses: 8398a7/action-slack@v3
38+
if: always()
39+
with:
40+
status: ${{ job.status }}
41+
fields: repo,author,action,eventName,ref,workflow
42+
env:
43+
GITHUB_TOKEN: ${{ secrets.STAKATER_GITHUB_TOKEN }}
44+
SLACK_WEBHOOK_URL: ${{ secrets.STAKATER_DELIVERY_SLACK_WEBHOOK }}

.goreleaser.yml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
before:
2+
hooks:
3+
- go mod download
4+
- go generate ./...
5+
builds:
6+
- env:
7+
- CGO_ENABLED=0
8+
goos:
9+
- linux
10+
- windows
11+
- darwin
12+
archives:
13+
- replacements:
14+
darwin: Darwin
15+
linux: Linux
16+
windows: Windows
17+
386: i386
18+
amd64: x86_64
19+
checksum:
20+
name_template: 'checksums.txt'
21+
snapshot:
22+
name_template: "{{ .Tag }}-next"
23+
changelog:
24+
sort: asc
25+
filters:
26+
exclude:
27+
- '^docs:'
28+
- '^test:'

Dockerfile

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Build the manager binary
2-
FROM golang:1.13 as builder
2+
FROM registry.svc.ci.openshift.org/openshift/release:golang-1.14 as builder
33

44
WORKDIR /workspace
55
# Copy the Go Modules manifests
@@ -13,9 +13,10 @@ RUN go mod download
1313
COPY main.go main.go
1414
COPY api/ api/
1515
COPY controllers/ controllers/
16+
COPY pkg/ pkg/
1617

1718
# Build
18-
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 GO111MODULE=on go build -a -o manager main.go
19+
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 GO111MODULE=on go build -mod=mod -a -o manager main.go
1920

2021
# Use distroless as minimal base image to package the manager binary
2122
# Refer to https://github.com/GoogleContainerTools/distroless for more details
@@ -24,4 +25,4 @@ WORKDIR /
2425
COPY --from=builder /workspace/manager .
2526
USER nonroot:nonroot
2627

27-
ENTRYPOINT ["/manager"]
28+
ENTRYPOINT ["/manager"]

0 commit comments

Comments
 (0)