Skip to content

Commit

Permalink
updated dependencies, pr workflow, makefile, dockerfile (#83)
Browse files Browse the repository at this point in the history
* updated dependencies, pr workflow, makefile, dockerfile

* lintfix: handle errors

* go mod tidy

---------

Co-authored-by: Richard Hagen <richard.hagen@bouvet.no>
  • Loading branch information
Richard87 and Richard87 authored Jan 3, 2024
1 parent 4d79626 commit 565f310
Show file tree
Hide file tree
Showing 7 changed files with 162 additions and 122 deletions.
33 changes: 32 additions & 1 deletion .github/workflows/pr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,39 @@ jobs:
name: Build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Build docker image
env:
REF: ${{ github. sha }}
run: docker build -t radix-github-webhook:${REF##*/} .

lint:
name: Lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 2
- uses: actions/setup-go@v4
with:
go-version: '1.21'
- name: Install dependencies
run: go mod download
- name: Install GolangCI Lint
run: curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.55.2

- name: golangci-lint
run: golangci-lint run --timeout=30m --max-same-issues=0 --out-format=github-actions

test:
name: Unit Test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v4
with:
go-version: '1.21'
- name: Install dependencies
run: go mod download
- name: Run Tests
run: go test -cover `go list ./...`
11 changes: 3 additions & 8 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ ENV GO111MODULE=on

RUN apk update && \
apk add ca-certificates && \
apk add --no-cache gcc musl-dev && \
go install honnef.co/go/tools/cmd/staticcheck@2023.1.3
apk add --no-cache gcc musl-dev

WORKDIR /go/src/github.com/equinor/radix-github-webhook/

Expand All @@ -14,19 +13,15 @@ COPY go.mod go.sum ./
RUN go mod download

COPY . .
# run tests and linting
RUN staticcheck ./... && \
go vet ./... && \
CGO_ENABLED=0 GOOS=linux go test `go list ./...`

# build
RUN CGO_ENABLED=0 GOOS=linux go build -ldflags "-s -w" -a -installsuffix cgo -o /usr/local/bin/radix-github-webhook
RUN CGO_ENABLED=0 GOOS=linux go build -ldflags "-s -w" -a -installsuffix cgo -o /radix-github-webhook
RUN addgroup -S -g 1000 radix-github-webhook
RUN adduser -S -u 1000 -G radix-github-webhook radix-github-webhook

FROM scratch
COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
COPY --from=builder /usr/local/bin/radix-github-webhook /usr/local/bin/radix-github-webhook
COPY --from=builder /radix-github-webhook /usr/local/bin/radix-github-webhook
COPY --from=builder /etc/passwd /etc/passwd
EXPOSE 3001
USER 1000
Expand Down
64 changes: 19 additions & 45 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,34 +18,12 @@ build: $(BINS)
test:
go test -cover `go list ./...`

staticcheck:
staticcheck ./...

.PHONY: deploy
deploy:
# Download deploy key + webhook shared secret
az keyvault secret download -f radix-github-webhook-radixregistration-values.yaml -n radix-github-webhook-radixregistration-values --vault-name radix-boot-dev-vault
# Add (also refreshes access tokens) and update helm repo
az acr helm repo add --name radixdev && helm repo update
# Install RR referring to the downloaded secrets
helm upgrade --install radix-github-webhook -f radix-github-webhook-radixregistration-values.yaml radixdev/radix-registration
# Delete secret file to avvoid being checked in
rm radix-github-webhook-radixregistration-values.yaml
# Allow operator to pick up RR. TODO should be handled with waiting for app namespace
sleep 5
# Create pipeline job
helm upgrade --install radix-pipeline-github-webhook radixdev/radix-pipeline-invocation \
--set name="radix-github-webhook" \
--set cloneURL="git@github.com:equinor/radix-github-webhook.git" \
--set cloneBranch="master"

.PHONY: undeploy
undeploy:
helm del --purge radix-github-webhook
helm del --purge radix-pipeline-github-webhook
.PHONY: lint
lint: bootstrap
golangci-lint run --max-same-issues 0

.PHONY: $(BINS)
$(BINS): vendor
$(BINS):
go build -ldflags '$(LDFLAGS)' -o bin/$@ .

.PHONY: docker-build
Expand All @@ -60,26 +38,22 @@ docker-push: $(addsuffix -push,$(IMAGES))
%-push:
docker push $(DOCKER_REGISTRY)/$*:$(IMAGE_TAG)

HAS_GOMETALINTER := $(shell command -v gometalinter;)
HAS_DEP := $(shell command -v dep;)
HAS_GIT := $(shell command -v git;)
.PHONY: mocks
mocks: bootstrap
mockgen -source ./radix/api_server.go -destination ./radix/api_server_mock.go -package radix

HAS_SWAGGER := $(shell command -v swagger;)
HAS_GOLANGCI_LINT := $(shell command -v golangci-lint;)
HAS_MOCKGEN := $(shell command -v mockgen;)

vendor:
ifndef HAS_GIT
$(error You must install git)
.PHONY: bootstrap
bootstrap:
ifndef HAS_SWAGGER
go install github.com/go-swagger/go-swagger/cmd/swagger@v0.30.5
endif
ifndef HAS_DEP
go get -u github.com/golang/dep/cmd/dep
ifndef HAS_GOLANGCI_LINT
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.55.2
endif
ifndef HAS_GOMETALINTER
go get -u github.com/alecthomas/gometalinter
gometalinter --install
ifndef HAS_MOCKGEN
go install github.com/golang/mock/mockgen@v1.6.0
endif
dep ensure

.PHONY: bootstrap
bootstrap: vendor

.PHONY: mocks
mocks:
mockgen -source ./radix/api_server.go -destination ./radix/api_server_mock.go -package radix
27 changes: 13 additions & 14 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,34 +8,33 @@ require (
github.com/golang-jwt/jwt/v4 v4.5.0
github.com/golang/mock v1.6.0
github.com/google/go-github/v53 v53.2.0
github.com/gorilla/mux v1.8.0
github.com/gorilla/mux v1.8.1
github.com/pkg/errors v0.9.1
github.com/prometheus/client_golang v1.16.0
github.com/prometheus/client_golang v1.18.0
github.com/sirupsen/logrus v1.9.3
github.com/spf13/pflag v1.0.5
github.com/stretchr/testify v1.8.4
golang.org/x/oauth2 v0.8.0
golang.org/x/oauth2 v0.15.0
)

require (
github.com/ProtonMail/go-crypto v0.0.0-20230217124315-7d5c6f04bbb8 // indirect
github.com/ProtonMail/go-crypto v0.0.0-20230923063757-afb1ddc0824c // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/cloudflare/circl v1.3.3 // indirect
github.com/cloudflare/circl v1.3.7 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/google/go-querystring v1.1.0 // indirect
github.com/kr/text v0.2.0 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect
github.com/matttproud/golang_protobuf_extensions/v2 v2.0.0 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/prometheus/client_model v0.3.0 // indirect
github.com/prometheus/common v0.42.0 // indirect
github.com/prometheus/procfs v0.10.1 // indirect
github.com/prometheus/client_model v0.5.0 // indirect
github.com/prometheus/common v0.45.0 // indirect
github.com/prometheus/procfs v0.12.0 // indirect
github.com/rogpeppe/go-internal v1.11.0 // indirect
golang.org/x/crypto v0.14.0 // indirect
golang.org/x/net v0.17.0 // indirect
golang.org/x/sys v0.13.0 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/protobuf v1.30.0 // indirect
golang.org/x/crypto v0.17.0 // indirect
golang.org/x/sys v0.15.0 // indirect
google.golang.org/appengine v1.6.8 // indirect
google.golang.org/protobuf v1.32.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
Loading

0 comments on commit 565f310

Please sign in to comment.