Skip to content

Commit

Permalink
Use composite action
Browse files Browse the repository at this point in the history
  • Loading branch information
cansavvy committed Jan 7, 2025
1 parent 2aa341e commit 169f336
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 35 deletions.
74 changes: 39 additions & 35 deletions .github/workflows/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,48 +6,52 @@ on:
workflow_call:
inputs:
directory:
description: 'What's the file path to this Dockerfile's folder in this repo'
required: true
type: string
tag:
description: 'What is this called on Dockerhub? e.g. jhudsl/base_ottr'
required: true
type: string
dockerhubpush:
description: 'Push to Dockerhub?'
description: 'Should this be pushed to Dockerhub?'
required: false
default: 'false'
type: string
token:
description: 'A GitHub Personal Access Token'
required: false
dockerhub_username:
description: 'A Dockerhub username that has access to this image'
required: false
dockerhub_token:
description: 'A Dockerhub token that has persmissions to push to this image'
required: false

defaults:
run:
working-directory: ./

jobs:

build-docker:
name: Build Docker image
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0

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

- name: Login to Docker Hub
if: ${{ inputs.dockerhubpush != 'false' }}
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Build
uses: docker/build-push-action@v6
with:
push: ${{ inputs.dockerhubpush }}
context: ${{ inputs.directory }}
file: ${{ inputs.directory }}/Dockerfile
platforms: linux/amd64
tags: ${{ inputs.tag }}
runs:
using: "composite"
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0
token: ${{ inputs.token }}

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

- name: Login to Docker Hub
if: ${{ inputs.dockerhubpush != 'false' }}
uses: docker/login-action@v3
with:
username: ${{ inputs.DOCKERHUB_USERNAME }}
password: ${{ inputs.DOCKERHUB_TOKEN }}

- name: Build
uses: docker/build-push-action@v6
with:
push: ${{ inputs.dockerhubpush }}
context: ${{ inputs.directory }}
file: ${{ inputs.directory }}/Dockerfile
platforms: linux/amd64
tags: ${{ inputs.tag }}
3 changes: 3 additions & 0 deletions .github/workflows/pull_request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,6 @@ jobs:
directory: ${{ matrix.config.dir }}
tag: ${{ matrix.config.name }}
dockerhubpush: false
token: ${ secrets.GH_PAT }
dockerhub_username: ${ secrets.DOCKERHUB_USERNAME }
dockerhub_token: ${ secrets.DOCKERHUB_TOKEN }

0 comments on commit 169f336

Please sign in to comment.