Skip to content

Commit

Permalink
add ghcr publish (#2)
Browse files Browse the repository at this point in the history
publish to ghcr
  • Loading branch information
dovholuknf authored Mar 24, 2024
1 parent b9fc89c commit 308355d
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 0 deletions.
40 changes: 40 additions & 0 deletions .github/workflows/publish-docker.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: Publish Docker Images

on:
push:
pull_request:
types: [labeled, closed]

jobs:
publish:
runs-on: ubuntu-latest
#if: github.event.pull_request.merged == true

steps:
- name: Checkout code
uses: actions/checkout@v2 # This step checks out your repository

- name: echo a thing or two
run: cat $GITHUB_EVENT_PATH
#echo $(jq -r '.label.name' $GITHUB_EVENT_PATH)

- name: Check if pushDocker.sh script exists
run: |
if [ -e "$GITHUB_WORKSPACE/pushDocker.sh" ]; then
echo "pushDocker.sh script exists"
else
echo "pushDocker.sh script does not exist"
fi
- name: Check if PR is labeled as "publish docker"
id: check_label
run: echo "publish=$(jq -r '.label.name' $GITHUB_EVENT_PATH | grep -c '^publish docker$')" >> $GITHUB_ENV

- name: Log in to GitHub Container Registry
run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin


- name: Execute Script
if: ${{ env.publish != '1' }}
run: $GITHUB_WORKSPACE/pushDocker.sh

1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
health.json
*.jwt
.idea
32 changes: 32 additions & 0 deletions pushDocker.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/bin/bash

# Retrieve version from the file or environment variable
HEALTHCHECK_PROXY_VERSION=$(cat version 2>/dev/null || echo "${HEALTHCHECK_PROXY_VERSION}")

# Check if version is set
if [ -z "${HEALTHCHECK_PROXY_VERSION}" ]; then
echo "HEALTHCHECK_PROXY_VERSION is not set and auto-detection failed."
exit 1
fi

echo "Building healthcheck-proxy version ${HEALTHCHECK_PROXY_VERSION} for amd64/arm64"

# Create and use buildx builder
docker buildx create --use --name=healthcheck-proxy

# Authenticate with GitHub Container Registry using the token from GitHub Secrets
echo "${GHCR_TOKEN}" | docker login ghcr.io -u "${GITHUB_ACTOR}" --password-stdin

# Build and push the Docker image
docker buildx build --platform linux/amd64,linux/arm64 . \
--tag "ghcr.io/${GITHUB_REPOSITORY}/healthcheck-proxy:${HEALTHCHECK_PROXY_VERSION}" \
--tag "ghcr.io/${GITHUB_REPOSITORY}/healthcheck-proxy:latest" \
--push

# Check if build and push were successful
if [ $? -eq 0 ]; then
echo "Build and push completed successfully."
else
echo "Build and push failed."
exit 1
fi
1 change: 1 addition & 0 deletions version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0.0.1

0 comments on commit 308355d

Please sign in to comment.