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