Skip to content

Commit

Permalink
Refactor GitHub Actions workflow: removed unused input parameters for…
Browse files Browse the repository at this point in the history
… versioning and reference type, streamlined build process by directly using GitHub context variables, and consolidated Docker build and push steps for improved clarity and efficiency.
  • Loading branch information
jaydrogers committed Dec 11, 2024
1 parent d8cc8f2 commit 2d14bd8
Showing 1 changed file with 6 additions and 45 deletions.
51 changes: 6 additions & 45 deletions .github/workflows/service_docker-build-and-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,30 +8,14 @@ on:
required: true
description: 'Release type (latest, beta, edge, dev, etc)'
default: 'edge'
version:
type: string
required: false
description: 'Version to build (e.g. 1.0.0)'
default: "${{ github.ref_name }}"
ref_type:
type: string
required: false
description: 'Trigger type (tag or branch)'
default: "${{ github.ref_type }}"
ref:
type: string
required: false
description: 'Ref to build (e.g. v1.0.0)'
default: ''

jobs:

build-and-push:
runs-on: ubuntu-24.04
steps:
- name: Check out code.
uses: actions/checkout@v4
with:
ref: ${{ inputs.ref }}

- name: Login to DockerHub
uses: docker/login-action@v3
Expand All @@ -55,9 +39,9 @@ jobs:
- name: Set REPOSITORY_BUILD_VERSION
id: set_version
run: |
if [ "${{ inputs.ref_type }}" == "tag" ]; then
if [ "${{ github.ref_type }}" == "tag" ]; then
echo "🚀 Setting REPOSITORY_BUILD_VERSION to Tag"
echo "REPOSITORY_BUILD_VERSION=${{ inputs.version }}-${{ github.run_id }}" >> $GITHUB_ENV
echo "REPOSITORY_BUILD_VERSION=${{ github.ref_name }}" >> $GITHUB_ENV
else
echo "👨‍🔬 Setting REPOSITORY_BUILD_VERSION to GIT Short SHA and GitHub Run ID"
SHORT_SHA=$(echo ${{ github.sha }} | cut -c1-7)
Expand All @@ -66,41 +50,18 @@ jobs:
- name: "📦 Assemble the Docker Tags"
run: |
if [ "${{ inputs.ref_type }}" == "tag" ]; then
if [ "${{ github.ref_type }}" == "tag" ]; then
bash build.sh \
--release-type ${{ inputs.release_type }} \
--version ${{ inputs.version }} \
--version ${{ github.ref_name }} \
--print-tags-only
else
bash build.sh \
--release-type ${{ inputs.release_type }} \
--print-tags-only
fi
- name: Build and export to Docker
uses: docker/build-push-action@v6
with:
file: src/Dockerfile
cache-from: type=gha,mode=max
cache-to: type=gha,mode=max
platforms: linux/amd64 # Only build amd64 for scanning
pull: true
push: false
load: true # Load into Docker's local image store
tags: ${{ env.DOCKER_TAGS }}

- name: Run Trivy vulnerability scanner
uses: aquasecurity/trivy-action@0.29.0
with:
image-ref: ${{ env.DOCKER_TAGS }}
format: 'table'
exit-code: 1
ignore-unfixed: true
severity: 'CRITICAL,HIGH'
hide-progress: true

- name: Build and push all platforms
if: success()
- name: Build and push
uses: docker/build-push-action@v6
with:
file: src/Dockerfile
Expand Down

0 comments on commit 2d14bd8

Please sign in to comment.