Skip to content

Commit

Permalink
ci: improve build workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
jcwillox committed Jun 10, 2024
1 parent 615b101 commit 2d50292
Show file tree
Hide file tree
Showing 7 changed files with 289 additions and 88 deletions.
137 changes: 137 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
name: "CI"

on:
push:
branches:
- "main"
- "feat**"
tags-ignore:
- "**"
pull_request:
workflow_dispatch:

concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true

jobs:
information:
name: "Gather add-on information"
runs-on: ubuntu-latest
outputs:
architectures: ${{ steps.information.outputs.architectures }}
base_image_signer: ${{ steps.information.outputs.codenotary_base_image }}
build: ${{ steps.information.outputs.build }}
description: ${{ steps.information.outputs.description }}
name: ${{ steps.information.outputs.name }}
slug: ${{ steps.override.outputs.slug }}
target: ${{ steps.information.outputs.target }}
steps:
- name: "⤵️ Check out code from GitHub"
uses: actions/checkout@v4

- name: "🚀 Run add-on information action"
id: information
uses: frenck/[email protected]

- name: "🚀 Process possible slug override"
id: override
run: |
echo "slug=hassio-rclone-backup" >> "$GITHUB_OUTPUT"
lint-addon:
name: Lint Add-on
needs:
- information
runs-on: ubuntu-latest
steps:
- name: ⤵️ Check out code from GitHub
uses: actions/checkout@v4
- name: 🚀 Run Add-on Lint
uses: frenck/[email protected]
with:
community: false
path: "./${{ needs.information.outputs.target }}"

build:
name: "Build ${{ matrix.architecture }}"
needs:
- information
- lint-addon
runs-on: ubuntu-latest
strategy:
matrix:
architecture: ${{ fromJson(needs.information.outputs.architectures) }}
steps:
- name: "⤵️ Check out code from GitHub"
uses: actions/checkout@v4

- name: "🏗 Set up build cache"
id: cache
uses: actions/[email protected]
with:
path: /tmp/.docker-cache
key: docker-${{ matrix.architecture }}-${{ github.sha }}
restore-keys: |
docker-${{ matrix.architecture }}
- name: "🏗 Set up QEMU"
uses: docker/[email protected]

- name: "🏗 Set up Docker Buildx"
uses: docker/[email protected]

- name: "ℹ️ Compose build flags"
id: flags
run: |
echo "date=$(date +"%Y-%m-%dT%H:%M:%SZ")" >> "$GITHUB_OUTPUT"
from=$(yq --no-colors eval ".build_from.${{ matrix.architecture }}" "${{ needs.information.outputs.build }}")
echo "from=${from}" >> "$GITHUB_OUTPUT"
if [[ "${{ matrix.architecture}}" = "amd64" ]]; then
echo "platform=linux/amd64" >> "$GITHUB_OUTPUT"
elif [[ "${{ matrix.architecture }}" = "i386" ]]; then
echo "platform=linux/386" >> "$GITHUB_OUTPUT"
elif [[ "${{ matrix.architecture }}" = "armhf" ]]; then
echo "platform=linux/arm/v6" >> "$GITHUB_OUTPUT"
elif [[ "${{ matrix.architecture }}" = "armv7" ]]; then
echo "platform=linux/arm/v7" >> "$GITHUB_OUTPUT"
elif [[ "${{ matrix.architecture }}" = "aarch64" ]]; then
echo "platform=linux/arm64/v8" >> "$GITHUB_OUTPUT"
else
echo "::error ::Could not determine platform for architecture ${{ matrix.architecture }}"
exit 1
fi
- name: "⤵️ Download base image"
if: steps.flags.outputs.from != 'null'
run: docker pull "${{ steps.flags.outputs.from }}"

- name: "🚀 Build"
uses: docker/[email protected]
with:
push: false
context: ${{ needs.information.outputs.target }}
file: ${{ needs.information.outputs.target }}/Dockerfile
cache-from: |
type=local,src=/tmp/.docker-cache
ghcr.io/${{ github.repository_owner }}/${{ needs.information.outputs.slug }}/${{ matrix.architecture }}:edge
cache-to: type=local,mode=max,dest=/tmp/.docker-cache-new
platforms: ${{ steps.flags.outputs.platform }}
build-args: |
BUILD_ARCH=${{ matrix.architecture }}
BUILD_DATE=${{ steps.flags.outputs.date }}
BUILD_DESCRIPTION=${{ needs.information.outputs.description }}
BUILD_FROM=${{ steps.flags.outputs.from }}
BUILD_NAME=${{ needs.information.outputs.name }}
BUILD_REF=${{ github.sha }}
BUILD_REPOSITORY=${{ github.repository }}
BUILD_VERSION=edge
# This ugly bit is necessary, or our cache will grow forever...
# Well until we hit GitHub's limit of 5GB :)
# https://github.com/docker/build-push-action/issues/252
# https://github.com/moby/buildkit/issues/1896
- name: "🚚 Swap build cache"
run: |
rm -rf /tmp/.docker-cache
mv /tmp/.docker-cache-new /tmp/.docker-cache
137 changes: 137 additions & 0 deletions .github/workflows/deploy.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
name: "Deploy"

concurrency:
group: queue

on:
release:
types: [published]

jobs:
information:
name: "ℹ️ Gather add-on information"
runs-on: ubuntu-latest
outputs:
architectures: ${{ steps.information.outputs.architectures }}
base_image_signer: ${{ steps.information.outputs.codenotary_base_image }}
build: ${{ steps.information.outputs.build }}
description: ${{ steps.information.outputs.description }}
environment: ${{ steps.release.outputs.environment }}
name: ${{ steps.information.outputs.name }}
signer: ${{ steps.information.outputs.codenotary_signer }}
slug: ${{ steps.override.outputs.slug }}
target: ${{ steps.information.outputs.target }}
version: ${{ steps.release.outputs.version }}
steps:
- name: "Checkout the repository"
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: "🚀 Run add-on information action"
id: information
uses: frenck/[email protected]

- name: "🚀 Process possible slug override"
id: override
run: |
echo "slug=hassio-rclone-backup" >> "$GITHUB_OUTPUT"
- name: "ℹ️ Gather version and environment"
id: release
run: |
version="${{ github.event.release.tag_name }}"
version="${version,,}"
version="${version#v}"
echo "version=${version}" >> "$GITHUB_OUTPUT"
deploy:
name: "👷 Build & Deploy ${{ matrix.architecture }}"
needs: information
runs-on: ubuntu-latest
strategy:
matrix:
architecture: ${{ fromJson(needs.information.outputs.architectures) }}
steps:
- name: "Checkout the repository"
uses: actions/checkout@v4

- name: "🏗 Set up build cache"
id: cache
uses: actions/[email protected]
with:
path: /tmp/.docker-cache
key: docker-${{ matrix.architecture }}-${{ github.sha }}
restore-keys: |
docker-${{ matrix.architecture }}
- name: "🏗 Set up QEMU"
uses: docker/[email protected]

- name: "🏗 Set up Docker Buildx"
uses: docker/[email protected]

- name: "ℹ️ Compose build flags"
id: flags
run: |
echo "date=$(date +"%Y-%m-%dT%H:%M:%SZ")" >> "$GITHUB_OUTPUT"
from=$(yq --no-colors eval ".build_from.${{ matrix.architecture }}" "${{ needs.information.outputs.build }}")
echo "from=${from}" >> "$GITHUB_OUTPUT"
if [[ "${{ matrix.architecture}}" = "amd64" ]]; then
echo "platform=linux/amd64" >> "$GITHUB_OUTPUT"
elif [[ "${{ matrix.architecture }}" = "i386" ]]; then
echo "platform=linux/386" >> "$GITHUB_OUTPUT"
elif [[ "${{ matrix.architecture }}" = "armhf" ]]; then
echo "platform=linux/arm/v6" >> "$GITHUB_OUTPUT"
elif [[ "${{ matrix.architecture }}" = "armv7" ]]; then
echo "platform=linux/arm/v7" >> "$GITHUB_OUTPUT"
elif [[ "${{ matrix.architecture }}" = "aarch64" ]]; then
echo "platform=linux/arm64/v8" >> "$GITHUB_OUTPUT"
else
echo "::error ::Could not determine platform for architecture ${{ matrix.architecture }}"
exit 1
fi
- name: "Login to GitHub Container Registry"
uses: docker/[email protected]
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: "⤵️ Download base image"
if: steps.flags.outputs.from != 'null'
run: docker pull "${{ steps.flags.outputs.from }}"

- name: "🚀 Build"
uses: docker/[email protected]
with:
push: true
tags: |
ghcr.io/${{ github.repository_owner }}/${{ needs.information.outputs.slug }}/${{ matrix.architecture }}:latest
ghcr.io/${{ github.repository_owner }}/${{ needs.information.outputs.slug }}/${{ matrix.architecture }}:${{ needs.information.outputs.version }}
context: ${{ needs.information.outputs.target }}
file: ${{ needs.information.outputs.target }}/Dockerfile
cache-from: |
type=local,src=/tmp/.docker-cache
ghcr.io/${{ github.repository_owner }}/${{ needs.information.outputs.slug }}/${{ matrix.architecture }}:edge
cache-to: type=local,mode=max,dest=/tmp/.docker-cache-new
platforms: ${{ steps.flags.outputs.platform }}
build-args: |
BUILD_ARCH=${{ matrix.architecture }}
BUILD_DATE=${{ steps.flags.outputs.date }}
BUILD_DESCRIPTION=${{ needs.information.outputs.description }}
BUILD_FROM=${{ steps.flags.outputs.from }}
BUILD_NAME=${{ needs.information.outputs.name }}
BUILD_REF=${{ github.sha }}
BUILD_REPOSITORY=${{ github.repository }}
BUILD_VERSION=${{ needs.information.outputs.version }}
# This ugly bit is necessary, or our cache will grow forever...
# Well until we hit GitHub's limit of 5GB :)
# https://github.com/docker/build-push-action/issues/252
# https://github.com/moby/buildkit/issues/1896
- name: "🚚 Swap build cache"
run: |
rm -rf /tmp/.docker-cache
mv /tmp/.docker-cache-new /tmp/.docker-cache
44 changes: 0 additions & 44 deletions .github/workflows/publish.yaml

This file was deleted.

35 changes: 0 additions & 35 deletions .github/workflows/test.yaml

This file was deleted.

21 changes: 15 additions & 6 deletions rclone_backup/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,12 @@ FROM $BUILD_FROM

# Build arguments
ARG BUILD_ARCH
ARG BUILD_NAME
ARG BUILD_DATE
ARG BUILD_DESCRIPTION
ARG BUILD_NAME
ARG BUILD_REF
ARG BUILD_REPOSITORY
ARG BUILD_SHA
ARG BUILD_VERSION

ENV LANG C.UTF-8
# renovate: datasource=github-releases depName=rclone packageName=rclone/rclone
Expand Down Expand Up @@ -81,13 +83,20 @@ RUN if [ "${BUILD_ARCH}" = "armhf" ]; then \

# Labels
LABEL \
io.hass.name="${BUILD_NAME}" \
io.hass.description="${BUILD_DESCRIPTION}" \
io.hass.arch="${BUILD_ARCH}" \
io.hass.type="addon" \
io.hass.version=${BUILD_VERSION} \
maintainer="Josh Willox" \
org.opencontainers.image.title="${BUILD_NAME}" \
org.opencontainers.image.description="${BUILD_DESCRIPTION}" \
org.opencontainers.image.vendor="" \
org.opencontainers.image.authors="Josh Willox" \
org.opencontainers.image.licenses="MIT" \
org.opencontainers.image.url="https://github.com/${BUILD_REPOSITORY}" \
org.opencontainers.image.source="https://github.com/${BUILD_REPOSITORY}" \
org.opencontainers.image.documentation="https://github.com/${BUILD_REPOSITORY}/blob/main/README.md" \
org.opencontainers.image.revision=${BUILD_SHA} \
org.opencontainers.image.authors="" \
org.opencontainers.image.vendor="" \
maintainer=""
org.opencontainers.image.created=${BUILD_DATE} \
org.opencontainers.image.revision=${BUILD_REF} \
org.opencontainers.image.version=${BUILD_VERSION}
Loading

0 comments on commit 2d50292

Please sign in to comment.