Skip to content

Commit

Permalink
backend/enh/docker-push-for-ci
Browse files Browse the repository at this point in the history
  • Loading branch information
vsaimanohar committed Sep 20, 2024
1 parent 1afc3eb commit ce33c9d
Showing 1 changed file with 43 additions and 9 deletions.
52 changes: 43 additions & 9 deletions .github/workflows/nix.yml
Original file line number Diff line number Diff line change
@@ -1,23 +1,24 @@
name: CI

on:
# Triggers the workflow on push or pull request events but only for the "main" branch
push:
branches: ["main"]
branches:
- main
- 'backend/enh/docker-push-for-ci' # This will trigger the workflow on any branch starting with 'test/'
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

build-and-push:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Setup Nix
uses: cachix/install-nix-action@v22
with:
nix_path: nixpkgs=channel:nixos-unstable

- uses: cachix/cachix-action@v15
with:
name: nammayatri
Expand All @@ -26,3 +27,36 @@ jobs:

- name: Build all flake outputs
run: om ci

- name: Build and push Docker image
env:
GITHUB_USERNAME: ${{ github.actor }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
# Build and load Docker image
IMAGE_PATH=$(nix build '.#dockerImage' --print-out-paths --no-update-lock-file)
docker load -i "$IMAGE_PATH"
# Get the image name and tag from Nix configuration
IMAGE_NAME="ghcr.io/nammayatri/beckn-gateway"
IMAGE_TAG=$(nix eval --raw '.#dockerImage.imageTag')
# Add branch name to tag if not on main branch
if [[ "${{ github.ref }}" != "refs/heads/main" ]]; then
BRANCH_NAME=$(echo ${{ github.ref }} | sed 's/refs\/heads\///')
IMAGE_TAG="${IMAGE_TAG}-${BRANCH_NAME}"
fi
FULL_IMAGE_NAME="${IMAGE_NAME}:${IMAGE_TAG}"
# Login to GitHub Container Registry
echo "$GITHUB_TOKEN" | docker login ghcr.io -u "$GITHUB_USERNAME" --password-stdin
# Push the image
docker push "$FULL_IMAGE_NAME"
# Logout
docker logout ghcr.io
# Output the pushed image name for reference
echo "Pushed image: $FULL_IMAGE_NAME"

0 comments on commit ce33c9d

Please sign in to comment.