Skip to content

Commit

Permalink
ci: updates Github Action inputs, k3s-etcd dockerfile updates
Browse files Browse the repository at this point in the history
  • Loading branch information
nxtcoder17 committed Sep 30, 2024
1 parent 787656a commit 446d729
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 118 deletions.
79 changes: 23 additions & 56 deletions .github/actions/release/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,13 @@ inputs:
description: 'GitHub Token'
required: true

image_name:
description: 'image name'
default: ''

image_tag:
description: 'image tag, if empty, will be generated from branch or tag'
default: ''

cachix_enabled:
description: "cachix enabled"
default: "false"
image_repository_prefix:
description: 'image repository prefix'
required: true

cachix_cache_name:
description: "cachix cache name"
default: "kloudlite"
default: ""

cachix_auth_token:
description: "cachix auth token"
Expand All @@ -29,7 +21,7 @@ inputs:
description: "dokcer enabled"
default: "false"

git_directory:
working_directory:
description: 'git directory'
default: "."

Expand All @@ -46,78 +38,53 @@ inputs:
description: 'builds nats backup script image'
default: false

outputs:
image_tag:
description: "Generated Image Tag"
value: ${{ steps.generate-image-tag.outputs.IMAGE_TAG }}

runs:
using: 'composite'
steps:
- name: setup ENV Variables
shell: bash
id: env-vars
working-directory: ${{ inputs.git_directory }}
run: |+
echo "PUSH_IMAGE=false" >> $GITHUB_ENV
echo "IMAGE_NAME=${{inputs.image_name}}" >> $GITHUB_ENV
- name: setup nix (with cachix)
if: ${{ inputs.cachix_enabled == 'true' }}
# uses: nxtcoder17/actions/setup-nix-cachix@main
uses: nxtcoder17/actions/.github/actions/setup-nix-cachix@main
uses: kloudlite/actions/setup-nix-cachix@v1
with:
flake_lock: ${{ inputs.git_directory }}/flake.lock
nix_develop_arguments: "${{ inputs.git_directory }}#default"
flake_lock: ${{ inputs.working_directory }}/flake.lock
nix_develop_arguments: "${{ inputs.working_directory }}#default"

cachix_cache_name: ${{ inputs.cachix_cache_name }}
cachix_auth_token: ${{ inputs.cachix_auth_token }}

- name: setup nix cache (with github cache)
if: ${{ inputs.cachix_enabled == 'false' }}
# uses: nxtcoder17/actions/setup-nix-github@main
uses: nxtcoder17/actions/.github/actions/setup-nix-github@main
with:
flake_lock: ${{ inputs.git_directory }}/flake.lock
nix_develop_arguments: "${{ inputs.git_directory }}#default"

- name: setup docker
if: ${{ inputs.docker_enabled == 'true' }}
# uses: nxtcoder17/actions/setup-docker@main
uses: nxtcoder17/actions/.github/actions/setup-docker@main
uses: kloudlite/actions/setup-docker@v1
with:
docker_registry: ghcr.io
docker_username: ${{ github.actor }}
docker_password: ${{ inputs.github_token }}

- name: check if image needs to be pushed
if: github.event_name != 'pull_request'
shell: bash
run: |+
echo "PUSH_IMAGE=true" >> $GITHUB_ENV
- name: Create Image Tag
if: ${{ inputs.image_tag != '' }}
shell: bash
run: |+
echo "IMAGE_TAG=${{ inputs.image_tag }}" >> $GITHUB_ENV
- name: Create Image Tag from branch name / tags
if: ${{ inputs.image_tag == '' }}
# uses: nxtcoder17/actions/generate-image-tag@main
uses: nxtcoder17/actions/.github/actions/generate-image-tag@main
id: generate-image-tag
uses: kloudlite/actions/generate-image-tag@v1

- name: etcd backup script
if: ${{ inputs.etcd == 'true' }}
working-directory: ${{ inputs.git_directory }}/k3s-etcd
working-directory: ${{ inputs.working_directory }}/k3s-etcd
shell: bash
run: |
task k3s-etcd image=$IMAGE_NAME:{{.IMAGE_TAG}}
task k3s-etcd image=${{ inputs.image_repository_prefix }}/etcd:$IMAGE_TAG
- name: mongodb backup script
if: ${{ inputs.mongodb == 'true' }}
working-directory: ${{ inputs.git_directory }}/mongodb
working-directory: ${{ inputs.working_directory }}/mongodb
shell: bash
run: |
task mongodb-backup image=$IMAGE_NAME:$IMAGE_TAG
task mongodb-backup image=${{ inputs.image_repository_prefix }}/mongodb:$IMAGE_TAG
- name: nats backup script
if: ${{ inputs.nats == 'true' }}
working-directory: ${{ inputs.git_directory }}/nats
working-directory: ${{ inputs.working_directory }}/nats
shell: bash
run: |
task nats-backup image=$IMAGE_NAME:$IMAGE_TAG
task nats-backup image=${{ inputs.image_repository_prefix }}/nats:$IMAGE_TAG
36 changes: 8 additions & 28 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ permissions:
jobs:
build-images:
strategy:
fail-fast: false
fail-fast: true
matrix:
image: [etcd, mongodb, nats]
arch: [amd64, arm64]
Expand All @@ -48,41 +48,31 @@ jobs:

runs-on: ${{ matrix.runs-on }}
name: ${{ matrix.image }}-${{ matrix.arch }}
outputs:
image_tag: ${{ steps.build-action.outputs.image_tag }}
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Create Image Tag
if: ${{ inputs.image_tag != '' }}
shell: bash
run: |+
echo "IMAGE_TAG=${{ inputs.image_tag }}" >> $GITHUB_ENV
- name: Create Image Tag from branch name / tags
if: ${{ inputs.image_tag == '' }}
# uses: nxtcoder17/actions/generate-image-tag@main
uses: nxtcoder17/actions/.github/actions/generate-image-tag@main

- name: build container images
id: build-action
uses: ./.github/actions/release/
with:
image_name: ghcr.io/${{ github.repository }}/${{ matrix.image }}
# image_tag: ${{ inputs.image_tag }}
image_tag: ${{ env.IMAGE_TAG }}-${{ matrix.arch }}

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

docker_enabled: true

github_token: ${{ secrets.GITHUB_TOKEN }}
git_directory: "."
working_directory: "."

etcd: ${{ matrix.image == 'etcd' }}
mongodb: ${{ matrix.image == 'mongodb' }}
nats: ${{ matrix.image == 'nats' }}


multiarch-images:
strategy:
fail-fast: false
Expand All @@ -101,25 +91,15 @@ jobs:

steps:
- name: setup docker
uses: nxtcoder17/actions/.github/actions/setup-docker@main
uses: kloudlite/actions/setup-docker@v1
with:
docker_username: ${{ github.actor }}
docker_password: ${{ secrets.GITHUB_TOKEN }}

- name: Create Image Tag
if: ${{ inputs.image_tag != '' }}
shell: bash
run: |+
echo "IMAGE_TAG=${{ inputs.image_tag }}" >> $GITHUB_ENV
- name: Create Image Tag from branch name / tags
if: ${{ inputs.image_tag == '' }}
# uses: nxtcoder17/actions/generate-image-tag@main
uses: nxtcoder17/actions/.github/actions/generate-image-tag@main

- name: multiarch manifest build
shell: bash
run: |
IMAGE_TAG="${{ needs.build-images.outputs.image_tag }}"
docker manifest create ${image_name}:${IMAGE_TAG} ${image_name}:${IMAGE_TAG}-amd64 ${image_name}:${IMAGE_TAG}-arm64
docker manifest annotate ${image_name}:${IMAGE_TAG} ${image_name}:${IMAGE_TAG}-amd64 --os linux --arch amd64
Expand Down
1 change: 1 addition & 0 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
# installPhase = "cp -r $src $out";
installPhase = ''
mkdir -p $out
ls -al $src
cp -r $src/bin $out
if [ -d "$src/lib" ]; then
cp -r $src/lib $out
Expand Down
2 changes: 1 addition & 1 deletion k3s-etcd/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@ COPY --chown=1001:1001 --chmod=700 ./backup.sh ./backup.sh

RUN sed -i "s|#built at#|Built at $(date +'+%r (%Z) on %b %d, %Y')|" ./backup.sh

USER 1001:1001
# USER 1001:1001
ENTRYPOINT ["./backup.sh"]
45 changes: 12 additions & 33 deletions k3s-etcd/backup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,39 +5,18 @@ set -o pipefail
set -o nounset

cat <<EOF
↙↙
↘↘↘↘
↘↘↘↘↘↘↘↘
↘↘↘↘↘↘↘↘↘↘↘
↘↘↘↘↘↘↘↘↘↘↘↘
↘↘↘↘↘↘↘↘↘↘↘↘
↖↘↘↘↘↘↘↘↘↘↘↘
↘↘↘↘↘↘↘↘↘↘↘ ↘↘↘
↘↘↘↘↘↘↘↘↘↘↘ ↘↘↘↘↘↘↘
↘↘↘↘↘↘↘↘↘↘↘↓ ↘↘↘↘↘↘↘↘↘↘↘
↘↘↘↘↘↘↘↘↘↘↘↘ ↘↘↘↘↘↘↘↘↘↘↘↘↘↘↙
↓↘↘↘↘↘↘↘↘↘↘↘ ↓↘↘↘↘↘↘↘↘↘↘↘↘↘↘↘↘↘
↘↘↘↘↘↘↘↘↘↘↘ ↘↘↘↘↘↘↘↘↘↘↘↘↘↘↘↘↘↘↘↘↘
↘↘↘↘↘↘↘↘↘↘↘ ↘↘↘↘↘↘↘↘↘↘↘↘↘↘↘↘↘↘↘↘↘↘↘↘↘
↘↘↘↘↘↘↘↘↘↘↘← ↘↘↘↘↘↘↘↘↘↘↘↘↘↘↘↘↘↘↘↘↘↘↘↘↘↘↘↘↘
↘↘↘↘↘↘↘↘↘↘↘↘ ↘↘↘↘↘↘↘↘↘↘↘↘↘↘↘↘↘↘↘↘↘↘↘↘↘↘↘↘↘↘↘↘↓ EtcD Backup
↘↘↘↘↘↘↘↘↘↘↘ ↘↘↘↘↘↘↘↘↘↘↘↘↘↘↘↘↘↘↘↘↘↘↘↘↘↘↘↘↘↘↘↘↘↘↘ #built at#
↘↘↘↘↘↘↘↘↘↘↘↘ ↘↘↘↘↘↘↘↘↘↘↘↘↘↘↘↘↘↘↘↘↘↘↘↘↘↘↘↘↘↘↘↘↖
↘↘↘↘↘↘↘↘↘↘↘↘ ↘↘↘↘↘↘↘↘↘↘↘↘↘↘↘↘↘↘↘↘↘↘↘↘↘↘↘↘↘
↘↘↘↘↘↘↘↘↘↘↘↙ ↘↘↘↘↘↘↘↘↘↘↘↘↘↘↘↘↘↘↘↘↘↘↘↘↘
↘↘↘↘↘↘↘↘↘↘↘↖ ↘↘↘↘↘↘↘↘↘↘↘↘↘↘↘↘↘↘↘↘↘
↙↘↘↘↘↘↘↘↘↘↘↘ ↖↘↘↘↘↘↘↘↘↘↘↘↘↘↘↘↘↘
↘↘↘↘↘↘↘↘↘↘↘↘ ↙↘↘↘↘↘↘↘↘↘↘↘↘↘
↘↘↘↘↘↘↘↘↘↘↘↘ ↘↘↘↘↘↘↘↘↘↘↙
↘↘↘↘↘↘↘↘↘↘↘↓ ↘↘↘↘↘↘↘
↘↘↘↘↘↘↘↘↘↘↘↙ ↘↘↘
↘↘↘↘↘↘↘↘↘↘↘
↘↘↘↘↘↘↘↘↘↘↘↘
↘↘↘↘↘↘↘↘↘↘↘↘
↘↘↘↘↘↘↘↘↘↘↘↙
↘↘↘↘↘↘↘↘
↘↘↘↘
↙←
**
****
**** *
**** ***** ▗▖ ▗▖▗▖ ▗▄▖ ▗▖ ▗▖▗▄▄▄ ▗▖ ▗▄▄▄▖▗▄▄▄▖▗▄▄▄▖
**** ********* ▐▌▗▞▘▐▌ ▐▌ ▐▌▐▌ ▐▌▐▌ █▐▌ █ █ ▐▌
**** ************ ▐▛▚▖ ▐▌ ▐▌ ▐▌▐▌ ▐▌▐▌ █▐▌ █ █ ▐▛▀▀▘
**** ********* ▐▌ ▐▌▐▙▄▄▖▝▚▄▞▘▝▚▄▞▘▐▙▄▄▀▐▙▄▄▖▗▄█▄▖ █ ▐▙▄▄▖
**** *****
**** * EtcD backup
**** #built at#
**
EOF

echo "${ENCRYPTION_PASSWORD?Error: env-var is not set}" >/dev/null
Expand Down

0 comments on commit 446d729

Please sign in to comment.