Skip to content

Commit

Permalink
Issue #3673: try to use the composite action
Browse files Browse the repository at this point in the history
for building devel and release images.
No need to pass input to the composite action as the contexts
env, matrix, and github are available there.

Log into Docker Hub outside the composite action.
  • Loading branch information
bschmalhofer committed Aug 13, 2024
1 parent 0170105 commit 15a5b14
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 94 deletions.
72 changes: 59 additions & 13 deletions .github/actions/docker_image_builder/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,7 @@ name: 'DockerImageBuilder'

description: 'Composite action for building Docker images and pushing them to Docker Hub'

inputs:
context:
description: 'the build context'
required: true
dockerfile:
description: 'the relevant dockerfile'
required: true
target:
description: 'target within the dockerfile'
required: true

#inputs:
#outputs:

runs:
Expand All @@ -36,13 +26,69 @@ runs:
run: |
echo 'env: ' $ENV_AS_JSON
echo 'matrix: ' $MATRIX_AS_JSON
echo 'inputs: ' $INPUTS_AS_JSON
echo 'github: ' $GITHUB_AS_JSON
env:
ENV_AS_JSON: ${{ toJSON(env) }}
MATRIX_AS_JSON: ${{ toJSON(matrix) }}
INPUTS_AS_JSON: ${{ toJSON(inputs) }}
GITHUB_AS_JSON: ${{ toJSON(github) }}

- name: 'Set up Docker Buildx'
uses: docker/setup-buildx-action@v3

-
# Build the image but do not push it to Docker Hub yet.
# Enable caching with Github Actions Cache, which is limited to 10 GB.
# context: . indicates that the current checkout is used
name: Build
uses: docker/build-push-action@v6
with:
load: true
context: ${{ matrix.context }}
file: ${{ matrix.dockerfile }}
pull: true
build-args: |
BUILD_DATE=${{ env.otobo_build_date }}
DOCKER_TAG=${{ env.otobo_docker_tag }}
GIT_REPO=${{ github.repositoryUrl }}
GIT_BRANCH=${{ env.otobo_branch }}
GIT_COMMIT=${{ env.otobo_commit }}
tags: ${{ env.otobo_ref }}
target: ${{ matrix.target }}
cache-from: type=gha
cache-to: type=gha,mode=max`

-
# Show some files in the image just to check sanity.
# otobo_first_time hasn't run yet, so /opt/otobo is still empty
name: Info
run: |
docker run --rm -w /opt/otobo_install/otobo_next --entrypoint /bin/bash $otobo_ref -c "more git-repo.txt git-branch.txt git-commit.txt RELEASE | cat"
-
# login to Docker Hub before pushing to Docker Hub
name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

-
# finally upload to DockerHub
# the built image is already available in the job
name: Push to DockerHub
uses: docker/build-push-action@v6
with:
push: true
context: ${{ matrix.context }}
file: ${{ matrix.dockerfile }}
pull: true
build-args: |
BUILD_DATE=${{ env.otobo_build_date }}
DOCKER_TAG=${{ env.otobo_docker_tag }}
GIT_REPO=${{ github.repositoryUrl }}
GIT_BRANCH=${{ env.otobo_branch }}
GIT_COMMIT=${{ env.otobo_commit }}
tags: ${{ env.otobo_ref }}
target: ${{ matrix.target }}
cache-from: type=gha
cache-to: type=gha,mode=max`
68 changes: 6 additions & 62 deletions .github/workflows/docker_image_builder_devel.yml
Original file line number Diff line number Diff line change
Expand Up @@ -96,49 +96,8 @@ jobs:
- '${{ matrix.context }}/**'
-
# Uses a local composite action.
# The repository must already be checked out.
name: 'Run local composite action'
if: steps.changes.outputs.context == 'true'
uses: ./.github/actions/docker_image_builder
with:
context: ${{ matrix.context }}
dockerfile: ${{ matrix.dockerfile }}
target: ${{ matrix.target }}

-
# Build the image but do not push it to Docker Hub yet.
# Enable caching with Github Actions Cache, which is limited to 10 GB.
# context: . indicates that the current checkout is used
name: Build
if: steps.changes.outputs.context == 'true'
uses: docker/build-push-action@v6
with:
load: true
context: ${{ matrix.context }}
file: ${{ matrix.dockerfile }}
pull: true
build-args: |
BUILD_DATE=${{ env.otobo_build_date }}
DOCKER_TAG=${{ env.otobo_docker_tag }}
GIT_REPO=${{ github.repositoryUrl }}
GIT_BRANCH=${{ env.otobo_branch }}
GIT_COMMIT=${{ env.otobo_commit }}
tags: ${{ env.otobo_ref }}
target: ${{ matrix.target }}
cache-from: type=gha
cache-to: type=gha,mode=max`

-
# Show some files in the image just to check sanity.
# otobo_first_time hasn't run yet, so /opt/otobo is still empty
name: Info
if: ${{ steps.changes.outputs.context == 'true' && matrix.dockerfile == 'otobo.web.dockerfile' }}
run: |
docker run --rm -w /opt/otobo_install/otobo_next --entrypoint /bin/bash $otobo_ref -c "more git-repo.txt git-branch.txt git-commit.txt RELEASE | cat"
-
# login to Docker Hub before pushing to Docker Hub
# login to Docker Hub before the composite action
# this avoids that secrets have to be passed
name: Login to Docker Hub
if: steps.changes.outputs.context == 'true'
uses: docker/login-action@v3
Expand All @@ -147,23 +106,8 @@ jobs:
password: ${{ secrets.DOCKERHUB_TOKEN }}

-
# finally upload to DockerHub
# the built image is already available in the job
name: Push to DockerHub
# Uses a local composite action.
# The repository must already be checked out.
name: 'Run local composite action'
if: steps.changes.outputs.context == 'true'
uses: docker/build-push-action@v6
with:
push: true
context: ${{ matrix.context }}
file: ${{ matrix.dockerfile }}
pull: true
build-args: |
BUILD_DATE=${{ env.otobo_build_date }}
DOCKER_TAG=${{ env.otobo_docker_tag }}
GIT_REPO=${{ github.repositoryUrl }}
GIT_BRANCH=${{ env.otobo_branch }}
GIT_COMMIT=${{ env.otobo_commit }}
tags: ${{ env.otobo_ref }}
target: ${{ matrix.target }}
cache-from: type=gha
cache-to: type=gha,mode=max`
uses: ./.github/actions/docker_image_builder
30 changes: 11 additions & 19 deletions .github/workflows/docker_image_builder_rel.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ on:

# Build a devel Docker image whenever there is a push into the listed branches.
# This is triggered by running the commands:
# git tag test-1_22_333_AAA
# git push origin test-1_22_333_AAA
# git tag test-1_22_333_DD
# git push origin test-1_22_333_DD
push:
tags:
- test-[0-9]+_[0-9]+_[0-9]+_*
Expand Down Expand Up @@ -73,28 +73,20 @@ jobs:
echo "otobo_commit=${{ github.sha }}"
) >> $GITHUB_ENV
- name: 'devel output'
run: |
echo 'matrix.target: ${{ matrix.target }}'
echo 'matrix.tag_prefix: ${{ matrix.tag_prefix }}'
echo 'env.otobo_branch: ${{ env.otobo_branch }}'
echo 'env.otobo_build_date: ${{ env.otobo_build_date }}'
echo 'env.otobo_commit: ${{ env.otobo_commit }}'
echo 'github.ref: ${{ github.ref }}'
echo 'github.ref_name: ${{ github.ref_name }}'
echo 'github.ref_type: ${{ github.ref_type }}'
echo 'github.event_name: ${{ github.event_name }}'
- name: 'check out the relevant OTOBO branch'
uses: actions/checkout@v4

-
# login to Docker Hub before the composite action
# this avoids that secrets have to be passed
name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

-
# Uses a local composite action.
# The repository must already be checked out.
name: 'Run local composite action'
#if: steps.changes.outputs.context == 'true'
uses: ./.github/actions/docker_image_builder
with:
context: ${{ matrix.context }}
dockerfile: ${{ matrix.dockerfile }}
target: ${{ matrix.target }}

0 comments on commit 15a5b14

Please sign in to comment.