Skip to content

Commit

Permalink
fix(ci) update directory name in dockerfile
Browse files Browse the repository at this point in the history
fix(ci) update go version in CI/CD to match go.mod
fix(ci) restore manifests target in Makefile
feat(ci) update setup-go github action
feat(ci) use makefile targets
feat(ci) format .github files
feat(makefile) Remove unused gomplate
feat(makefile) Add make-lint target
feat(makefile) Create binaries folder when necessary
feat(dockerfile) Copy all file at once
feat(dockerfile) use single make command

Signed-off-by: Pierre Péronnet <pierre.peronnet@ovhcloud.com>
  • Loading branch information
holyhope committed Aug 28, 2020
1 parent 7d0174c commit 8949437
Show file tree
Hide file tree
Showing 7 changed files with 141 additions and 120 deletions.
9 changes: 5 additions & 4 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
*.so
*.dylib
bin
node_modules

# Test binary, build with `go test -c`
*.test
Expand All @@ -25,13 +26,13 @@ bin
*.swo
*~

## Github
.github

## KubeBuilder autogenerated files
config/crd/bases
config/rbac/role.yaml
config/webhook/manifests.yaml

## Pkger autogenerated files
pkged.go

## goreleaser
dist/
dist/
52 changes: 22 additions & 30 deletions .github/workflows/goreleaser.yml
Original file line number Diff line number Diff line change
@@ -1,39 +1,31 @@
on:
push:
tags:
- 'v*'
- 'v*'

jobs:
goreleaser:
runs-on: ubuntu-latest
steps:
-
name: Checkout
uses: actions/checkout@v2
-
name: Unshallow
# required for the changelog to work correctly
run: git fetch --prune --unshallow
-
name: Set up Go
uses: actions/setup-go@v1
with:
go-version: 1.13
-
name: prepare changelog
run: |
tag=${{ github.ref }}
tag=${tag##*/}
cat <<EOF | tee /tmp/release.txt
## Docker images
- uses: actions/checkout@v2
- # required for the changelog to work correctly
run: git fetch --prune --unshallow
- uses: actions/setup-go@v2
with:
go-version: 1.14
- name: prepare changelog
run: |
tag=${{ github.ref }}
tag=${tag##*/}
cat <<EOF | tee /tmp/release.txt
## Docker images
- \`docker pull goharbor/harbor-operator:$tag\`
EOF
-
name: Run GoReleaser
uses: goreleaser/goreleaser-action@v1
with:
version: v0.129.0
args: release --rm-dist --release-footer /tmp/release.txt
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- \`docker pull goharbor/harbor-operator:$tag\`
EOF
- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v1
with:
version: v0.129.0
args: release --rm-dist --release-footer /tmp/release.txt
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
54 changes: 24 additions & 30 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,33 +20,30 @@ jobs:

docker-lint:
runs-on: ubuntu-latest
name: DockerLint
name: 'dockerfile: lint'
steps:
- name: Checkout
uses: actions/checkout@v2
- name: lint
uses: brpaz/hadolint-action@master
- uses: actions/checkout@v2
- run: make docker-lint

# Golang tests
go-lint:
runs-on: ubuntu-latest
name: GoLint
name: 'golang: lint'
steps:
- uses: actions/checkout@v2
- name: Run golangci-lint
uses: actions-contrib/golangci-lint@v1
- uses: actions/setup-go@v2
with:
golangci_lint_version: 1.22.2
go-version: 1.14
- uses: actions/checkout@v2
- run: make go-lint

go-dependencies:
runs-on: ubuntu-latest
name: Dependencies are up to date
steps:
- uses: actions/setup-go@v1
- uses: actions/setup-go@v2
with:
go-version: 1.13
- name: Checkout
uses: actions/checkout@v2
go-version: 1.14
- uses: actions/checkout@v2
- run: go mod tidy
- run: go mod vendor
- run: go mod graph
Expand All @@ -58,11 +55,10 @@ jobs:
runs-on: ubuntu-latest
name: Generated files are up to date
steps:
- uses: actions/setup-go@v1
- uses: actions/setup-go@v2
with:
go-version: 1.13
- name: Checkout
uses: actions/checkout@v2
go-version: 1.14
- uses: actions/checkout@v2
- run: make generate
- name: Check diff
run: |
Expand All @@ -82,10 +78,9 @@ jobs:
k8sVersion: ["1.15", "1.16", "1.17"]

steps:
- name: Set up Go 1.13
uses: actions/setup-go@v1
- uses: actions/setup-go@v2
with:
go-version: 1.13
go-version: 1.14
- name: Install Kubernetes v${{ matrix.k8sVersion }}
run: |
sudo snap install microk8s --channel='${{ matrix.k8sVersion }}/stable' --classic
Expand Down Expand Up @@ -122,8 +117,10 @@ jobs:
crd-kubernetes-resources:
runs-on: ubuntu-latest
name: 'kubernetes_resources: ./config/crd'
steps:
- run: sudo apt-get install -y bzr # Required to install controller-gen in make manifests
steps:
- uses: actions/setup-go@v2
with:
go-version: 1.14
- uses: actions/checkout@v2
- run: make manifests
- uses: azure/k8s-bake@v1
Expand All @@ -136,7 +133,9 @@ jobs:
runs-on: ubuntu-latest
name: 'kubernetes_resources: ./config/default'
steps:
- run: sudo apt-get install -y bzr # Required to install controller-gen in make manifests
- uses: actions/setup-go@v2
with:
go-version: 1.14
- uses: actions/checkout@v2
- run: make manifests
- uses: azure/k8s-bake@v1
Expand All @@ -162,9 +161,4 @@ jobs:
name: 'documentation: lint'
steps:
- uses: actions/checkout@v2
- name: markdownlint-cli
uses: nosborn/github-action-markdown-cli@v1.1.1
with:
files: .
config_file: ".markdownlint.json"
ignore_files: "vendor"
- run: make md-lint
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
*.so
*.dylib
bin
node_modules

# Test binary, build with `go test -c`
*.test
Expand All @@ -31,4 +32,4 @@ pkged.go
.DS_Store

## goreleaser
dist/
dist/
24 changes: 4 additions & 20 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Build the manager binary
FROM golang:1.13.4 as builder
FROM golang:1.14.5 as builder

WORKDIR /workspace
# Copy the Go Modules manifests
Expand All @@ -13,31 +13,15 @@ ENV CGO_ENABLED=0 \
GO111MODULE=on

# Copy the go source
COPY main.go main.go
COPY api api
COPY pkg pkg
COPY controllers controllers
COPY assets assets
COPY . .

COPY hack hack

COPY Makefile Makefile

RUN make generate

COPY vendor vendor
# Build
RUN go build -a \
-ldflags "-X ${GO_APP_PKG}.OperatorVersion=${RELEASE_VERSION}" \
-o manager \
pkged.go \
main.go
RUN make manager

# Use distroless as minimal base image to package the manager binary
# Refer to https://github.com/GoogleContainerTools/distroless for more details
FROM gcr.io/distroless/static:nonroot
WORKDIR /
COPY --from=builder /workspace/manager .
COPY --from=builder /workspace/bin/manager .
USER nonroot:nonroot

ENTRYPOINT ["/manager"]
Loading

0 comments on commit 8949437

Please sign in to comment.