Skip to content

Commit

Permalink
Create reusable workflow for building images
Browse files Browse the repository at this point in the history
  • Loading branch information
chbrandt committed Oct 24, 2023
1 parent 38fd4ae commit a43d427
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 42 deletions.
49 changes: 7 additions & 42 deletions .github/workflows/docker_build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,45 +32,10 @@ on:


jobs:
docker:
runs-on: ubuntu-latest
steps:
- # https://github.com/marketplace/actions/checkout
name: Checkout
uses: actions/checkout@v4
- # https://github.com/marketplace/actions/docker-metadata-action
name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
# list of Docker images to use as base name for tags
images: |
${{ vars.DOCKERHUB_USERNAME }}/jupyter-gispy
# generate Docker tags based on the following events/attributes
tags: |
type=raw,value=latest,enable=${{ github.ref == format('refs/heads/{0}', 'stable') }}
type=ref,event=branch,enable=${{ github.ref == format('refs/heads/{0}', 'test') }}
type=ref,event=tag
type=sha
- # https://github.com/marketplace/actions/docker-setup-qemu
name: Set up QEMU
uses: docker/setup-qemu-action@v3
- # https://github.com/marketplace/actions/docker-setup-buildx
name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- # https://github.com/marketplace/actions/docker-login
name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- # https://github.com/marketplace/actions/build-and-push-docker-images
name: Build and push
uses: docker/build-push-action@v5
with:
context: ./dockerfiles
file: ./dockerfiles/gispy.dockerfile
# push: true
push: ${{ github.event_name == 'push' }}
# tags: user/app:latest
tags: ${{ steps.meta.outputs.tags }}
gispy:
uses: ./.github/workflows/workflow_build.yml
with:
image_name: ${{ vars.DOCKERHUB_USERNAME }}/jupyter-gispy
context_path: ./dockerfiles
dockerfile_path: ./dockerfiles/gispy.dockerfile
secrets: inherit
65 changes: 65 additions & 0 deletions .github/workflows/workflow_build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# Reusable workflow for building the docker images
#
# Reference docs:
# - https://docs.github.com/en/actions/using-workflows/reusing-workflows

on:
# Define workflow as reusable
workflow_call:
inputs:
image_name:
required: true
type: string
context_path:
required: true
type: string
file_path:
required: true
type: string


jobs:

build:
runs-on: ubuntu-latest

steps:
- # https://github.com/marketplace/actions/checkout
name: Checkout
uses: actions/checkout@v4
- # https://github.com/marketplace/actions/docker-metadata-action
name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
# list of Docker images to use as base name for tags
images: |
${{ inputs.image_name }}
# generate Docker tags based on the following events/attributes
tags: |
type=raw,value=latest,enable=${{ github.ref == format('refs/heads/{0}', 'stable') }}
type=ref,event=branch,enable=${{ github.ref == format('refs/heads/{0}', 'test') }}
type=ref,event=tag
type=sha
- # https://github.com/marketplace/actions/docker-setup-qemu
name: Set up QEMU
uses: docker/setup-qemu-action@v3
- # https://github.com/marketplace/actions/docker-setup-buildx
name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- # https://github.com/marketplace/actions/docker-login
name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- # https://github.com/marketplace/actions/build-and-push-docker-images
name: Build and push
uses: docker/build-push-action@v5
with:
context: ${{ inputs.context_path }}
file: ${{ inputs.file_path }}
# push: true
push: ${{ github.event_name == 'push' }}
# tags: user/app:latest
tags: ${{ steps.meta.outputs.tags }}

0 comments on commit a43d427

Please sign in to comment.