Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Release scripts #11

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions .dockerignore

This file was deleted.

71 changes: 13 additions & 58 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: CI

on:
push:
branches: [ main ]
branches: [ master ]
tags:
- "*"
pull_request:
Expand All @@ -21,7 +21,7 @@ jobs:
with:
go-version: 1.23
- name: Build
run: make
run: make build

docs:
runs-on: ubuntu-latest
Expand All @@ -37,41 +37,6 @@ jobs:
# make gen-docs
# git diff --exit-code

linux:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: 1.23
- name: Build kg and kgctl for all Linux Architectures
run: make all-build

darwin:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: 1.23
- name: Build kgctl for Darwin amd64
run: make OS=darwin ARCH=amd64
- name: Build kgctl for Darwin arm64
run: make OS=darwin ARCH=arm64

windows:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: 1.23
- name: Build kgctl for Windows
run: make OS=windows

unit:
runs-on: ubuntu-latest
steps:
Expand All @@ -94,25 +59,15 @@ jobs:
- name: Run e2e Tests
run: make e2e

lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: 1.23
- name: Lint Code
run: make lint

container:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: 1.23
- name: Container
run: make container
# https://github.com/castai/kilo/issues/12
#lint:
# runs-on: ubuntu-latest
# steps:
# - uses: actions/checkout@v3
# - name: Set up Go
# uses: actions/setup-go@v4
# with:
# go-version: 1.23
# - name: Lint Code
# run: make lint

47 changes: 47 additions & 0 deletions .github/workflows/goreleaser.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: goreleaser

on:
pull_request:
paths:
- .github/workflows/goreleaser.yml
- .goreleaser.yaml
push:
tags:
- 'v*'

permissions:
contents: write

jobs:
goreleaser:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0
- uses: actions/setup-go@v4
with:
go-version: v1.23.0
- name: SET LDFLAGS
run: echo "LDFLAGS=$(make ldflags)" >> $GITHUB_ENV
- name: Delete non-semver tags
run: 'git tag -d $(git tag -l | grep -v "^v")'
- name: Run GoReleaser on tag
if: github.event_name != 'pull_request'
uses: goreleaser/goreleaser-action@v4
with:
distribution: goreleaser
version: latest
args: release --timeout 60m
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Run GoReleaser on pull request
if: github.event_name == 'pull_request'
uses: goreleaser/goreleaser-action@v4
with:
distribution: goreleaser
version: latest
args: release --timeout 60m --snapshot
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
110 changes: 110 additions & 0 deletions .github/workflows/images.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
name: Create and publish a Container image

on:
push:
branches:
- master # Trigger the workflow on push to the master branch
tags:
- 'v*' # Trigger the workflow on version tags like v1.0.0, v2.0.0, etc.
pull_request:
branches:
- master # Trigger workflow when a PR targets the master branch

permissions:
contents: read
packages: write
id-token: write

# Defines two custom environment variables for the workflow. These are used for the Container registry domain, and a name for the Docker image that this workflow builds.
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}

jobs:
build-tagged-image:
runs-on: ubuntu-latest
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v')
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Log in to the Container registry
uses: docker/login-action@65b78e6e13532edd9afa3aa52ac7964289d1a9c1
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@9ec57ed1fcdbf14dcef7dfbe97b2010124a938b7
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}

- name: Build and push versioned Docker image
uses: docker/build-push-action@f2a1d5e99d037542a71f64918e516c093c6f3fc4
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }} # Version tag from the metadata action
labels: ${{ steps.meta.outputs.labels }}

build-latest-image:
runs-on: ubuntu-latest
if: github.event_name == 'push' && github.ref == 'refs/heads/master'
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Log in to the Container registry
uses: docker/login-action@65b78e6e13532edd9afa3aa52ac7964289d1a9c1
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@9ec57ed1fcdbf14dcef7dfbe97b2010124a938b7
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}

- name: Build and push latest Docker image
uses: docker/build-push-action@f2a1d5e99d037542a71f64918e516c093c6f3fc4
with:
context: .
push: true
tags: |
${{ steps.meta.outputs.tags }}
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest
labels: ${{ steps.meta.outputs.labels }}

build-pr-image:
runs-on: ubuntu-latest
if: github.event_name == 'pull_request'
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Log in to the Container registry
uses: docker/login-action@65b78e6e13532edd9afa3aa52ac7964289d1a9c1
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@9ec57ed1fcdbf14dcef7dfbe97b2010124a938b7
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}

- name: Build and push PR-specific Docker image
uses: docker/build-push-action@f2a1d5e99d037542a71f64918e516c093c6f3fc4
with:
context: .
push: true
tags: |
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:pr-${{ github.event.pull_request.number }}
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ github.sha }} # Short commit hash
labels: ${{ steps.meta.outputs.labels }}
21 changes: 0 additions & 21 deletions .github/workflows/release.yaml

This file was deleted.

8 changes: 2 additions & 6 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,5 @@
bin/
tmp/
e2e/kind.yaml*
hack/tools/controller-gen
hack/tools/controller-gen-v0.16.1
hack/tools/openshift-goimports
hack/tools/openshift-goimports-c72f1dc2e3aacfa00aece3391d938c9bc734e791
hack/tools/yaml-patch
hack/tools/yaml-patch-v0.0.11
hack/tools/
dist/
38 changes: 38 additions & 0 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
project_name: kilo-castai
version: 2
env:
- CGO_ENABLED=0
- LDFLAGS={{ .Env.LDFLAGS }}

builds:
- id: kilo-kg
dir: cmd/kg
binary: kg
ldflags: "{{ .Env.LDFLAGS }}"
goos:
- linux
goarch:
- amd64
- arm64
- id: kilo-kgctl
dir: cmd/kgctl
binary: kilo-kgctl
ldflags: "{{ .Env.LDFLAGS }}"
goos:
- linux
goarch:
- amd64
- arm64

archives:
- id: kilo-plugin
builds:
- kilo-kgctl
- kilo-kg
name_template: "kilo-plugin_{{ .Version }}_{{ .Os }}_{{ .Arch }}"

release:
prerelease: auto
mode: keep-existing
github:
owner: castai
50 changes: 42 additions & 8 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,20 +1,54 @@
ARG FROM=alpine
FROM $FROM AS cni
# BUILDER PHASE
FROM --platform=${BUILDPLATFORM} docker.io/golang:1.23.0 AS builder
WORKDIR /workspace

# Install dependencies.
RUN apt-get update && apt-get install -y jq && mkdir bin

# Run this with docker build --build-arg goproxy=$(go env GOPROXY) to override the goproxy
ARG goproxy=https://proxy.golang.org
ENV GOPROXY=$goproxy

# Copy the Go Modules manifests
COPY go.mod go.mod
COPY go.sum go.sum
USER 0

# Cache deps before building and copying source so that we don't need to re-download as much
# and so that source changes don't invalidate our downloaded layer
RUN --mount=type=cache,target=/go/pkg/mod \
go mod download

# Copy the sources
COPY ./ ./

ARG TARGETOS
ARG TARGETARCH

RUN --mount=type=cache,target=/root/.cache/go-build \
--mount=type=cache,target=/go/pkg/mod \
make build OS=${TARGETOS} ARCH=${TARGETARCH}

# CNI DOWNLOAD PHASE
FROM alpine AS cni
ARG GOARCH=amd64
ARG CNI_PLUGINS_VERSION=v1.1.1
ARG CNI_PLUGINS_VERSION=v1.6.0
RUN apk add --no-cache curl && \
curl -Lo cni.tar.gz https://github.com/containernetworking/plugins/releases/download/$CNI_PLUGINS_VERSION/cni-plugins-linux-$GOARCH-$CNI_PLUGINS_VERSION.tgz && \
tar -xf cni.tar.gz

FROM $FROM
# FINAL IMAGE
FROM alpine
ARG GOARCH
ARG ALPINE_VERSION=v3.20
LABEL maintainer="squat <[email protected]>"
LABEL maintainer="Cast AI"
RUN echo -e "https://alpine.global.ssl.fastly.net/alpine/$ALPINE_VERSION/main\nhttps://alpine.global.ssl.fastly.net/alpine/$ALPINE_VERSION/community" > /etc/apk/repositories && \
apk add --no-cache ipset iptables ip6tables graphviz font-noto

COPY --from=cni bridge host-local loopback portmap /opt/cni/bin/
ADD https://raw.githubusercontent.com/kubernetes-sigs/iptables-wrappers/e139a115350974aac8a82ec4b815d2845f86997e/iptables-wrapper-installer.sh /
RUN chmod 700 /iptables-wrapper-installer.sh && /iptables-wrapper-installer.sh --no-sanity-check
COPY bin/linux/$GOARCH/kg /opt/bin/
COPY bin/linux/$GOARCH/kgctl /opt/bin/
ENTRYPOINT ["/opt/bin/kg"]

COPY --from=builder workspace/bin/* /usr/local/bin/

ENTRYPOINT ["/usr/local/bin/kg"]
Loading
Loading