Skip to content

Commit

Permalink
Added ability to push to GHCR
Browse files Browse the repository at this point in the history
  • Loading branch information
jaydrogers committed Nov 29, 2023
1 parent 3922740 commit 47fed8d
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 35 deletions.
12 changes: 7 additions & 5 deletions .github/workflows/service_docker-build-and-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@ on:
default-image-variation:
type: string
default: 'cli'
docker-repo-name:
type: string
default: 'serversideup/php'

jobs:
setup-matrix:
Expand Down Expand Up @@ -79,6 +76,13 @@ jobs:
username: ${{ secrets.DOCKER_HUB_USERNAME }}
password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }}

- name: Login to GitHub Container Registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Set up QEMU
uses: docker/setup-qemu-action@v2

Expand All @@ -90,13 +94,11 @@ jobs:
chmod +x ./scripts/assemble-docker-tags.sh
./scripts/assemble-docker-tags.sh
env:
DOCKER_REPOSITORY: "${{ inputs.docker-repo-name }}"
PHP_VERSIONS_FILE: "${{ inputs.php-versions-file }}"
DEFAULT_IMAGE_VARIATION: ${{ inputs.default-image-variation }}
PHP_BUILD_VERSION: ${{ matrix.patch_version }}
PHP_BUILD_VARIATION: ${{ matrix.php_variation }}
PHP_BUILD_BASE_OS: ${{ matrix.base_os }}
CHECKOUT_TYPE: ${{ inputs.checkout-type }}
DOCKER_TAG_PREFIX: ${{ inputs.tag-prefix }}

- name: Set REPOSITORY_BUILD_VERSION
Expand Down
59 changes: 29 additions & 30 deletions scripts/assemble-docker-tags.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ set -oe pipefail
# Environment Settings

# Required variables to set
CHECKOUT_TYPE="${CHECKOUT_TYPE:-"branch"}"
DEFAULT_IMAGE_VARIATION="${DEFAULT_IMAGE_VARIATION:-"cli"}"
DOCKER_REPOSITORY="${DOCKER_REPOSITORY:-"serversideup/php"}"
DOCKER_TAG_PREFIX="${DOCKER_TAG_PREFIX:-"edge-"}"
PHP_VERSIONS_FILE="${PHP_VERSIONS_FILE:-"scripts/conf/php-versions.yml"}"

DOCKER_REGISTRY_IMAGE_NAMES=("docker.io/serversideup/php" "ghcr.io/serversideup/php")
DOCKER_TAG_PREFIX="${DOCKER_TAG_PREFIX:-"edge-"}"

##########################
# Functions

Expand Down Expand Up @@ -73,18 +73,21 @@ check_vars() {

add_docker_tag() {
docker_tag_suffix=$1
tag_name="$DOCKER_REPOSITORY:$DOCKER_TAG_PREFIX$docker_tag_suffix"

if [[ -z "$DOCKER_TAGS" ]]; then
# Do not prefix with comma
DOCKER_TAGS+="$tag_name"
else
# Add a comma to separate the tags
DOCKER_TAGS+=",$tag_name"
fi

# Trim commas for a better output
echo_color_message blue "🐳 Set tag: ${tag_name//,} "
for image_name in "${DOCKER_REGISTRY_IMAGE_NAMES[@]}"; do
tag_name="$image_name:$DOCKER_TAG_PREFIX$docker_tag_suffix"

if [[ -z "$DOCKER_TAGS" ]]; then
# Do not prefix with comma
DOCKER_TAGS+="$tag_name"
else
# Add a comma to separate the tags
DOCKER_TAGS+=",$tag_name"
fi

# Trim commas for a better output
echo_color_message blue "🐳 Set tag: ${tag_name//,} "
done
}

function is_latest_stable_patch() {
Expand All @@ -103,8 +106,8 @@ function is_default_base_os() {
[[ "$build_base_os" == "$default_base_os_within_build_minor" ]]
}

function is_checkout_type_of_latest_stable() {
[[ "$CHECKOUT_TYPE" == "latest-stable" ]]
function is_stable() {
[[ -z "$DOCKER_TAG_PREFIX" ]]
}

function is_default_variation() {
Expand All @@ -115,22 +118,21 @@ help_menu() {
echo "Usage: $0 [--variation <variation> --os <os> --patch-version <patch-version> --latest]"
echo
echo "This script dives deep into the advanced logic of assembling Docker tags for GitHub Actions."
echo "If \$CI is \"true\", it outputs the tags to GITHUB_ENV for use in subsequent steps."
echo "If \$CI is 'true', it outputs the tags to GITHUB_ENV for use in subsequent steps."
echo "You can run this locally for debugging. The script has beautiful output and can help debug"
echo "any advanced logic issues."
echo
echo "Options:"
echo " --variation <variation> Set the PHP variation (e.g., apache, fpm)"
echo " --os <os> Set the base OS (e.g., bullseye, bookworm, alpine)"
echo " --variation <variation> Set the PHP variation (e.g., apache, fpm)"
echo " --os <os> Set the base OS (e.g., bullseye, bookworm, alpine)"
echo " --patch-version <patch-version> Set the PHP patch version (e.g., 7.4.10)"
echo " --latest Use 'latest-stable' as the checkout type"
echo " --latest Set DOCKER_TAG_PREFIX to an empty string (making this a stable release)"
echo
echo "Environment Variables (Defaults):"
echo " CHECKOUT_TYPE The checkout type (default: branch)"
echo " DEFAULT_IMAGE_VARIATION The default PHP image variation (default: cli)"
echo " DOCKER_REPOSITORY The Docker repository (default: serversideup/php)"
echo " DOCKER_TAG_PREFIX The Docker tag prefix (default: edge-)"
echo " PHP_VERSIONS_FILE Path to PHP versions file (default: scripts/conf/php-versions.yml)"
echo " DEFAULT_IMAGE_VARIATION The default PHP image variation (default: cli)"
echo " DOCKER_REGISTRY_IMAGE_NAMES Names of images to tag (default: 'docker.io/serversideup/php' 'ghcr.io/serversideup/php')"
echo " DOCKER_TAG_PREFIX The Docker tag prefix (default: edge-)"
echo " PHP_VERSIONS_FILE Path to PHP versions file (default: scripts/conf/php-versions.yml)"
}

##########################
Expand All @@ -153,7 +155,6 @@ while [[ $# -gt 0 ]]; do
;;
--latest)
DOCKER_TAG_PREFIX=""
CHECKOUT_TYPE="latest-stable"
shift 1
;;
*)
Expand All @@ -170,9 +171,7 @@ check_vars \
PHP_BUILD_VARIATION \
PHP_BUILD_VERSION \
PHP_BUILD_BASE_OS \
DOCKER_REPOSITORY \
PHP_VERSIONS_FILE \
CHECKOUT_TYPE
PHP_VERSIONS_FILE

if [[ ! -f $PHP_VERSIONS_FILE ]]; then
echo_color_message red "🚨 PHP Versions file not found at $PHP_VERSIONS_FILE"
Expand Down Expand Up @@ -258,7 +257,7 @@ if is_latest_stable_patch; then
if is_latest_major && is_default_variation; then
add_docker_tag "$build_base_os"

if is_default_base_os && is_checkout_type_of_latest_stable && is_default_variation; then
if is_default_base_os && is_stable && is_default_variation; then
add_docker_tag "latest"
fi
fi
Expand Down

0 comments on commit 47fed8d

Please sign in to comment.