Skip to content

Commit

Permalink
Added github workflow action
Browse files Browse the repository at this point in the history
  • Loading branch information
krobertson committed Mar 25, 2024
1 parent 180c522 commit ade7204
Showing 1 changed file with 86 additions and 0 deletions.
86 changes: 86 additions & 0 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
---
# yaml-language-server: $schema=https://json.schemastore.org/github-workflow.json
name: Build Image

on:
workflow_dispatch:
push:
tags:
- "v*.*.*"
branches:
- main
pull_request:
types:
- opened
- reopened
schedule:
- cron: "0 0 * * 6"

env:
REGISTRY_IMAGE: ghcr.io/${{ github.repository }}

jobs:
build:
runs-on: ubuntu-latest
if: "!contains(github.event.head_commit.message, '[ci-skip]')"
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Prepare
id: prep
run: |
VERSION=dev
if [[ $GITHUB_REF == refs/tags/v* ]]; then
VERSION=${GITHUB_REF#refs/tags/}
fi
# v1.0.0
TAGS="${REGISTRY_IMAGE}:${VERSION}"
# v1.0.0,v1
TAGS="${TAGS},${REGISTRY_IMAGE}:${VERSION%%.*}"
if [[ $VERSION =~ ^v[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ ]]; then
# :v1.0.0,:v1,:latest
TAGS="${TAGS},${REGISTRY_IMAGE}:latest"
fi
echo ::set-output name=tags::${TAGS}
if [ "${{github.event_name}}" == "pull_request" ]; then
echo ::set-output name=push::false
echo ::set-output name=cache_from::"type=registry,ref=${REGISTRY_IMAGE}:buildcache"
echo ::set-output name=cache_to::""
else
echo ::set-output name=push::true
echo ::set-output name=cache_from::"type=registry,ref=${REGISTRY_IMAGE}:buildcache"
echo ::set-output name=cache_to::"type=registry,ref=${REGISTRY_IMAGE}:buildcache,mode=max"
fi
echo ::set-output name=github_server_url::"${GITHUB_SERVER_URL}"
- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v3

- name: Login to GitHub Container Registry
if: github.event_name != 'pull_request'
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Build and Push
id: docker_build
uses: docker/build-push-action@v5
with:
builder: ${{ steps.buildx.outputs.name }}
context: .
file: ./Dockerfile
platforms: linux/amd64,linux/arm64
push: ${{ steps.prep.outputs.push }}
tags: ${{ steps.prep.outputs.tags }}
build-args: |
IMAGE_SOURCE=${{ steps.prep.outputs.github_server_url }}/${{ github.repository }}
cache-from: ${{ steps.prep.outputs.cache_from }}
cache-to: ${{ steps.prep.outputs.cache_to }}

- name: Image digest
run: echo ${{ steps.docker_build.outputs.digest }}

0 comments on commit ade7204

Please sign in to comment.