backend/enh/docker-push-for-ci #16
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: CI | |
on: | |
# Triggers the workflow on push events for all branches | |
push: | |
branches: ["*"] | |
# Triggers the workflow on pull request events for all branches | |
pull_request: | |
branches: ["*"] | |
# 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 | |
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: 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" |