forked from clicktruck/cert-manager-webhook-oci
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: prepare github action workflows #1
Signed-off-by: Thomas Pham <thomas.pham@sicpa.com>
- Loading branch information
Showing
15 changed files
with
283 additions
and
372 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
name: 'Release Helm Chart' | ||
|
||
on: | ||
push: | ||
branches: | ||
- 'main' | ||
paths: | ||
- 'deploy/**' | ||
|
||
jobs: | ||
release: | ||
# depending on default permission settings for your org (contents being read-only or read-write for workloads), you will have to add permissions | ||
# see: https://docs.github.com/en/actions/security-guides/automatic-token-authentication#modifying-the-permissions-for-the-github_token | ||
permissions: | ||
contents: write | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v3 | ||
with: | ||
fetch-depth: 0 | ||
|
||
- name: Configure Git | ||
run: | | ||
git config user.name "$GITHUB_ACTOR" | ||
git config user.email "$GITHUB_ACTOR@users.noreply.github.com" | ||
- name: Install Helm | ||
uses: azure/setup-helm@v3 | ||
with: | ||
version: v3.11.2 | ||
|
||
- name: Run chart-releaser | ||
uses: helm/chart-releaser-action@v1.5.0 | ||
with: | ||
charts_dir: deploy | ||
charts_repo_url: https://github.com/thpham/cert-manager-webhook-oci | ||
env: | ||
CR_TOKEN: "${{ secrets.GITHUB_TOKEN }}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
name: 'Build and push main/tags' | ||
|
||
on: | ||
workflow_dispatch: | ||
push: | ||
branches: | ||
- 'main' | ||
tags: | ||
- 'v*' | ||
# Ignore specific changes | ||
paths-ignore: | ||
- 'deploy/**' | ||
pull_request: | ||
types: [ labeled ] | ||
branches: | ||
- 'main' | ||
paths-ignore: | ||
- 'deploy/**' | ||
|
||
env: | ||
REGISTRY: ghcr.io | ||
IMAGE_NAME: ${{ github.repository_owner }}/cert-manager-webhook-oci | ||
|
||
jobs: | ||
build-and-publish: | ||
if: github.event_name == 'push' || github.event.label.name == 'build' | ||
# depending on default permission settings for your org (contents being read-only or read-write for workloads), you will have to add permissions | ||
# see: https://docs.github.com/en/actions/security-guides/automatic-token-authentication#modifying-the-permissions-for-the-github_token | ||
permissions: | ||
contents: read | ||
packages: write | ||
runs-on: ubuntu-latest | ||
strategy: | ||
fail-fast: false | ||
matrix: | ||
platform: | ||
- linux/amd64 | ||
- linux/arm64 | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v3 | ||
|
||
# Add support for more platforms with QEMU (optional) | ||
# https://github.com/docker/setup-qemu-action | ||
- name: Set up QEMU | ||
id: qemu | ||
uses: docker/setup-qemu-action@v2 | ||
|
||
# https://github.com/docker/setup-buildx-action | ||
- name: Set up Docker Buildx | ||
id: buildx | ||
uses: docker/setup-buildx-action@v2 | ||
|
||
- name: Login to GHCR | ||
if: github.event_name == 'push' | ||
uses: docker/login-action@v2 | ||
with: | ||
registry: ghcr.io | ||
username: ${{ github.repository_owner }} | ||
password: ${{ secrets.GITHUB_TOKEN }} | ||
|
||
# https://github.com/docker/metadata-action | ||
- name: Docker meta | ||
id: meta | ||
uses: docker/metadata-action@v4 | ||
with: | ||
images: | | ||
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} | ||
tags: | | ||
type=ref,event=tag | ||
type=ref,event=pr | ||
type=semver,pattern={{version}} | ||
type=semver,pattern={{major}}.{{minor}} | ||
# set latest tag for main branch | ||
type=raw,value=latest,enable=${{ github.ref == format('refs/heads/{0}', 'main') }} | ||
- name: Release build | ||
id: release_build | ||
uses: docker/build-push-action@v4 | ||
with: | ||
context: . | ||
platforms: ${{ matrix.platform }} | ||
push: ${{ github.event_name == 'push' }} | ||
tags: ${{ steps.meta.outputs.tags }} | ||
labels: ${{ steps.meta.outputs.labels }} | ||
build-args: | | ||
Version=${{ steps.meta.outputs.tags }} | ||
GitCommit=${{ github.sha }} | ||
- name: Image digest | ||
run: echo ${{ steps.release_build.outputs.digest }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
name: 'README sync' | ||
|
||
on: | ||
push: | ||
branches: | ||
- 'main' | ||
paths: | ||
- 'gh-pages-readme.md' | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- run: | | ||
cp -f gh-pages-readme.md ${{ runner.temp }}/README.md | ||
- uses: actions/checkout@v3 | ||
with: | ||
ref: gh-pages | ||
- run: | | ||
cp -f ${{ runner.temp }}/README.md . | ||
git config user.name "$GITHUB_ACTOR" | ||
git config user.email "$GITHUB_ACTOR@users.noreply.github.com" | ||
git add README.md | ||
git commit --signoff -m "Sync README from main" | ||
git push |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
name: 'Run tests' | ||
|
||
on: | ||
pull_request: | ||
types: [ labeled ] | ||
workflow_dispatch: | ||
|
||
jobs: | ||
test: | ||
runs-on: ubuntu-latest | ||
if: github.event.label.name == 'testing' | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v3 | ||
|
||
- uses: actions/setup-go@v4 | ||
with: | ||
go-version: '1.20.4' | ||
|
||
- name: Run tests | ||
shell: bash | ||
run: | | ||
make test |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,42 @@ | ||
ARG GOLANG_VERSION=1.20.4 | ||
ARG ALPINE_VERSION=3.17 | ||
|
||
FROM golang:${GOLANG_VERSION}-alpine${ALPINE_VERSION} AS build_deps | ||
FROM --platform=${BUILDPLATFORM:-linux/amd64} golang:${GOLANG_VERSION} AS builder | ||
|
||
RUN apk add --no-cache git | ||
ARG TARGETPLATFORM | ||
ARG BUILDPLATFORM | ||
ARG TARGETOS | ||
ARG TARGETARCH | ||
|
||
WORKDIR /workspace | ||
ARG Version | ||
ARG GitCommit | ||
|
||
ENV CGO_ENABLED=0 | ||
ENV GO111MODULE=on | ||
|
||
COPY go.mod . | ||
COPY go.sum . | ||
RUN mkdir -p /go/src/github.com/thpham/cert-manager-webhook-oci | ||
WORKDIR /go/src/github.com/thpham/cert-manager-webhook-oci | ||
|
||
# Cache the download before continuing | ||
COPY go.mod go.mod | ||
COPY go.sum go.sum | ||
RUN go mod download | ||
|
||
FROM build_deps AS build | ||
COPY pkg pkg | ||
COPY main.go main.go | ||
COPY main_test.go main_test.go | ||
|
||
COPY . . | ||
#RUN CGO_ENABLED=${CGO_ENABLED} GOOS=${TARGETOS} GOARCH=${TARGETARCH} \ | ||
# go test -v ./... | ||
|
||
RUN CGO_ENABLED=0 go build -o webhook -ldflags '-w -extldflags "-static"' . | ||
RUN CGO_ENABLED=${CGO_ENABLED} GOOS=${TARGETOS} GOARCH=${TARGETARCH} \ | ||
go build -ldflags "-s -w -X github.com/thpham/cert-manager-webhook-oci/pkg/version.Release=${Version} -X github.com/thpham/cert-manager-webhook-oci/pkg/version.SHA=${GitCommit}" -o /usr/bin/cert-manager-webhook-oci . | ||
|
||
FROM alpine:${ALPINE_VERSION} | ||
FROM --platform=${BUILDPLATFORM:-linux/amd64} gcr.io/distroless/base:nonroot | ||
|
||
RUN apk add --no-cache ca-certificates | ||
LABEL org.opencontainers.image.source=https://github.com/thpham/cert-manager-webhook-oci | ||
|
||
COPY --from=build /workspace/webhook /usr/local/bin/webhook | ||
WORKDIR / | ||
COPY --from=builder /usr/bin/cert-manager-webhook-oci / | ||
USER nonroot:nonroot | ||
|
||
ENTRYPOINT ["webhook"] | ||
CMD ["/cert-manager-webhook-oci"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.