hardcode commit hash and version #12
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: "Docker Image Build and Publish (Non-Main)" | |
on: | |
push: | |
branches-ignore: | |
- "main" | |
env: | |
REGISTRY: ghcr.io | |
IMAGE_NAME: ${{ github.repository }} | |
jobs: | |
build: | |
name: Build and Push Docker Image | |
runs-on: ubuntu-latest | |
permissions: | |
contents: read | |
packages: write | |
id-token: write | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v3 | |
- name: Setup Docker buildx | |
uses: sigstore/cosign-installer@v3.1.1 | |
- name: Check install! | |
run: cosign version | |
- name: Login to GitHub Container Registry | |
if: github.event_name != 'pull_request' | |
uses: docker/login-action@v1 | |
with: | |
registry: ${{ env.REGISTRY }} | |
username: ${{ secrets.GHCR_USERNAME }} | |
password: ${{ secrets.GHCR_TOKEN }} | |
- name: Downcase Repository Name | |
run: echo "REPO=${GITHUB_REPOSITORY,,}" >>${GITHUB_ENV} | |
- name: Build and Push Docker Image | |
run: | | |
export CURRENT_BRANCH=${GITHUB_REF#refs/heads/} | |
export TAG=$CURRENT_BRANCH | |
export GITHUB_REF_IMAGE=${{ env.REGISTRY }}/$REPO:$GITHUB_SHA | |
export GITHUB_BRANCH_IMAGE=${{ env.REGISTRY }}/$REPO:$TAG | |
docker build -t $GITHUB_REF_IMAGE -t $GITHUB_BRANCH_IMAGE . | |
echo "Pushing Image to GitHub Container Registry" | |
docker push $GITHUB_REF_IMAGE | |
docker push $GITHUB_BRANCH_IMAGE |