Skip to content

Commit

Permalink
Change docker-build and release logic
Browse files Browse the repository at this point in the history
Signed-off-by: Oguz Ozturk <[email protected]>
  • Loading branch information
oguzkaganozt committed Feb 18, 2024
1 parent 621e772 commit d26f720
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 36 deletions.
57 changes: 37 additions & 20 deletions .github/actions/docker-build-and-push/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,21 +27,16 @@ runs:
sudo apt-get -y install jq
shell: bash

# workflow_dispatch: latest, release_version
# schedule: date
- name: Set Docker tags
id: set-docker-tags
run: |
tags=()
if [ "${{ github.event_name }}" == "workflow_dispatch" ]; then
if [ "${{ github.event.inputs.publish_packages }}" == "true" ]; then
tags+=("${{ github.event.inputs.release_version }}")
tags+=("latest")
fi
else
tags+=("latest")
if [ "${{ github.event_name }}" == "push" ] && [ "${{ github.ref_type }}" == "tag" ]; then
tags+=("$(echo "${{ github.ref }}" | sed -E 's/.*([vV][0-9]+\.[0-9]+\.[0-9]+).*/\1/')")
fi
tags+=("{{date 'YYYYMMDD'}}")
tags+=("latest")
# Output multiline strings: https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#multiline-strings
EOF=$(dd if=/dev/urandom bs=15 count=1 status=none | base64)
Expand Down Expand Up @@ -73,15 +68,15 @@ runs:
suffix=-devel${{ inputs.tag-suffix }}
- name: Docker meta for runtime
if: ${{ github.event_name == 'workflow_dispatch' }}
if: ${{ github.event_name == 'workflow_dispatch' }} || ( ${{ github.event_name == "push" && github.ref_type == "tag" }} )
id: meta-runtime
uses: docker/metadata-action@v4
with:
images: ghcr.io/${{ github.repository_owner }}/${{ inputs.bake-target }}
tags: ${{ steps.set-docker-tags.outputs.tags }}
bake-target: docker-metadata-action-runtime
flavor: |
latest=${{ github.event.inputs.publish_packages }}
latest=${{ github.event_name == "push" && github.ref_type == "tag" }}
suffix=-runtime${{ inputs.tag-suffix }}
- name: Login to GitHub Container Registry
Expand All @@ -92,8 +87,8 @@ runs:
username: ${{ github.repository_owner }}
password: ${{ github.token }}

- name: Build and Push prebuilt and devel
if: ${{ github.event_name != 'workflow_dispatch' }}
- name: Build and Push - prebuilt and devel
if: ${{ (github.event_name == "push" && github.ref_type == "branch") || github.event_name == "schedule" }}
uses: docker/bake-action@v3
with:
# Checking event_name for https://github.com/autowarefoundation/autoware/issues/2796
Expand All @@ -110,7 +105,7 @@ runs:
${{ inputs.build-args }}
- name: Build and Publish Release to GitHub Container Registry
if: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.publish_packages }}
if: ${{ github.event_name == 'push' && github.ref_type == 'tag' }}
uses: docker/bake-action@v3
with:
push: true
Expand All @@ -124,7 +119,7 @@ runs:
${{ inputs.build-args }}
- name: Build and Save Artifacts
if: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.publish_packages != true}}
if: ${{ github.event_name == 'workflow_dispatch' }}
uses: docker/bake-action@v3
with:
push: false
Expand All @@ -140,13 +135,35 @@ runs:
devel.output=type=docker,dest=/tmp/devel.tar
runtime.output=type=docker,dest=/tmp/runtime.tar
- name: Upload Artifacts
if: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.publish_packages != true }}
- name: Upload Artifacts - prebuilt
if: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.save-artifacts == true }}
uses: actions/upload-artifact@v4
with:
name: prebuilt
path: /tmp/prebuilt.tar
retention-days: 7
compression-level: 6
overwrite: true
if-no-files-found: warn

- name: Upload Artifacts - devel
if: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.save-artifacts == true }}
uses: actions/upload-artifact@v4
with:
name: devel
path: /tmp/devel.tar
retention-days: 7
compression-level: 6
overwrite: true
if-no-files-found: warn

- name: Upload Artifacts - runtime
if: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.save-artifacts == true }}
uses: actions/upload-artifact@v4
with:
name: docker-images
path: /tmp/*.tar
name: runtime
path: /tmp/runtime.tar
retention-days: 7
compression-level: 6
overwrite: true
if-no-files-found: error
if-no-files-found: warn
18 changes: 10 additions & 8 deletions .github/workflows/docker-build-and-push-main-self-hosted.yaml
Original file line number Diff line number Diff line change
@@ -1,23 +1,25 @@
# workflow_dispatch: Build all. No publish to registry; save as tarball.
# schedule: Build only devel and prebuilt. TAGS: date, latest
# push-branch: Build only devel and prebuilt. TAGS: date, latest
# push-tag: Build all. TAGS: version, date, latest

name: docker-build-and-push-main-self-hosted

on:
push:
tags:
- 'adkit-v*.*.*'
branches:
- main
schedule:
- cron: 0 0 1,15 * *
workflow_dispatch:
inputs:
publish_packages:
description: 'Publish packages to Registry(Check, if release)'
save-artifacts:
description: 'Save artifacts to Github Actions'
required: true
default: false
default: true
type: boolean
release_version:
description: 'Release Version(Semver, if release)'
required: false
default: ''
type: string

jobs:
docker-build-and-push-main-self-hosted:
Expand Down
18 changes: 10 additions & 8 deletions .github/workflows/docker-build-and-push-main.yaml
Original file line number Diff line number Diff line change
@@ -1,23 +1,25 @@
# workflow_dispatch: Build all. No publish to registry; save as tarball.
# schedule: Build only devel and prebuilt. TAGS: date, latest
# push-branch: Build only devel and prebuilt. TAGS: date, latest
# push-tag: Build all. TAGS: version, date, latest

name: docker-build-and-push-main

on:
push:
tags:
- 'adkit-v*.*.*'
branches:
- main
schedule:
- cron: 0 0 1,15 * *
workflow_dispatch:
inputs:
publish_packages:
description: 'Publish packages to Registry(Check, if release)'
save-artifacts:
description: 'Save artifacts to Github Actions'
required: true
default: false
default: true
type: boolean
release_version:
description: 'Release Version(Semver, if release)'
required: false
default: ''
type: string

jobs:
docker-build-and-push-main:
Expand Down

0 comments on commit d26f720

Please sign in to comment.