Skip to content

Commit

Permalink
Change confusing GitHub Actions procedures
Browse files Browse the repository at this point in the history
  • Loading branch information
ehfd authored Oct 20, 2023
1 parent 8434485 commit 331a839
Show file tree
Hide file tree
Showing 6 changed files with 437 additions and 556 deletions.
70 changes: 35 additions & 35 deletions .github/actions/build_and_publish_image/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at https://mozilla.org/MPL/2.0/.

name: Build & publish an image
name: Build & publish image

description: Build an image from source, then publish it to GHCR
description: Build image from source, then publish it to GHCR

inputs:
build_args:
Expand Down Expand Up @@ -44,39 +44,39 @@ inputs:
runs:
using: composite
steps:
- shell: bash
run: |
set -x
echo "${{ inputs.github_personal_access_token }}" | docker login ghcr.io -u "${{ inputs.github_username }}" --password-stdin
export BUILD_ARGS=""
if [[ -n "${{ inputs.build_args }}" ]]; then
IFS=";" read -ra args <<< "${{ inputs.build_args }}"
for arg in ${args[@]}; do
BUILD_ARGS+="--build-arg $arg "
if [[ "$arg" =~ "UBUNTU_RELEASE" ]]; then
# pull latest base image
eval "export $arg"
docker pull "ubuntu:${UBUNTU_RELEASE?}"
fi
done
fi
- shell: bash
run: |
set -x
echo "${{ inputs.github_personal_access_token }}" | docker login ghcr.io -u "${{ inputs.github_username }}" --password-stdin
export BUILD_ARGS=""
if [[ -n "${{ inputs.build_args }}" ]]; then
IFS=";" read -ra args <<< "${{ inputs.build_args }}"
for arg in ${args[@]}; do
BUILD_ARGS+="--build-arg $arg "
if [[ "$arg" =~ "UBUNTU_RELEASE" ]]; then
# pull latest base image
eval "export $arg"
docker pull "ubuntu:${UBUNTU_RELEASE?}"
fi
done
fi
export IMAGE_TAG_URL_PREFIX=ghcr.io/selkies-project/selkies-gstreamer/
export IMAGE_TAG_1="${IMAGE_TAG_URL_PREFIX}${{ inputs.image_name }}:${{ inputs.image_version_1 }}"
if [[ "${{ inputs.use_cache }}" == "true" ]]; then
docker pull "$IMAGE_TAG_1" || true
(cd "${{ inputs.image_source_directory }}" && docker build $BUILD_ARGS -f "${{ inputs.dockerfile }}" --cache-from "$IMAGE_TAG_1" -t "$IMAGE_TAG_1" .)
else
(cd "${{ inputs.image_source_directory }}" && docker build $BUILD_ARGS -f "${{ inputs.dockerfile }}" -t "$IMAGE_TAG_1" .)
fi
if [[ "${{ inputs.push_image }}" == "true" ]]; then
docker push "$IMAGE_TAG_1"
fi
export IMAGE_TAG_URL_PREFIX=ghcr.io/selkies-project/selkies-gstreamer/
export IMAGE_TAG_1="${IMAGE_TAG_URL_PREFIX}${{ inputs.image_name }}:${{ inputs.image_version_1 }}"
if [[ "${{ inputs.use_cache }}" == "true" ]]; then
docker pull "$IMAGE_TAG_1" || true
(cd "${{ inputs.image_source_directory }}" && docker build $BUILD_ARGS -f "${{ inputs.dockerfile }}" --cache-from "$IMAGE_TAG_1" -t "$IMAGE_TAG_1" .)
else
(cd "${{ inputs.image_source_directory }}" && docker build $BUILD_ARGS -f "${{ inputs.dockerfile }}" -t "$IMAGE_TAG_1" .)
fi
if [[ "${{ inputs.push_image }}" == "true" ]]; then
docker push "$IMAGE_TAG_1"
fi
if [[ ! -z "${{ inputs.image_version_2 }}" ]]; then
export IMAGE_TAG_2="${IMAGE_TAG_URL_PREFIX}${{ inputs.image_name }}:${{ inputs.image_version_2 }}"
docker tag "$IMAGE_TAG_1" "$IMAGE_TAG_2"
if [[ "${{ inputs.push_image }}" == "true" ]]; then
docker push "$IMAGE_TAG_2"
fi
if [[ ! -z "${{ inputs.image_version_2 }}" ]]; then
export IMAGE_TAG_2="${IMAGE_TAG_URL_PREFIX}${{ inputs.image_name }}:${{ inputs.image_version_2 }}"
docker tag "$IMAGE_TAG_1" "$IMAGE_TAG_2"
if [[ "${{ inputs.push_image }}" == "true" ]]; then
docker push "$IMAGE_TAG_2"
fi
fi
149 changes: 73 additions & 76 deletions .github/workflows/build_and_publish_all_images.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,7 @@ name: Build & publish all images
on:
push:
branches:
- main
paths:
- ".github/workflows/build_and_publish_all_images.yaml"
- ".github/actions/build_and_publish_image/action.yaml"
- main
workflow_dispatch:

jobs:
Expand All @@ -20,58 +17,58 @@ jobs:
strategy:
matrix:
include:
- name: coturn
source_directory: addons/coturn

- name: coturn-web
source_directory: addons/coturn-web

- name: gst-web
source_directory: addons/gst-web

- name: gstreamer
version_suffix: -ubuntu20.04
build_args: UBUNTU_RELEASE=20.04
source_directory: addons/gstreamer

- name: gstreamer
version_suffix: -ubuntu22.04
build_args: UBUNTU_RELEASE=22.04
source_directory: addons/gstreamer
- name: js-interposer
version_suffix: -ubuntu20.04
build_args: DISTRIB_RELEASE=20.04;PKG_NAME=selkies-js-interposer;PKG_VERSION=0.0.0
source_directory: addons/js-interposer
dockerfile: Dockerfile.ubuntu_debpkg

- name: js-interposer
version_suffix: -ubuntu22.04
build_args: DISTRIB_RELEASE=22.04;PKG_NAME=selkies-js-interposer;PKG_VERSION=0.0.0
source_directory: addons/js-interposer
dockerfile: Dockerfile.ubuntu_debpkg

- name: infra-gcp-installer
source_directory: infra/gce/installer-image

- name: py-build
build_args: PACKAGE_VERSION=0.0.0.dev0
source_directory: .
- name: coturn
source_directory: addons/coturn

- name: coturn-web
source_directory: addons/coturn-web

- name: gst-web
source_directory: addons/gst-web

- name: gstreamer
version_suffix: -ubuntu20.04
build_args: UBUNTU_RELEASE=20.04
source_directory: addons/gstreamer

- name: gstreamer
version_suffix: -ubuntu22.04
build_args: UBUNTU_RELEASE=22.04
source_directory: addons/gstreamer

- name: js-interposer
version_suffix: -ubuntu20.04
build_args: DISTRIB_RELEASE=20.04;PKG_NAME=selkies-js-interposer;PKG_VERSION=0.0.0
source_directory: addons/js-interposer
dockerfile: Dockerfile.ubuntu_debpkg

- name: js-interposer
version_suffix: -ubuntu22.04
build_args: DISTRIB_RELEASE=22.04;PKG_NAME=selkies-js-interposer;PKG_VERSION=0.0.0
source_directory: addons/js-interposer
dockerfile: Dockerfile.ubuntu_debpkg

- name: infra-gcp-installer
source_directory: infra/gce/installer-image

- name: py-build
build_args: PACKAGE_VERSION=0.0.0.dev0
source_directory: .

name: ${{ matrix.name }}${{ matrix.version_suffix }} image build & publish
steps:
- uses: actions/checkout@v4

- name: Build & publish ${{ matrix.name }} image
uses: ./.github/actions/build_and_publish_image
with:
build_args: ${{ matrix.build_args }}
github_personal_access_token: ${{ secrets.GITHUB_TOKEN }}
github_username: $GITHUB_ACTOR
image_name: ${{ matrix.name }}
image_source_directory: ${{ matrix.source_directory }}
image_version_1: $GITHUB_REF_NAME${{ matrix.version_suffix }}
dockerfile: ${{ matrix.dockerfile || 'Dockerfile' }}
- uses: actions/checkout@v4

- name: Build & publish ${{ matrix.name }} image
uses: ./.github/actions/build_and_publish_image
with:
build_args: ${{ matrix.build_args }}
github_personal_access_token: ${{ secrets.GITHUB_TOKEN }}
github_username: $GITHUB_ACTOR
image_name: ${{ matrix.name }}
image_source_directory: ${{ matrix.source_directory }}
image_version_1: $GITHUB_REF_NAME${{ matrix.version_suffix }}
dockerfile: ${{ matrix.dockerfile || 'Dockerfile' }}

# Note: When modifying this job, copy modifications to all other workflows' image jobs.
all_example_images:
Expand All @@ -80,29 +77,29 @@ jobs:
strategy:
matrix:
include:
- name: gst-py-example
version_suffix: -ubuntu20.04
build_args: PACKAGE_VERSION=0.0.0.dev0;UBUNTU_RELEASE=20.04;GSTREAMER_BASE_IMAGE_RELEASE=${{ github.ref_name }};PY_BUILD_IMAGE=ghcr.io/selkies-project/selkies-gstreamer/py-build:${{ github.ref_name }};WEB_IMAGE=ghcr.io/selkies-project/selkies-gstreamer/gst-web:${{ github.ref_name }};JS_BASE_IMAGE_RELEASE=${{ github.ref_name }};JS_BASE_IMAGE=ghcr.io/selkies-project/selkies-gstreamer/js-interposer
dockerfile: Dockerfile.example
source_directory: .

- name: gst-py-example
version_suffix: -ubuntu22.04
build_args: PACKAGE_VERSION=0.0.0.dev0;UBUNTU_RELEASE=22.04;GSTREAMER_BASE_IMAGE_RELEASE=${{ github.ref_name }};PY_BUILD_IMAGE=ghcr.io/selkies-project/selkies-gstreamer/py-build:${{ github.ref_name }};WEB_IMAGE=ghcr.io/selkies-project/selkies-gstreamer/gst-web:${{ github.ref_name }};JS_BASE_IMAGE_RELEASE=${{ github.ref_name }};JS_BASE_IMAGE=ghcr.io/selkies-project/selkies-gstreamer/js-interposer
dockerfile: Dockerfile.example
source_directory: .
- name: gst-py-example
version_suffix: -ubuntu20.04
build_args: PACKAGE_VERSION=0.0.0.dev0;UBUNTU_RELEASE=20.04;GSTREAMER_BASE_IMAGE_RELEASE=${{ github.ref_name }};PY_BUILD_IMAGE=ghcr.io/selkies-project/selkies-gstreamer/py-build:${{ github.ref_name }};WEB_IMAGE=ghcr.io/selkies-project/selkies-gstreamer/gst-web:${{ github.ref_name }};JS_BASE_IMAGE_RELEASE=${{ github.ref_name }};JS_BASE_IMAGE=ghcr.io/selkies-project/selkies-gstreamer/js-interposer
dockerfile: Dockerfile.example
source_directory: .

- name: gst-py-example
version_suffix: -ubuntu22.04
build_args: PACKAGE_VERSION=0.0.0.dev0;UBUNTU_RELEASE=22.04;GSTREAMER_BASE_IMAGE_RELEASE=${{ github.ref_name }};PY_BUILD_IMAGE=ghcr.io/selkies-project/selkies-gstreamer/py-build:${{ github.ref_name }};WEB_IMAGE=ghcr.io/selkies-project/selkies-gstreamer/gst-web:${{ github.ref_name }};JS_BASE_IMAGE_RELEASE=${{ github.ref_name }};JS_BASE_IMAGE=ghcr.io/selkies-project/selkies-gstreamer/js-interposer
dockerfile: Dockerfile.example
source_directory: .

name: ${{ matrix.name }}${{ matrix.version_suffix }} image build & publish
steps:
- uses: actions/checkout@v4

- name: Build & publish ${{ matrix.name }} image
uses: ./.github/actions/build_and_publish_image
with:
build_args: ${{ matrix.build_args }}
dockerfile: ${{ matrix.dockerfile }}
github_personal_access_token: ${{ secrets.GITHUB_TOKEN }}
github_username: $GITHUB_ACTOR
image_name: ${{ matrix.name }}
image_source_directory: ${{ matrix.source_directory }}
image_version_1: $GITHUB_REF_NAME${{ matrix.version_suffix }}
- uses: actions/checkout@v4

- name: Build & publish ${{ matrix.name }} image
uses: ./.github/actions/build_and_publish_image
with:
build_args: ${{ matrix.build_args }}
dockerfile: ${{ matrix.dockerfile }}
github_personal_access_token: ${{ secrets.GITHUB_TOKEN }}
github_username: $GITHUB_ACTOR
image_name: ${{ matrix.name }}
image_source_directory: ${{ matrix.source_directory }}
image_version_1: $GITHUB_REF_NAME${{ matrix.version_suffix }}
Loading

0 comments on commit 331a839

Please sign in to comment.