From f2ce7efbb841933888df06aac660d9052374e6aa Mon Sep 17 00:00:00 2001 From: HaimKortovich Date: Tue, 31 Mar 2026 17:11:46 -0500 Subject: [PATCH] try make it work --- .gitea/workflows/build-and-publish.yaml | 106 ++++++++++++------------ 1 file changed, 54 insertions(+), 52 deletions(-) diff --git a/.gitea/workflows/build-and-publish.yaml b/.gitea/workflows/build-and-publish.yaml index 247f496..9e4dc41 100644 --- a/.gitea/workflows/build-and-publish.yaml +++ b/.gitea/workflows/build-and-publish.yaml @@ -1,70 +1,72 @@ -name: Build and Publish - +# .gitea/workflows/build.yaml +name: Build and Deploy on: push: branches: - main env: - REGISTRY: ${{ format('{0}', replace(replace(github.server_url, 'https://', ''), 'http://', '')) }} - # Dynamically extracts just the repository name (e.g., 'my-repo' from 'owner/my-repo') - CHART_NAME: ${{ github.event.repository.name }} + REGISTRY: ${{ github.server_url }} IMAGE_NAME: ${{ github.event.repository.name }} + CHART_NAME: ${{ github.event.repository.name }} jobs: - build-release: - runs-on: nix + build: + runs-on: ubuntu-latest + container: + image: nixos/nix:latest + options: --privileged steps: - - name: Checkout via Native Git - env: - GITEA_URL: ${{ github.server_url }} - TOKEN: ${{ secrets.GITHUB_TOKEN }} - REPO: ${{ github.repository }} - SHA: ${{ github.sha }} + - name: Checkout run: | - nix shell nixpkgs#gnused - STRIPPED_URL=$(echo $GITEA_URL | sed -e 's|^https://||' -e 's|^http://||') - 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 + nix-shell -p git --run "git clone https://token:${{ secrets.GITHUB_TOKEN }}@$(echo ${{ github.server_url }} | sed 's|https://||')/${{ github.repository }}.git ." + nix-shell -p git --run "git checkout ${{ github.sha }}" + + - name: Setup Nix run: | - nix build ./build/#dockerImage - docker load -i result - - - name: Log in to Gitea Container Registry - uses: docker/login-action@v3 - with: - registry: ${{ env.REGISTRY }} - username: ${{ github.actor }} - password: ${{ secrets.GITHUB_TOKEN }} - - - name: Tag and Push Docker Image + echo "experimental-features = nix-command flakes" >> /etc/nix/nix.conf + + - name: Build with Nix + run: | + nix build .#dockerImage --print-build-logs + nix build .#helmChart --print-build-logs + + - name: Setup Docker + run: | + nix-shell -p docker --run "dockerd &" + sleep 5 + + - name: Load and Push Docker Image run: | VERSION=${{ github.run_number }} - TARGET_IMAGE=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} - nix shell nixpkgs#docker - # 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 - run: | - VERSION=${{ github.run_number }} - - nix shell nixpkgs#kubernetes-helm - # Packages the chart using the dynamically injected repo name - helm package ops/chart --version $VERSION --app-version $VERSION - - - name: Push Helm Chart to Gitea Registry + REGISTRY_HOST=$(echo "${{ env.REGISTRY }}" | sed -e 's|^https://||' -e 's|^http://||') + TARGET_IMAGE=${REGISTRY_HOST}/${{ github.repository_owner }}/${{ env.IMAGE_NAME }} + + 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: | 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 - curl --user "${{ github.actor }}:${{ secrets.GITHUB_TOKEN }}" \ - -X POST \ - --upload-file ./$CHART_FILE \ - "${{ github.server_url }}/api/packages/${{ github.repository_owner }}/helm/api/charts" + nix-shell -p curl --run " + curl -f --user '${{ github.actor }}:${{ secrets.GITHUB_TOKEN }}' \ + -X POST \ + --upload-file ./${CHART_FILE} \ + '${{ github.server_url }}/api/packages/${{ github.repository_owner }}/helm/api/charts' + "