Feat docker prebuilt (@master) (#175)

This commit is contained in:
Simon Lecoq
2021-03-07 13:07:06 +01:00
committed by GitHub
parent a2175ec0c7
commit 469b076dcc
3 changed files with 33 additions and 31 deletions

View File

@@ -182,11 +182,12 @@ inputs:
description: Use mocked data instead of live APIs description: Use mocked data instead of live APIs
default: no default: no
# Use a pre-built image from GitHub registry (experimental) # Use a pre-built image from GitHub registry when using unreleased versions of "lowlighter/metrics"
# This option has no effect on forks (images will always be rebuilt from Dockerfile)
# See https://github.com/users/lowlighter/packages/container/package/metrics for more information # See https://github.com/users/lowlighter/packages/container/package/metrics for more information
use_prebuilt_image: use_prebuilt_image:
description: Use pre-built image from GitHub registry description: Use pre-built image from GitHub registry
default: "" default: yes
# ==================================================================================== # ====================================================================================
# 📰 Recent activity # 📰 Recent activity
@@ -846,6 +847,7 @@ runs:
steps: steps:
- run: | - run: |
# Create environment file from inputs and GitHub variables # Create environment file from inputs and GitHub variables
echo "::group::Metrics docker image setup"
cd $METRICS_ACTION_PATH cd $METRICS_ACTION_PATH
touch .env touch .env
for INPUT in $(echo $INPUTS | jq -r 'to_entries|map("INPUT_\(.key|ascii_upcase)=\(.value|@uri)")|.[]'); do for INPUT in $(echo $INPUTS | jq -r 'to_entries|map("INPUT_\(.key|ascii_upcase)=\(.value|@uri)")|.[]'); do
@@ -864,20 +866,11 @@ runs:
# Image tag (extracted from version or from env) # Image tag (extracted from version or from env)
METRICS_TAG=v$(echo $METRICS_VERSION | sed -r 's/^([0-9]+[.][0-9]+).*/\1/') METRICS_TAG=v$(echo $METRICS_VERSION | sed -r 's/^([0-9]+[.][0-9]+).*/\1/')
if [[ $METRICS_USE_PREBUILT_IMAGE ]]; then
METRICS_TAG=$METRICS_USE_PREBUILT_IMAGE
echo "Pre-built image: yes"
fi
echo "Image tag: $METRICS_TAG" echo "Image tag: $METRICS_TAG"
# Image name # Image name
# Pre-built image
if [[ $METRICS_USE_PREBUILT_IMAGE ]]; then
echo "Using pre-built version $METRICS_TAG, will pull docker image from GitHub registry"
METRICS_IMAGE=ghcr.io/lowlighter/metrics:$METRICS_TAG
docker image pull $METRICS_IMAGE > /dev/null
# Official action # Official action
elif [[ $METRICS_SOURCE == "lowlighter" ]]; then if [[ $METRICS_SOURCE == "lowlighter" ]]; then
# Is released version # Is released version
set +e set +e
METRICS_IS_RELEASED=$(expr $(expr match $METRICS_VERSION .*-beta) == 0) METRICS_IS_RELEASED=$(expr $(expr match $METRICS_VERSION .*-beta) == 0)
@@ -887,7 +880,14 @@ runs:
if [[ "$METRICS_IS_RELEASED" -gt "0" ]]; then if [[ "$METRICS_IS_RELEASED" -gt "0" ]]; then
echo "Using released version $METRICS_TAG, will pull docker image from GitHub registry" echo "Using released version $METRICS_TAG, will pull docker image from GitHub registry"
METRICS_IMAGE=ghcr.io/lowlighter/metrics:$METRICS_TAG METRICS_IMAGE=ghcr.io/lowlighter/metrics:$METRICS_TAG
docker image pull $METRICS_IMAGE > /dev/null docker image pull $METRICS_IMAGE
# Use registry for unreleased version with pre-built images
elif [[ ! $METRICS_USE_PREBUILT_IMAGE =~ ^([Ff]alse|[Oo]ff|[Nn]o|0)$ ]]; then
METRICS_TAG="$METRICS_TAG-beta"
echo "Image tag (updated): $METRICS_TAG"
echo "Using pre-built version $METRICS_TAG, will pull docker image from GitHub registry"
METRICS_IMAGE=ghcr.io/lowlighter/metrics:$METRICS_TAG
docker image pull $METRICS_IMAGE
# Rebuild image for unreleased version # Rebuild image for unreleased version
else else
echo "Using an unreleased version ($METRICS_VERSION)" echo "Using an unreleased version ($METRICS_VERSION)"
@@ -902,15 +902,16 @@ runs:
# Build image if necessary # Build image if necessary
set +e set +e
docker image inspect $METRICS_IMAGE > /dev/null docker image inspect $METRICS_IMAGE
METRICS_IMAGE_NEEDS_BUILD="$?" METRICS_IMAGE_NEEDS_BUILD="$?"
set -e set -e
if [[ "$METRICS_IMAGE_NEEDS_BUILD" -gt "0" ]]; then if [[ "$METRICS_IMAGE_NEEDS_BUILD" -gt "0" ]]; then
echo "Image $METRICS_IMAGE is not present locally, rebuilding it from Dockerfile" echo "Image $METRICS_IMAGE is not present locally, rebuilding it from Dockerfile"
docker build -t $METRICS_IMAGE . > /dev/null docker build -t $METRICS_IMAGE .
else else
echo "Image $METRICS_IMAGE is present locally" echo "Image $METRICS_IMAGE is present locally"
fi fi
echo "::endgroup::"
# Run docker image with current environment # Run docker image with current environment
docker run --init --volume $GITHUB_EVENT_PATH:$GITHUB_EVENT_PATH --env-file .env $METRICS_IMAGE docker run --init --volume $GITHUB_EVENT_PATH:$GITHUB_EVENT_PATH --env-file .env $METRICS_IMAGE

View File

@@ -27,6 +27,7 @@ runs:
steps: steps:
- run: | - run: |
# Create environment file from inputs and GitHub variables # Create environment file from inputs and GitHub variables
echo "::group::Metrics docker image setup"
cd $METRICS_ACTION_PATH cd $METRICS_ACTION_PATH
touch .env touch .env
for INPUT in $(echo $INPUTS | jq -r 'to_entries|map("INPUT_\(.key|ascii_upcase)=\(.value|@uri)")|.[]'); do for INPUT in $(echo $INPUTS | jq -r 'to_entries|map("INPUT_\(.key|ascii_upcase)=\(.value|@uri)")|.[]'); do
@@ -45,20 +46,11 @@ runs:
# Image tag (extracted from version or from env) # Image tag (extracted from version or from env)
METRICS_TAG=v$(echo $METRICS_VERSION | sed -r 's/^([0-9]+[.][0-9]+).*/\1/') METRICS_TAG=v$(echo $METRICS_VERSION | sed -r 's/^([0-9]+[.][0-9]+).*/\1/')
if [[ $METRICS_USE_PREBUILT_IMAGE ]]; then
METRICS_TAG=$METRICS_USE_PREBUILT_IMAGE
echo "Pre-built image: yes"
fi
echo "Image tag: $METRICS_TAG" echo "Image tag: $METRICS_TAG"
# Image name # Image name
# Pre-built image
if [[ $METRICS_USE_PREBUILT_IMAGE ]]; then
echo "Using pre-built version $METRICS_TAG, will pull docker image from GitHub registry"
METRICS_IMAGE=ghcr.io/lowlighter/metrics:$METRICS_TAG
docker image pull $METRICS_IMAGE > /dev/null
# Official action # Official action
elif [[ $METRICS_SOURCE == "lowlighter" ]]; then if [[ $METRICS_SOURCE == "lowlighter" ]]; then
# Is released version # Is released version
set +e set +e
METRICS_IS_RELEASED=$(expr $(expr match $METRICS_VERSION .*-beta) == 0) METRICS_IS_RELEASED=$(expr $(expr match $METRICS_VERSION .*-beta) == 0)
@@ -68,7 +60,14 @@ runs:
if [[ "$METRICS_IS_RELEASED" -gt "0" ]]; then if [[ "$METRICS_IS_RELEASED" -gt "0" ]]; then
echo "Using released version $METRICS_TAG, will pull docker image from GitHub registry" echo "Using released version $METRICS_TAG, will pull docker image from GitHub registry"
METRICS_IMAGE=ghcr.io/lowlighter/metrics:$METRICS_TAG METRICS_IMAGE=ghcr.io/lowlighter/metrics:$METRICS_TAG
docker image pull $METRICS_IMAGE > /dev/null docker image pull $METRICS_IMAGE
# Use registry for unreleased version with pre-built images
elif [[ ! $METRICS_USE_PREBUILT_IMAGE =~ ^([Ff]alse|[Oo]ff|[Nn]o|0)$ ]]; then
METRICS_TAG="$METRICS_TAG-beta"
echo "Image tag (updated): $METRICS_TAG"
echo "Using pre-built version $METRICS_TAG, will pull docker image from GitHub registry"
METRICS_IMAGE=ghcr.io/lowlighter/metrics:$METRICS_TAG
docker image pull $METRICS_IMAGE
# Rebuild image for unreleased version # Rebuild image for unreleased version
else else
echo "Using an unreleased version ($METRICS_VERSION)" echo "Using an unreleased version ($METRICS_VERSION)"
@@ -83,15 +82,16 @@ runs:
# Build image if necessary # Build image if necessary
set +e set +e
docker image inspect $METRICS_IMAGE > /dev/null docker image inspect $METRICS_IMAGE
METRICS_IMAGE_NEEDS_BUILD="$?" METRICS_IMAGE_NEEDS_BUILD="$?"
set -e set -e
if [[ "$METRICS_IMAGE_NEEDS_BUILD" -gt "0" ]]; then if [[ "$METRICS_IMAGE_NEEDS_BUILD" -gt "0" ]]; then
echo "Image $METRICS_IMAGE is not present locally, rebuilding it from Dockerfile" echo "Image $METRICS_IMAGE is not present locally, rebuilding it from Dockerfile"
docker build -t $METRICS_IMAGE . > /dev/null docker build -t $METRICS_IMAGE .
else else
echo "Image $METRICS_IMAGE is present locally" echo "Image $METRICS_IMAGE is present locally"
fi fi
echo "::endgroup::"
# Run docker image with current environment # Run docker image with current environment
docker run --init --volume $GITHUB_EVENT_PATH:$GITHUB_EVENT_PATH --env-file .env $METRICS_IMAGE docker run --init --volume $GITHUB_EVENT_PATH:$GITHUB_EVENT_PATH --env-file .env $METRICS_IMAGE

View File

@@ -210,9 +210,10 @@ inputs:
type: boolean type: boolean
default: no default: no
# Use a pre-built image from GitHub registry (experimental) # Use a pre-built image from GitHub registry when using unreleased versions of "lowlighter/metrics"
# This option has no effect on forks (images will always be rebuilt from Dockerfile)
# See https://github.com/users/lowlighter/packages/container/package/metrics for more information # See https://github.com/users/lowlighter/packages/container/package/metrics for more information
use_prebuilt_image: use_prebuilt_image:
description: Use pre-built image from GitHub registry description: Use pre-built image from GitHub registry
type: string type: boolean
default: "" default: yes