Skip to content

Commit

Permalink
[actions] Refactor building and pushing docker containers
Browse files Browse the repository at this point in the history
Move the logic into a re-usable action so we can later use it from within bcc-test
workflow to build (instead of pulling) the container when a dockerfile is modified.
  • Loading branch information
chantra committed Sep 9, 2022
1 parent 6129eef commit 83cf8b1
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 24 deletions.
47 changes: 47 additions & 0 deletions .github/actions/build-container/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: "Build/Push container"
description: "Build a BCC CI container and push it when not a pull-request."

inputs:
os_distro:
description: "OS Disctribution. Ex: ubuntu"
required: true
os_version:
description: "Version of the OS. Ex: 20.04"
required: true
os_nick:
description: "Nickname of the OS. Ex: focal"
required: true
registry:
description: "Registry where to push images"
default: ghcr.io
password:
description: "Password used to log into the docker registry."
push:
description: "Whether or not to push the build image"
type: boolean
default: false

runs:
using: "composite"
steps:
# Login against registry except on PR
# https://github.com/docker/login-action
- name: Log into registry ${{ inputs.registry }}
if: ${{ inputs.push == 'true' && github.event_name != 'pull_request' }}

uses: docker/login-action@v2
with:
registry: ${{ inputs.registry }}
username: ${{ github.actor }}
password: ${{ inputs.password }}

- name: Build and push
uses: docker/build-push-action@v3
with:
push: ${{ inputs.push == 'true' && github.event_name != 'pull_request' }}
build-args: |
VERSION=${{ inputs.os_version }}
SHORTNAME=${{ inputs.os_nick }}
file: docker/build/Dockerfile.${{ inputs.os_distro }}
tags: ${{ inputs.registry }}/${{ github.repository }}:${{ inputs.os_distro }}-${{ inputs.os_version }}

30 changes: 6 additions & 24 deletions .github/workflows/publish-build-containers.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,6 @@ on:
paths:
- 'docker/build/**'


env:
# Use docker.io for Docker Hub if empty
REGISTRY: ghcr.io
# github.repository as <account>/<repo>
IMAGE_NAME: ${{ github.repository }}
jobs:

publish_ghcr:
Expand All @@ -35,23 +29,11 @@ jobs:

- uses: actions/checkout@v2

# Login against registry except on PR
# https://github.com/docker/login-action
- name: Log into registry ${{ env.REGISTRY }}
if: github.event_name != 'pull_request'
uses: docker/login-action@v2
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Build and push
uses: docker/build-push-action@v3
uses: ./.github/actions/build-container
with:
push: ${{ github.event_name != 'pull_request' }}
build-args: |
VERSION=${{ matrix.os.version }}
SHORTNAME=${{ matrix.os.nick }}
file: docker/build/Dockerfile.${{ matrix.os.distro }}
tags: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ matrix.os.distro }}-${{ matrix.os.version }}

os_distro: ${{ matrix.os.distro }}
os_version: ${{ matrix.os.version }}
os_nick: ${{ matrix.os.nick }}
password: ${{ secrets.GITHUB_TOKEN }}
push: true

0 comments on commit 83cf8b1

Please sign in to comment.