Skip to content
This repository has been archived by the owner on Oct 28, 2024. It is now read-only.

Commit

Permalink
Add Docker build GitHub Actions
Browse files Browse the repository at this point in the history
  • Loading branch information
ahosgood committed Jan 2, 2024
1 parent dc674d0 commit ee1a41b
Show file tree
Hide file tree
Showing 3 changed files with 94 additions and 0 deletions.
44 changes: 44 additions & 0 deletions .github/actions/docker-build/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: Build Docker image

inputs:
version:
required: true
type: string
latest:
required: false
type: boolean
default: false
github-token:
required: true
type: string
docker-image-name:
required: true
type: string

runs:
using: "composite"
steps:
- uses: actions/checkout@v3
- name: Log in to registry
run: echo "${{ inputs.github-token }}" | docker login ghcr.io -u $ --password-stdin
shell: bash
- uses: hadolint/[email protected]
with:
dockerfile: Dockerfile
ignore: DL3045,DL3007
- name: Build and push image
run: |
IMAGE_ID=$(echo "ghcr.io/${{ github.repository_owner }}/${{ inputs.docker-image-name }}" | tr '[A-Z]' '[a-z]')
echo "IMAGE_ID=$IMAGE_ID" >> "$GITHUB_OUTPUT"
echo $IMAGE_ID
docker build --tag $IMAGE_ID:${{ inputs.version }} --platform=linux/amd64 --no-cache .
docker push $IMAGE_ID:${{ inputs.version }}
shell: bash
- name: Tag latest
if: inputs.latest
run: |
IMAGE_ID=$(echo "ghcr.io/${{ github.repository_owner }}/${{ inputs.docker-image-name }}" | tr '[A-Z]' '[a-z]')
echo $IMAGE_ID
docker tag $IMAGE_ID:${{ inputs.version }} $IMAGE_ID:latest
docker push $IMAGE_ID:latest
shell: bash
21 changes: 21 additions & 0 deletions .github/actions/get-version-tag/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: Get version tag

outputs:
version-tag:
description: "Version tag"
value: ${{ steps.version-tag.outputs.VERSION }}

runs:
using: "composite"
steps:
- id: version-tag
name: Get tag from branch, tag or release
run: |
VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,')
# Strip "v" prefix from tag name
[[ "${{ github.ref }}" == "refs/tags/"* ]] && VERSION=$(echo $VERSION | sed -e 's/^v//')
[ "$VERSION" == "main" ] && VERSION=develop
[ "$VERSION" == "develop" ] && VERSION=develop
echo "Version: $VERSION"
echo "VERSION=$VERSION" >> "$GITHUB_OUTPUT"
shell: bash
29 changes: 29 additions & 0 deletions .github/workflows/cd.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: CD

on:
workflow_dispatch:
push:
branches:
- proof-of-concept

concurrency:
group: cd

jobs:
build:
runs-on: ubuntu-latest
permissions:
packages: write
contents: read
steps:
- uses: actions/checkout@v3
- name: Get tag
id: version-tag
uses: ./.github/actions/get-version-tag
- name: Build Docker image
uses: ./.github/actions/docker-build
with:
version: ${{ steps.version-tag.outputs.version-tag }}
latest: true
github-token: ${{ secrets.GITHUB_TOKEN }}
docker-image-name: ${{ vars.DOCKER_IMAGE_NAME }}

0 comments on commit ee1a41b

Please sign in to comment.