mirror of
https://github.com/hassio-addons/addon-base.git
synced 2025-05-03 18:31:26 +00:00
Add CI based on GitHub Actions (#52)
* Add CI based on GitHub Actions * Prettified Code! * Add basic add-on config * Process add-on lint warnings * Fix QEMU User Static binary conditions * Fix expression * Resolving missing target variable * Add deployment * Cleanup Co-authored-by: frenck <frenck@users.noreply.github.com>
This commit is contained in:
parent
0c3a37057e
commit
139cea17f0
8 changed files with 350 additions and 12 deletions
2
.github/PULL_REQUEST_TEMPLATE.md
vendored
2
.github/PULL_REQUEST_TEMPLATE.md
vendored
|
@ -6,4 +6,4 @@
|
|||
|
||||
> ([Github link][autolink-references] to related issues or pull requests)
|
||||
|
||||
[autolink-references]: https://help.github.com/articles/autolinked-references-and-urls/
|
||||
[autolink-references]: https://help.github.com/articles/autolinked-references-and-urls/
|
||||
|
|
190
.github/workflows/ci.yaml
vendored
Normal file
190
.github/workflows/ci.yaml
vendored
Normal file
|
@ -0,0 +1,190 @@
|
|||
---
|
||||
name: CI
|
||||
|
||||
# yamllint disable-line rule:truthy
|
||||
on:
|
||||
push:
|
||||
pull_request:
|
||||
types:
|
||||
- opened
|
||||
- reopened
|
||||
- synchronize
|
||||
workflow_dispatch:
|
||||
|
||||
jobs:
|
||||
information:
|
||||
name: Gather add-on information
|
||||
runs-on: ubuntu-latest
|
||||
outputs:
|
||||
architectures: ${{ steps.information.outputs.architectures }}
|
||||
build: ${{ steps.information.outputs.build }}
|
||||
slug: ${{ steps.information.outputs.slug }}
|
||||
target: ${{ steps.information.outputs.target }}
|
||||
steps:
|
||||
- name: ⤵️ Check out code from GitHub
|
||||
uses: actions/checkout@v2.3.4
|
||||
- name: 🚀 Run add-on information action
|
||||
id: information
|
||||
uses: frenck/action-addon-information@v1.0.0
|
||||
|
||||
lint-addon:
|
||||
name: Lint Add-on
|
||||
needs:
|
||||
- information
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: ⤵️ Check out code from GitHub
|
||||
uses: actions/checkout@v2.3.4
|
||||
- name: 🚀 Run Add-on Lint
|
||||
uses: frenck/action-addon-linter@v1.1.0
|
||||
with:
|
||||
community: true
|
||||
path: "./${{ needs.information.outputs.target }}"
|
||||
|
||||
lint-hadolint:
|
||||
name: Hadolint
|
||||
needs:
|
||||
- information
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: ⤵️ Check out code from GitHub
|
||||
uses: actions/checkout@v2.3.4
|
||||
- name: 🚀 Run Hadolint
|
||||
uses: brpaz/hadolint-action@v1.3.1
|
||||
with:
|
||||
dockerfile: "./${{ needs.information.outputs.target }}/Dockerfile"
|
||||
|
||||
lint-json:
|
||||
name: JSON Lint
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: ⤵️ Check out code from GitHub
|
||||
uses: actions/checkout@v2.3.4
|
||||
- name: 🚀 Run JQ
|
||||
run: |
|
||||
shopt -s globstar
|
||||
cat **/*.json | jq '.'
|
||||
|
||||
lint-markdown:
|
||||
name: MarkdownLint
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: ⤵️ Check out code from GitHub
|
||||
uses: actions/checkout@v2.3.4
|
||||
- name: 🚀 Run mdl
|
||||
uses: actionshub/markdownlint@2.0.0
|
||||
|
||||
lint-shellcheck:
|
||||
name: Shellcheck
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: ⤵️ Check out code from GitHub
|
||||
uses: actions/checkout@v2.3.4
|
||||
- name: 🚀 Run Shellcheck
|
||||
uses: ludeeus/action-shellcheck@1.0.0
|
||||
env:
|
||||
SHELLCHECK_OPTS: -s bash
|
||||
|
||||
lint-yamllint:
|
||||
name: YAMLLint
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: ⤵️ Check out code from GitHub
|
||||
uses: actions/checkout@v2.3.4
|
||||
- name: 🚀 Run YAMLLint
|
||||
uses: frenck/action-yamllint@v1.0.2
|
||||
|
||||
lint-prettier:
|
||||
name: Prettier
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: ⤵️ Check out code from GitHub
|
||||
uses: actions/checkout@v2.3.4
|
||||
- name: 🚀 Run Prettier
|
||||
uses: creyD/prettier_action@v3.3
|
||||
with:
|
||||
prettier_options: --write **/*.{json,js,md,yaml}
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
|
||||
build:
|
||||
name: Build ${{ matrix.architecture }}
|
||||
needs:
|
||||
- information
|
||||
- lint-addon
|
||||
- lint-hadolint
|
||||
- lint-json
|
||||
- lint-markdown
|
||||
- lint-prettier
|
||||
- lint-shellcheck
|
||||
- lint-yamllint
|
||||
runs-on: ubuntu-latest
|
||||
strategy:
|
||||
matrix:
|
||||
architecture: ${{ fromJson(needs.information.outputs.architectures) }}
|
||||
steps:
|
||||
- name: ⤵️ Check out code from GitHub
|
||||
uses: actions/checkout@v2.3.4
|
||||
- name: 🏗 Set up build cache
|
||||
id: cache
|
||||
uses: actions/cache@v2.1.3
|
||||
with:
|
||||
path: /tmp/.docker-cache
|
||||
key: docker-${{ github.ref }}-${{ matrix.architecture }}-${{ github.sha }}
|
||||
restore-keys: |
|
||||
docker-${{ github.ref }}-${{ matrix.architecture }}
|
||||
- name: 🏗 Set up QEMU
|
||||
uses: docker/setup-qemu-action@v1.0.1
|
||||
- name: 🏗 Set up QEMU User Static for aarch64
|
||||
if: ${{ matrix.architecture == 'aarch64' }}
|
||||
run: |
|
||||
curl -L -s \
|
||||
"https://github.com/hassio-addons/qemu-user-static/releases/download/v5.0.0/qemu-aarch64-static.tar.gz" | \
|
||||
tar zxvf - -C "${{ needs.information.outputs.target }}/rootfs/usr/bin/"
|
||||
- name: 🏗 Set up QEMU User Static for armhf/armv7
|
||||
if: ${{ matrix.architecture == 'armhf' || matrix.architecture == 'armv7' }}
|
||||
run: |
|
||||
curl -L -s \
|
||||
"https://github.com/hassio-addons/qemu-user-static/releases/download/v5.0.0/qemu-arm-static.tar.gz" | \
|
||||
tar zxvf - -C "${{ needs.information.outputs.target }}/rootfs/usr/bin/"
|
||||
- name: 🏗 Set up Docker Buildx
|
||||
uses: docker/setup-buildx-action@v1.1.1
|
||||
- name: ℹ️ Compose build flags
|
||||
id: flags
|
||||
run: |
|
||||
echo "::set-output name=date::$(date +"%Y-%m-%dT%H:%M:%SZ")"
|
||||
from=$(jq --raw-output ".build_from.${{ matrix.architecture }}" "${{ needs.information.outputs.build }}")
|
||||
echo "::set-output name=from::${from}"
|
||||
|
||||
if [[ "${{ matrix.architecture}}" = "amd64" ]]; then
|
||||
echo "::set-output name=platform::linux/amd64"
|
||||
elif [[ "${{ matrix.architecture }}" = "i386" ]]; then
|
||||
echo "::set-output name=platform::linux/386"
|
||||
elif [[ "${{ matrix.architecture }}" = "armhf" ]]; then
|
||||
echo "::set-output name=platform::linux/arm/v6"
|
||||
elif [[ "${{ matrix.architecture }}" = "armv7" ]]; then
|
||||
echo "::set-output name=platform::linux/arm/v7"
|
||||
elif [[ "${{ matrix.architecture }}" = "aarch64" ]]; then
|
||||
echo "::set-output name=platform::linux/arm64/v8"
|
||||
else
|
||||
echo "::error ::Could not determine platform for architecture ${{ matrix.architecture }}"
|
||||
exit 1
|
||||
fi
|
||||
- name: 🚀 Build
|
||||
uses: docker/build-push-action@v2.2.2
|
||||
with:
|
||||
push: false
|
||||
context: ${{ needs.information.outputs.target }}
|
||||
file: ${{ needs.information.outputs.target }}/Dockerfile
|
||||
cache-from: |
|
||||
type=local,src=/tmp/.docker-cache
|
||||
ghcr.io/hassio-addons/${{ needs.information.outputs.slug }}/${{ matrix.architecture }}:edge
|
||||
cache-to: type=local,mode=max,dest=/tmp/.docker-cache
|
||||
platforms: ${{ steps.flags.outputs.platform }}
|
||||
build-args: |
|
||||
BUILD_ARCH=${{ matrix.architecture }}
|
||||
BUILD_DATE=${{ steps.flags.outputs.date }}
|
||||
BUILD_FROM=${{ steps.flags.outputs.from }}
|
||||
BUILD_REF=${{ github.sha }}
|
||||
BUILD_REPOSITORY=${{ github.repository }}
|
||||
BUILD_VERSION=dev
|
138
.github/workflows/deploy.yaml
vendored
Normal file
138
.github/workflows/deploy.yaml
vendored
Normal file
|
@ -0,0 +1,138 @@
|
|||
---
|
||||
name: Deploy
|
||||
|
||||
# yamllint disable-line rule:truthy
|
||||
on:
|
||||
release:
|
||||
types:
|
||||
- published
|
||||
workflow_run:
|
||||
workflows: ["CI"]
|
||||
branches: [main]
|
||||
types:
|
||||
- completed
|
||||
|
||||
jobs:
|
||||
information:
|
||||
if: |
|
||||
github.event_name == 'release'
|
||||
|| (
|
||||
github.event_name == 'workflow_run'
|
||||
&& github.event.workflow_run.conclusion == 'success'
|
||||
)
|
||||
name: ℹ️ Gather add-on information
|
||||
runs-on: ubuntu-latest
|
||||
outputs:
|
||||
architectures: ${{ steps.information.outputs.architectures }}
|
||||
build: ${{ steps.information.outputs.build }}
|
||||
environment: ${{ steps.release.outputs.environment }}
|
||||
slug: ${{ steps.information.outputs.slug }}
|
||||
target: ${{ steps.information.outputs.target }}
|
||||
version: ${{ steps.release.outputs.version }}
|
||||
steps:
|
||||
- name: ⤵️ Check out code from GitHub
|
||||
uses: actions/checkout@v2.3.4
|
||||
- name: 🚀 Run add-on information action
|
||||
id: information
|
||||
uses: frenck/action-addon-information@v1.0.0
|
||||
- name: ℹ️ Gather version and environment
|
||||
id: release
|
||||
run: |
|
||||
sha="${{ github.sha }}"
|
||||
environment="edge"
|
||||
version="${sha:0:7}"
|
||||
if [[ "${{ github.event_name }}" = "release" ]]; then
|
||||
version="${{ github.event.release.tag_name }}"
|
||||
version="${version,,}"
|
||||
version="${version#v}"
|
||||
environment="stable"
|
||||
if [[ "${{ github.event.release.prerelease }}" = "true" ]]; then
|
||||
environment="beta"
|
||||
fi
|
||||
fi
|
||||
|
||||
echo "::set-output name=environment::${environment}"
|
||||
echo "::set-output name=version::${version}"
|
||||
|
||||
deploy:
|
||||
name: 👷 Build & Deploy ${{ matrix.architecture }}
|
||||
needs: information
|
||||
runs-on: ubuntu-latest
|
||||
strategy:
|
||||
matrix:
|
||||
architecture: ${{ fromJson(needs.information.outputs.architectures) }}
|
||||
steps:
|
||||
- name: ⤵️ Check out code from GitHub
|
||||
uses: actions/checkout@v2.3.4
|
||||
- name: 🏗 Set up build cache
|
||||
id: cache
|
||||
uses: actions/cache@v2.1.3
|
||||
with:
|
||||
path: /tmp/.docker-cache
|
||||
key: docker-${{ github.ref }}-${{ matrix.architecture }}-${{ github.sha }}
|
||||
restore-keys: |
|
||||
docker-${{ github.ref }}-${{ matrix.architecture }}
|
||||
- name: 🏗 Set up QEMU
|
||||
uses: docker/setup-qemu-action@v1.0.1
|
||||
- name: 🏗 Set up QEMU User Static for aarch64
|
||||
if: ${{ matrix.architecture == 'aarch64' }}
|
||||
run: |
|
||||
curl -L -s \
|
||||
"https://github.com/hassio-addons/qemu-user-static/releases/download/v5.0.0/qemu-aarch64-static.tar.gz" | \
|
||||
tar zxvf - -C "${{ needs.information.outputs.target }}/rootfs/usr/bin/"
|
||||
- name: 🏗 Set up QEMU User Static for armhf/armv7
|
||||
if: ${{ matrix.architecture == 'armhf' || matrix.architecture == 'armv7' }}
|
||||
run: |
|
||||
curl -L -s \
|
||||
"https://github.com/hassio-addons/qemu-user-static/releases/download/v5.0.0/qemu-arm-static.tar.gz" | \
|
||||
tar zxvf - -C "${{ needs.information.outputs.target }}/rootfs/usr/bin/"
|
||||
- name: 🏗 Set up Docker Buildx
|
||||
uses: docker/setup-buildx-action@v1.1.1
|
||||
- name: ℹ️ Compose build flags
|
||||
id: flags
|
||||
run: |
|
||||
echo "::set-output name=date::$(date +"%Y-%m-%dT%H:%M:%SZ")"
|
||||
from=$(jq --raw-output ".build_from.${{ matrix.architecture }}" "${{ needs.information.outputs.build }}")
|
||||
echo "::set-output name=from::${from}"
|
||||
|
||||
if [[ "${{ matrix.architecture}}" = "amd64" ]]; then
|
||||
echo "::set-output name=platform::linux/amd64"
|
||||
elif [[ "${{ matrix.architecture }}" = "i386" ]]; then
|
||||
echo "::set-output name=platform::linux/386"
|
||||
elif [[ "${{ matrix.architecture }}" = "armhf" ]]; then
|
||||
echo "::set-output name=platform::linux/arm/v6"
|
||||
elif [[ "${{ matrix.architecture }}" = "armv7" ]]; then
|
||||
echo "::set-output name=platform::linux/arm/v7"
|
||||
elif [[ "${{ matrix.architecture }}" = "aarch64" ]]; then
|
||||
echo "::set-output name=platform::linux/arm64/v8"
|
||||
else
|
||||
echo "::error ::Could not determine platform for architecture ${{ matrix.architecture }}"
|
||||
exit 1
|
||||
fi
|
||||
- name: 🏗 Login to GitHub Container Registry
|
||||
uses: docker/login-action@v1.8.0
|
||||
with:
|
||||
registry: ghcr.io
|
||||
username: ${{ secrets.GHCR_USERNAME }}
|
||||
password: ${{ secrets.GHCR_PASSWORD }}
|
||||
- name: 🚀 Build and push
|
||||
uses: docker/build-push-action@v2.2.2
|
||||
with:
|
||||
push: true
|
||||
tags: |
|
||||
ghcr.io/hassio-addons/${{ needs.information.outputs.slug }}/${{ matrix.architecture }}:${{ needs.information.outputs.environment }}
|
||||
ghcr.io/hassio-addons/${{ 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/hassio-addons/${{ needs.information.outputs.slug }}/${{ matrix.architecture }}:edge
|
||||
cache-to: type=local,mode=max,dest=/tmp/.docker-cache
|
||||
platforms: ${{ steps.flags.outputs.platform }}
|
||||
build-args: |
|
||||
BUILD_ARCH=${{ matrix.architecture }}
|
||||
BUILD_DATE=${{ steps.flags.outputs.date }}
|
||||
BUILD_FROM=${{ steps.flags.outputs.from }}
|
||||
BUILD_REF=${{ github.sha }}
|
||||
BUILD_REPOSITORY=${{ github.repository }}
|
||||
BUILD_VERSION=${{ needs.information.outputs.version }}
|
|
@ -26,4 +26,4 @@ Even better: You could submit a pull request with a fix / new feature!
|
|||
the second reviewer to merge it for you.
|
||||
|
||||
[github]: https://github.com/hassio-addons/addon-base/issues
|
||||
[prs]: https://github.com/hassio-addons/addon-base/pulls
|
||||
[prs]: https://github.com/hassio-addons/addon-base/pulls
|
||||
|
|
|
@ -45,12 +45,12 @@ functionality. The format of the log is based on
|
|||
[Keep a Changelog][keepchangelog].
|
||||
|
||||
Releases are based on [Semantic Versioning][semver], and use the format
|
||||
of ``MAJOR.MINOR.PATCH``. In a nutshell, the version will be incremented
|
||||
of `MAJOR.MINOR.PATCH`. In a nutshell, the version will be incremented
|
||||
based on the following:
|
||||
|
||||
- ``MAJOR``: Incompatible or major changes.
|
||||
- ``MINOR``: Backwards-compatible new features and enhancements.
|
||||
- ``PATCH``: Backwards-compatible bugfixes and package updates.
|
||||
- `MAJOR`: Incompatible or major changes.
|
||||
- `MINOR`: Backwards-compatible new features and enhancements.
|
||||
- `PATCH`: Backwards-compatible bugfixes and package updates.
|
||||
|
||||
## Support
|
||||
|
||||
|
|
|
@ -72,6 +72,7 @@ ENTRYPOINT ["/init"]
|
|||
ARG BUILD_DATE
|
||||
ARG BUILD_REF
|
||||
ARG BUILD_VERSION
|
||||
ARG BUILD_REPOSITORY
|
||||
|
||||
# Labels
|
||||
LABEL \
|
||||
|
@ -90,8 +91,8 @@ LABEL \
|
|||
org.opencontainers.image.authors="Franck Nijhof <frenck@addons.community>" \
|
||||
org.opencontainers.image.licenses="MIT" \
|
||||
org.opencontainers.image.url="https://addons.community" \
|
||||
org.opencontainers.image.source="https://github.com/hassio-addons/addon-base" \
|
||||
org.opencontainers.image.documentation="https://github.com/hassio-addons/addon-base/blob/main/README.md" \
|
||||
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.created=${BUILD_DATE} \
|
||||
org.opencontainers.image.revision=${BUILD_REF} \
|
||||
org.opencontainers.image.version=${BUILD_VERSION}
|
||||
|
|
|
@ -1,12 +1,9 @@
|
|||
{
|
||||
"image": "hassioaddons/base-{arch}",
|
||||
"squash": false,
|
||||
"build_from": {
|
||||
"aarch64": "arm64v8/alpine:3.12.1",
|
||||
"amd64": "amd64/alpine:3.12.1",
|
||||
"armhf": "arm32v6/alpine:3.12.1",
|
||||
"armv7": "arm32v7/alpine:3.12.1",
|
||||
"i386": "i386/alpine:3.12.1"
|
||||
},
|
||||
"args": {}
|
||||
}
|
||||
}
|
||||
|
|
12
base/config.json
Normal file
12
base/config.json
Normal file
|
@ -0,0 +1,12 @@
|
|||
{
|
||||
"name": "Base Image",
|
||||
"version": "dev",
|
||||
"slug": "base",
|
||||
"description": "Docker base images used by Home Assistant Community Add-ons.",
|
||||
"url": "https://github.com/hassio-addons/addon-base",
|
||||
"arch": ["aarch64", "amd64", "armhf", "armv7", "i386"],
|
||||
"options": {},
|
||||
"schema": {},
|
||||
"boot": "auto",
|
||||
"startup": "application"
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue