This commit is contained in:
@@ -1,70 +1,72 @@
|
|||||||
name: Build and Publish
|
# .gitea/workflows/build.yaml
|
||||||
|
name: Build and Deploy
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
branches:
|
branches:
|
||||||
- main
|
- main
|
||||||
|
|
||||||
env:
|
env:
|
||||||
REGISTRY: ${{ format('{0}', replace(replace(github.server_url, 'https://', ''), 'http://', '')) }}
|
REGISTRY: ${{ github.server_url }}
|
||||||
# Dynamically extracts just the repository name (e.g., 'my-repo' from 'owner/my-repo')
|
|
||||||
CHART_NAME: ${{ github.event.repository.name }}
|
|
||||||
IMAGE_NAME: ${{ github.event.repository.name }}
|
IMAGE_NAME: ${{ github.event.repository.name }}
|
||||||
|
CHART_NAME: ${{ github.event.repository.name }}
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
build-release:
|
build:
|
||||||
runs-on: nix
|
runs-on: ubuntu-latest
|
||||||
|
container:
|
||||||
|
image: nixos/nix:latest
|
||||||
|
options: --privileged
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout via Native Git
|
- name: Checkout
|
||||||
env:
|
|
||||||
GITEA_URL: ${{ github.server_url }}
|
|
||||||
TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
||||||
REPO: ${{ github.repository }}
|
|
||||||
SHA: ${{ github.sha }}
|
|
||||||
run: |
|
run: |
|
||||||
nix shell nixpkgs#gnused
|
nix-shell -p git --run "git clone https://token:${{ secrets.GITHUB_TOKEN }}@$(echo ${{ github.server_url }} | sed 's|https://||')/${{ github.repository }}.git ."
|
||||||
STRIPPED_URL=$(echo $GITEA_URL | sed -e 's|^https://||' -e 's|^http://||')
|
nix-shell -p git --run "git checkout ${{ github.sha }}"
|
||||||
echo "Cloning from: $STRIPPED_URL"
|
|
||||||
# Perform the clone
|
|
||||||
git clone --depth 1 "https://token:${TOKEN}@${STRIPPED_URL}/${REPO}.git" .
|
|
||||||
# Checkout the specific commit
|
|
||||||
git checkout $SHA
|
|
||||||
|
|
||||||
- name: Build Docker Image via Nix Flake
|
- name: Setup Nix
|
||||||
run: |
|
run: |
|
||||||
nix build ./build/#dockerImage
|
echo "experimental-features = nix-command flakes" >> /etc/nix/nix.conf
|
||||||
docker load -i result
|
|
||||||
|
|
||||||
- name: Log in to Gitea Container Registry
|
- name: Build with Nix
|
||||||
uses: docker/login-action@v3
|
run: |
|
||||||
with:
|
nix build .#dockerImage --print-build-logs
|
||||||
registry: ${{ env.REGISTRY }}
|
nix build .#helmChart --print-build-logs
|
||||||
username: ${{ github.actor }}
|
|
||||||
password: ${{ secrets.GITHUB_TOKEN }}
|
|
||||||
|
|
||||||
- name: Tag and Push Docker Image
|
- name: Setup Docker
|
||||||
|
run: |
|
||||||
|
nix-shell -p docker --run "dockerd &"
|
||||||
|
sleep 5
|
||||||
|
|
||||||
|
- name: Load and Push Docker Image
|
||||||
run: |
|
run: |
|
||||||
VERSION=${{ github.run_number }}
|
VERSION=${{ github.run_number }}
|
||||||
TARGET_IMAGE=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
|
REGISTRY_HOST=$(echo "${{ env.REGISTRY }}" | sed -e 's|^https://||' -e 's|^http://||')
|
||||||
nix shell nixpkgs#docker
|
TARGET_IMAGE=${REGISTRY_HOST}/${{ github.repository_owner }}/${{ env.IMAGE_NAME }}
|
||||||
# Replace 'nix-built-image:latest' with your flake's internal image name
|
|
||||||
docker tag nix-built-image:latest $TARGET_IMAGE:$VERSION
|
|
||||||
docker push $TARGET_IMAGE:$VERSION
|
|
||||||
|
|
||||||
- name: Package Helm Chart
|
nix-shell -p docker --run "
|
||||||
|
docker load < result
|
||||||
|
SOURCE_IMAGE=\$(docker images --format '{{.Repository}}:{{.Tag}}' | head -n 1)
|
||||||
|
|
||||||
|
echo '${{ secrets.GITHUB_TOKEN }}' | docker login ${REGISTRY_HOST} -u ${{ github.actor }} --password-stdin
|
||||||
|
|
||||||
|
docker tag \$SOURCE_IMAGE ${TARGET_IMAGE}:${VERSION}
|
||||||
|
docker tag \$SOURCE_IMAGE ${TARGET_IMAGE}:latest
|
||||||
|
docker push ${TARGET_IMAGE}:${VERSION}
|
||||||
|
docker push ${TARGET_IMAGE}:latest
|
||||||
|
"
|
||||||
|
|
||||||
|
- name: Package and Push Helm Chart
|
||||||
run: |
|
run: |
|
||||||
VERSION=${{ github.run_number }}
|
VERSION=${{ github.run_number }}
|
||||||
|
|
||||||
nix shell nixpkgs#kubernetes-helm
|
nix-shell -p kubernetes-helm --run "
|
||||||
# Packages the chart using the dynamically injected repo name
|
helm package result/chart --version ${VERSION} --app-version ${VERSION}
|
||||||
helm package ops/chart --version $VERSION --app-version $VERSION
|
"
|
||||||
|
|
||||||
- name: Push Helm Chart to Gitea Registry
|
|
||||||
run: |
|
|
||||||
VERSION=${{ github.run_number }}
|
|
||||||
CHART_FILE=${{ env.CHART_NAME }}-${VERSION}.tgz
|
CHART_FILE=${{ env.CHART_NAME }}-${VERSION}.tgz
|
||||||
|
|
||||||
curl --user "${{ github.actor }}:${{ secrets.GITHUB_TOKEN }}" \
|
nix-shell -p curl --run "
|
||||||
-X POST \
|
curl -f --user '${{ github.actor }}:${{ secrets.GITHUB_TOKEN }}' \
|
||||||
--upload-file ./$CHART_FILE \
|
-X POST \
|
||||||
"${{ github.server_url }}/api/packages/${{ github.repository_owner }}/helm/api/charts"
|
--upload-file ./${CHART_FILE} \
|
||||||
|
'${{ github.server_url }}/api/packages/${{ github.repository_owner }}/helm/api/charts'
|
||||||
|
"
|
||||||
|
|||||||
Reference in New Issue
Block a user