Skip to content

Commit

Permalink
fix image builds
Browse files Browse the repository at this point in the history
  • Loading branch information
mjudeikis committed Nov 26, 2024
1 parent 1218925 commit 74eefb2
Show file tree
Hide file tree
Showing 6 changed files with 83 additions and 266 deletions.
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

88 changes: 37 additions & 51 deletions .github/workflows/goreleaser.yml
Original file line number Diff line number Diff line change
@@ -1,61 +1,47 @@
name: Create and publish a Container image
name: goreleaser

on:
pull_request:
paths:
- .github/workflows/goreleaser.yml
- .goreleaser.yaml
push:
branches:
- master # Trigger the workflow on push to the master branch
tags:
- 'v*' # Trigger the workflow on tags like v1.0.0, v2.0.0, etc.
pull_request:
branches:
- master # Trigger workflow when a PR targets the master branch
- 'v*'

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 }}
contents: write

jobs:
build-and-push-image:
goreleaser:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write

steps:
- name: Checkout repository
uses: actions/checkout@v4

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

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

# Build and push Docker image
- name: Build and push Docker image
uses: docker/build-push-action@f2a1d5e99d037542a71f64918e516c093c6f3fc4
with:
context: .
push: true
# Tag the image as 'latest' for master branch, versioned tags for versioned pushes, and PR-specific tags
tags: |
${{ steps.meta.outputs.tags }}
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${GITHUB_REF##*/} # This will use the tag from the push
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:pr-${{ github.event.pull_request.number }} # PR-specific tag
labels: ${{ steps.meta.outputs.labels }}
- 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 }}
14 changes: 10 additions & 4 deletions .github/workflows/images.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ on:
- master # Trigger the workflow on push to the master branch
tags:
- 'v*' # Trigger the workflow on 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
Expand Down Expand Up @@ -49,9 +52,12 @@ jobs:
with:
context: .
push: true
# Tag the image as 'latest' for master branch and as the version tag for versioned pushes
# Tag the image as 'latest' only for master branch, versioned tags for versioned pushes, and PR-specific tags
tags: |
# Version tags for releases
${{ steps.meta.outputs.tags }}
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${GITHUB_REF##*/} # This will use the tag from the push
labels: ${{ steps.meta.outputs.labels }}
# Commit SHA for PR builds for precise versioning
${{ github.event_name == 'pull_request' && env.REGISTRY && env.IMAGE_NAME && format('{0}/{1}:{2}', env.REGISTRY, env.IMAGE_NAME, github.sha.substring(0, 7)) }}
labels: ${{ steps.meta.outputs.labels }}
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/
15 changes: 0 additions & 15 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,33 +11,18 @@ builds:
ldflags: "{{ .Env.LDFLAGS }}"
goos:
- linux
- darwin
- windows
goarch:
- amd64
- arm64
ignore:
- goos: darwin
goarch: ppc64le
- goos: windows
goarch: ppc64le
- id: kilo-kgctl
dir: cmd/kgctl
binary: kilo-kgctl
ldflags: "{{ .Env.LDFLAGS }}"
goos:
- linux
- darwin
- windows
goarch:
- amd64
- arm64
ignore:
- goos: darwin
goarch: ppc64le
- goos: windows
goarch: ppc64le


archives:
- id: kilo-plugin
Expand Down
Loading

0 comments on commit 74eefb2

Please sign in to comment.