Skip to content

Commit

Permalink
ci: adds k3s runner and k3s binary in release workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
nxtcoder17 committed Oct 9, 2024
1 parent f16e417 commit b0b1d6d
Showing 1 changed file with 158 additions and 8 deletions.
166 changes: 158 additions & 8 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,26 @@
name: build-images

on:
workflow_call:
inputs:
working_directory:
description: "cd into this directory"
required: true
type: string

image_name_prefix:
description: "image name prefix to use for container images"
required: true
type: string

secrets:
GITHUB_TOKEN:
required: true
CACHIX_AUTH_TOKEN:
required: true
CACHIX_CACHE_NAME:
required: true

workflow_dispatch:

push:
Expand Down Expand Up @@ -35,11 +55,24 @@ jobs:
- name: Checkout
uses: actions/checkout@v4

- name: setup env (on workflow_call)
shell: bash
if: github.event.name == 'workflow_call'
run: |+
echo "WORKING_DIR=${{ inputs.working_directory }}" | tee -a $GITHUB_ENV | tee -a $GITHUB_OUTPUT
echo "IMAGE_NAME_PREFIX=${{ inputs.image_name_prefix }}" | tee -a $GITHUB_ENV | tee -a $GITHUB_OUTPUT
- name: setup env (not on workflow_call)
shell: bash
run: |+
echo "WORKING_DIR=." | tee -a $GITHUB_ENV | tee -a $GITHUB_OUTPUT
echo "IMAGE_NAME_PREFIX=ghcr.io/${{ github.repository }}" | tee -a $GITHUB_ENV | tee -a $GITHUB_OUTPUT
- name: setup nix (with cachix)
uses: kloudlite/actions/setup-nix-cachix@v1
with:
flake_lock: ${{ inputs.working_directory }}/flake.lock
nix_develop_arguments: ${{ inputs.working_directory }}#default
flake_lock: ${{ env.WORKING_DIR }}/flake.lock
nix_develop_arguments: ${{ env.WORKING_DIR }}/#default

cachix_cache_name: ${{ secrets.CACHIX_CACHE_NAME }}
cachix_auth_token: ${{ secrets.CACHIX_AUTH_TOKEN }}
Expand All @@ -56,24 +89,24 @@ jobs:

- name: builds iac job image
if: ${{ matrix.name == 'iac-job' }}
working-directory: "./"
working-directory: ${{ env.WORKING_DIR }}
shell: bash
run: |
task local:build:iac-job Image="ghcr.io/${{ github.repository }}/iac-job:${IMAGE_TAG}"
task local:build:iac-job Image="$IMAGE_NAME_PREFIX/iac-job:${IMAGE_TAG}"
- name: builds gcp-spot-node-terminator
if: ${{ matrix.name == 'gcp-spot-node-terminator' }}
working-directory: ./cmd/gcp-spot-node-terminator
working-directory: ${{ env.WORKING_DIR }}/cmd/gcp-spot-node-terminator
shell: bash
run: |
task container:build-and-push image="ghcr.io/${{github.repository}}/cmd/gcp-spot-node-terminator:$IMAGE_TAG" push=true dockerArgs=""
task container:build-and-push image="$IMAGE_NAME_PREFIX/cmd/gcp-spot-node-terminator:$IMAGE_TAG" push=true dockerArgs=""
- name: builds aws spot node terminator
if: ${{ matrix.name == 'aws-spot-node-terminator'}}
working-directory: ./cmd/aws-spot-node-terminator
working-directory: ${{env.WORKING_DIR}}/cmd/aws-spot-node-terminator
shell: bash
run: |
task container:build-and-push image="ghcr.io/${{ github.repository }}/cmd/aws-spot-node-terminator:$IMAGE_TAG" push=true dockerArgs=""
task container:build-and-push image="$IMAGE_NAME_PREFIX/cmd/aws-spot-node-terminator:$IMAGE_TAG" push=true dockerArgs=""
# - uses: ./.github/actions/build-container-images
# with:
Expand All @@ -85,3 +118,120 @@ jobs:
# builds_iac_job: ${{ matrix.name == 'iac-job' }}
# builds_aws_spot_node_terminator: ${{ matrix.name == 'aws-spot-node-terminator' }}
# builds_gcp_spot_node_terminator: ${{ matrix.name == 'gcp-spot-node-terminator' }}

build-k3s-runner-and-binary:
runs-on: ubuntu-latest
env:
k3s_version: "v1.30.5+k3s1"
steps:
- name: Checkout
uses: actions/checkout@v4

- name: setup env (on workflow_call)
shell: bash
if: github.event.name == 'workflow_call'
run: |+
echo "WORKING_DIR=${{ inputs.working_directory }}" | tee -a $GITHUB_ENV | tee -a $GITHUB_OUTPUT
echo "IMAGE_NAME_PREFIX=${{ inputs.image_name_prefix }}" | tee -a $GITHUB_ENV | tee -a $GITHUB_OUTPUT
- name: setup env (not on workflow_call)
shell: bash
run: |+
echo "WORKING_DIR=." | tee -a $GITHUB_ENV | tee -a $GITHUB_OUTPUT
echo "IMAGE_NAME_PREFIX=ghcr.io/${{ github.repository }}" | tee -a $GITHUB_ENV | tee -a $GITHUB_OUTPUT
- name: setup nix (with cachix)
uses: kloudlite/actions/setup-nix-cachix@v1
with:
flake_lock: ${{ env.WORKING_DIR }}/flake.lock
nix_develop_arguments: ${{ env.WORKING_DIR }}/#default

cachix_cache_name: ${{ secrets.CACHIX_CACHE_NAME }}
cachix_auth_token: ${{ secrets.CACHIX_AUTH_TOKEN }}

- name: build k3s runner
shell: bash
working-directory: ${{env.WORKING_DIR}}/cmd/k3s-runner
run: |+
GOARCH=amd64 task build
GOARCH=arm64 task build
- name: download supported k3s binary
shell: bash
working-directory: ${{ env.WORKING_DIR }}/cmd/k3s-runner
run: |+
echo "$PWD"
mkdir -p ./bin
curl -L0 "https://github.com/k3s-io/k3s/releases/download/$k3s_version/k3s" > ./bin/k3s-amd64
cp ./bin/k3s-amd64 ./bin/k3s
curl -L0 "https://github.com/k3s-io/k3s/releases/download/$k3s_version/k3s-arm64" > ./bin/k3s-arm64
- name: Upload Artifact
uses: actions/upload-artifact@v4
with:
name: k3s
path: ${{ env.WORKING_DIR }}/cmd/k3s-runner/bin/*

releasing-binaries:
runs-on: ubuntu-latest
needs: build-k3s-runner-and-binary

permissions:
contents: write
packages: write

steps:
- name: Download all artifacts
uses: actions/download-artifact@v4
with:
path: ${{ github.workspace }}/binaries
name: k3s

- name: flattening all the artifacts
shell: bash
run: |+
ls -R ${{ github.workspace }}/binaries
mkdir -p ${{ github.workspace }}/upload/binaries
shopt -s globstar
file ./** | grep 'executable,' | awk -F: '{print $1}' | xargs -I {} cp {} ${{ github.workspace }}/upload/binaries
shopt -u globstar
- uses: nxtcoder17/actions/generate-image-tag@v1
id: tag_name

- name: running for master branch
if: startsWith(github.ref, 'refs/heads/master')
run: |+
echo "IMAGE_TAG=nightly" | tee -a $GITHUB_ENV | tee -a $GITHUB_OUTPUT
- name: ensure github release exists
shell: bash
env:
GH_TOKEN: ${{ github.token }}
run: |+
set +e
gh release list -R ${{ github.repository }} | awk '{print $3}' | grep -i "$IMAGE_TAG"
exit_code=$?
if [ $exit_code -ne 0 ]; then
gh release create $IMAGE_TAG -R ${{ github.repository }} --generate-notes --prerelease --draft=false
fi
- name: upload to github release
shell: bash
env:
GH_TOKEN: ${{ github.token }}
run: |+
extra_args=""
if [ "$IMAGE_TAG" = "nightly" ]; then
extra_args="--clobber"
fi
gh release upload $IMAGE_TAG -R ${{github.repository}} $extra_args ${{github.workspace}}/upload/binaries/*
- name: mark release as latest
if: startsWith(github.ref, 'refs/tags/')
env:
GH_TOKEN: ${{ github.token }}
shell: bash
run: |+
gh release edit $IMAGE_TAG -R ${{ github.repository }} --latest

0 comments on commit b0b1d6d

Please sign in to comment.