Skip to content

Commit

Permalink
Merge branch 'develop' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
yinghaoSunn authored Dec 16, 2024
2 parents 9c6ebe1 + 39c014e commit 67c0b0e
Show file tree
Hide file tree
Showing 15 changed files with 241 additions and 484 deletions.
138 changes: 138 additions & 0 deletions .github/workflows/docker-build-image.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
name: build-image

on:
workflow_call:
inputs:
image-name:
required: true
type: string
build-context:
required: true
type: string
dockerfile:
required: true
type: string
r-version:
required: true
type: string
parent-image:
required: false
default: ''
type: string
model-version:
required: false
default: ''
type: string
platforms:
required: false
default: "linux/amd64"
type: string

jobs:
build:
runs-on: ubuntu-latest
permissions:
packages: write

steps:

- name: lowercase image name
id: name
run: echo "image_name=$(echo ${{ inputs.image-name }} | tr '[:upper:]' '[:lower:]')" >> $GITHUB_OUTPUT

- name: set PARENT_IMAGE only if specified
id: parent
shell: bash
run: |
REGISTRY=$(
[[ ${{ github.event_name }} == 'pull_request' ]] &&
echo "ghcr.io/${{ github.actor }}/${{ github.repository }}" ||
echo "docker.io/pecan")
echo "PARENT_IMAGE_IF_SET=$(
[[ -n '${{ inputs.parent-image }}' ]] &&
echo "PARENT_IMAGE=${REGISTRY}/"'${{ inputs.parent-image }}'
)" >> $GITHUB_OUTPUT
- name: set MODEL_VERSION only if specified
id: modelver
shell: bash
run: |
echo "MODEL_VERSION_IF_SET=$(
[[ -n '${{ inputs.model-version }}' ]] &&
echo 'MODEL_VERSION=${{ inputs.model-version }}'
)" >> $GITHUB_OUTPUT
- uses: actions/checkout@v4

# create metadata for image
- name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
# list of Docker images to use as base name for tags
images: |
name=ghcr.io/${{ github.actor }}/${{ github.repository }}/${{ steps.name.outputs.image_name }}
name=pecan/${{ steps.name.outputs.image_name }},enable=${{ github.event_name != 'pull_request' }}
# generate Docker tags based on the following events/attributes
tags: |
type=schedule
type=ref,event=branch
type=ref,event=pr
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=semver,pattern={{major}}
# setup docker build
- name: Set up QEMU
uses: docker/setup-qemu-action@v3

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

- name: Inspect Builder
run: |
echo "Name: ${{ steps.buildx.outputs.name }}"
echo "Endpoint: ${{ steps.buildx.outputs.endpoint }}"
echo "Status: ${{ steps.buildx.outputs.status }}"
echo "Flags: ${{ steps.buildx.outputs.flags }}"
echo "Platforms: ${{ steps.buildx.outputs.platforms }}"
# login to registries
- name: Login to DockerHub
if: github.event_name != 'pull_request'
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_PASSWORD }}

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

# build the docker images
- name: Build and push ${{ steps.name.outputs.image_name }}
uses: docker/build-push-action@v6
with:
context: ${{ inputs.build-context }}
file: ${{ inputs.dockerfile }}
push: true
platforms: ${{ inputs.platforms }}
cache-from: type=gha
cache-to: type=gha,mode=max
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
build-args: |
VERSION=${{ steps.meta.outputs.version }}
IMAGE_VERSION=${{ steps.meta.outputs.version }}
PECAN_VERSION=${{ steps.meta.outputs.version }}
R_VERSION=${{ inputs.r-version }}
${{ steps.parent.outputs.PARENT_IMAGE_IF_SET }}
${{ steps.modelver.outputs.MODEL_VERSION_IF_SET }}
GITHUB_PAT=${{ secrets.GITHUB_TOKEN }}
PECAN_GIT_BRANCH=${{ github.head_ref || github.ref_name }}
PECAN_GIT_CHECKSUM=${{ github.sha }}
PECAN_GIT_DATE=${{ github.event.repository.updated_at }}
Loading

0 comments on commit 67c0b0e

Please sign in to comment.