From bb725fe58a8b34574ed1f87c7c52f614d5c11c5d Mon Sep 17 00:00:00 2001 From: Christer Edvartsen Date: Thu, 8 Feb 2024 13:07:12 +0100 Subject: [PATCH] initial commit of Dockerfile and GitHub workflows --- .github/workflows/main.yaml | 63 +++++++++++++++++++++++++++++++++++++ .github/workflows/pr.yaml | 44 ++++++++++++++++++++++++++ Dockerfile | 12 +++++++ 3 files changed, 119 insertions(+) create mode 100644 .github/workflows/main.yaml create mode 100644 .github/workflows/pr.yaml create mode 100644 Dockerfile diff --git a/.github/workflows/main.yaml b/.github/workflows/main.yaml new file mode 100644 index 0000000..c1d25b8 --- /dev/null +++ b/.github/workflows/main.yaml @@ -0,0 +1,63 @@ +name: Build and push image and chart +on: + push: + branches: + - main +jobs: + build_push: + outputs: + version: ${{ steps.build-push-sign.outputs.version }} + permissions: + contents: read + id-token: write + name: Build and push + runs-on: ubuntu-latest-16-cores + steps: + - uses: actions/checkout@v4 + - uses: asdf-vm/actions/setup@v3 + - id: asdf-cache + uses: actions/cache@v4 + with: + path: ~/.asdf/ + key: ${{ runner.os }}-asdf-${{ hashFiles('**/.tool-versions') }} + - uses: asdf-vm/actions/install@v3 + if: steps.asdf-cache.outputs.cache-hit != 'true' + with: + before_install: | + asdf install golang latest + asdf global golang latest + - name: Find go cache dir + id: go-cache + run: | + go version + # Clear cache dirs to avoid error when restoring + go clean -cache -modcache + echo "gocache=$(go env GOCACHE)" >> $GITHUB_OUTPUT + echo "gomodcache=$(go env GOMODCACHE)" >> $GITHUB_OUTPUT + - name: Cache go modules + uses: actions/cache@v4 + with: + path: | + ${{ steps.go-cache.outputs.gocache }} + ${{ steps.go-cache.outputs.gomodcache }} + key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} + - run: go test ./... + # - run: helm lint --strict ./charts + - run: make staticcheck + - run: make vulncheck + - name: Check code format and run code generators + run: | + make fmt + make generate + git diff --exit-code --name-only + - id: go_version + run: echo "go_version=$(asdf current golang | awk '{print $2}')" >> $GITHUB_OUTPUT + - uses: nais/platform-build-push-sign@main + id: build-push-sign + with: + name: api-reconcilers + build_args: | + GO_VERSION=${{ steps.go_version.outputs.go_version }}- + google_service_account: gh-api-reconcilers + workload_identity_provider: ${{ secrets.NAIS_IO_WORKLOAD_IDENTITY_PROVIDER }} + push: true diff --git a/.github/workflows/pr.yaml b/.github/workflows/pr.yaml new file mode 100644 index 0000000..dd924a3 --- /dev/null +++ b/.github/workflows/pr.yaml @@ -0,0 +1,44 @@ +name: Check pull request +on: pull_request +jobs: + test: + name: Check pull request + runs-on: ubuntu-22.04 + steps: + - uses: actions/checkout@v4 + - uses: asdf-vm/actions/setup@v3 + - id: asdf-cache + uses: actions/cache@v4 + with: + path: ~/.asdf/ + key: ${{ runner.os }}-asdf-${{ hashFiles('**/.tool-versions') }} + - uses: asdf-vm/actions/install@v3 + if: steps.asdf-cache.outputs.cache-hit != 'true' + with: + before_install: | + asdf install golang latest + asdf global golang latest + - name: Find go cache dir + id: go-cache + run: | + go version + # Clear cache dirs to avoid error when restoring + go clean -cache -modcache + echo "gocache=$(go env GOCACHE)" >> $GITHUB_OUTPUT + echo "gomodcache=$(go env GOMODCACHE)" >> $GITHUB_OUTPUT + - name: Cache go modules + uses: actions/cache@v4 + with: + path: | + ${{ steps.go-cache.outputs.gocache }} + ${{ steps.go-cache.outputs.gomodcache }} + key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} + - run: go test ./... + - run: helm lint --strict ./charts + - run: make staticcheck + - run: make vulncheck + - name: Check code format and run code generators + run: | + make fmt + make generate + git diff --exit-code --name-only \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..4f8cf07 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,12 @@ +ARG GO_VERSION="" +FROM golang:${GO_VERSION}alpine as builder +WORKDIR /src +COPY go.* /src/ +RUN go mod download +COPY . /src +RUN go build -o bin/api-reconcilers ./cmd/api-reconcilers + +FROM gcr.io/distroless/base +WORKDIR /app +COPY --from=builder /src/bin/api-reconcilers /app/api-reconcilers +ENTRYPOINT ["/app/api-reconcilers"]