diff --git a/.gitea/workflows/build-and-publish.yaml b/.gitea/workflows/build-and-publish.yaml index 9e4dc41..f146e90 100644 --- a/.gitea/workflows/build-and-publish.yaml +++ b/.gitea/workflows/build-and-publish.yaml @@ -1,72 +1,69 @@ -# .gitea/workflows/build.yaml -name: Build and Deploy +name: Build and Publish + on: push: branches: - main env: - REGISTRY: ${{ github.server_url }} - IMAGE_NAME: ${{ github.event.repository.name }} + 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 }} + IMAGE_NAME: ${{ github.event.repository.name }} jobs: - build: - runs-on: ubuntu-latest - container: - image: nixos/nix:latest - options: --privileged + build-release: + runs-on: nix 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: | - 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 + STRIPPED_URL=$(nix shell nixpkgs#gnused 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 run: | - 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 + 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 run: | VERSION=${{ github.run_number }} - 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 + 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 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 - 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' - " + curl --user "${{ github.actor }}:${{ secrets.GITHUB_TOKEN }}" \ + -X POST \ + --upload-file ./$CHART_FILE \ + "${{ github.server_url }}/api/packages/${{ github.repository_owner }}/helm/api/charts"