From 5ef3d86fd253c9c6b89edceebdf5b04b5b212e0c Mon Sep 17 00:00:00 2001 From: "saimanohar.veeravajhula" Date: Fri, 20 Sep 2024 16:45:35 +0530 Subject: [PATCH] backend/enh/docker-push-for-ci --- .github/workflows/nix.yml | 40 +++++++++++++++++++++++++------ Jenkinsfile | 50 --------------------------------------- 2 files changed, 33 insertions(+), 57 deletions(-) delete mode 100644 Jenkinsfile diff --git a/.github/workflows/nix.yml b/.github/workflows/nix.yml index 2c185c3..25f53ca 100644 --- a/.github/workflows/nix.yml +++ b/.github/workflows/nix.yml @@ -1,28 +1,54 @@ name: CI on: - # Triggers the workflow on push or pull request events but only for the "main" branch push: branches: ["main"] pull_request: branches: ["main"] - - # Allows you to run this workflow manually from the Actions tab workflow_dispatch: -# A workflow run is made up of one or more jobs that can run sequentially or in parallel jobs: build: runs-on: x86_64-linux - + outputs: + image_name: ${{ steps.image_info.outputs.image_name }} steps: - uses: actions/checkout@v4 - - uses: cachix/cachix-action@v15 with: name: nammayatri authToken: "${{ secrets.CACHIX_AUTH_TOKEN }}" - skipPush: true - name: Build all flake outputs run: om ci + + - name: Docker tasks + if: github.ref == 'refs/heads/main' + run: | + nix build .#dockerImage -o docker-image.tgz + echo "image_name=$(nix eval --raw .#dockerImage.imageName):$(nix eval --raw .#dockerImage.imageTag)" >> $GITHUB_OUTPUT + + - name: Upload Docker image tarball + if: github.ref == 'refs/heads/main' + uses: actions/upload-artifact@v4 + with: + name: docker-image + path: docker-image.tgz + + push-docker: + needs: build + runs-on: ubuntu-latest + if: github.ref == 'refs/heads/main' + steps: + - name: Download Docker image tarball + uses: actions/download-artifact@v4 + with: + name: docker-image + - name: Load and push Docker image + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + echo "$GITHUB_TOKEN" | docker login ghcr.io -u "${{ github.actor }}" --password-stdin + docker load < docker-image.tgz + docker push ${{ needs.build.outputs.image_name }} + docker logout ghcr.io diff --git a/Jenkinsfile b/Jenkinsfile deleted file mode 100644 index 95d62c6..0000000 --- a/Jenkinsfile +++ /dev/null @@ -1,50 +0,0 @@ -pipeline { - agent none - stages { - stage ('Matrix') { - matrix { - agent { - label "${SYSTEM}" - } - axes { - axis { - name 'SYSTEM' - values 'x86_64-linux', 'aarch64-darwin' - } - } - stages { - stage ('Cachix setup') { - steps { - cachixUse "nammayatri" - } - } - stage ('Nix Build All') { - steps { - nixCI system: env.SYSTEM - } - } - stage ('Docker image') { - when { - allOf { - branch 'main'; expression { 'x86_64-linux' == env.SYSTEM } - } - } - steps { - dockerPush "dockerImage", "ghcr.io" - } - } - stage ('Cachix push') { - when { - anyOf { - branch 'main'; branch 'prodHotPush' - } - } - steps { - cachixPush "nammayatri" - } - } - } - } - } - } -}