Skip to content

Commit

Permalink
refactor(everything)!: universal repo a. github actions
Browse files Browse the repository at this point in the history
* anki-sync-server now named anki-sync-server not oci-anki-sync
* universal structure for more images to come
  * every software has own directory
  * use strategy.matrix in gh actions
  * split readme into one project wide and one for the software
* multi-arch builds
  * convert docker-style to cargo-style
  * cross-compile on linux/amd64
  * install rustup target (not included because different buildplatform than target)
  * install c (gcc) compiler (reason: same as rustup)

BREAKING CHANGE: new container name
Signed-off-by: Frederik Zorn <federdaemn@mail.de>
  • Loading branch information
z0rrn committed Oct 29, 2023
1 parent 03e0d51 commit d7f6f16
Show file tree
Hide file tree
Showing 13 changed files with 312 additions and 163 deletions.
12 changes: 0 additions & 12 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,3 @@ updates:
# prefix all commit messages with "chore(deps): "
commit-message:
prefix: "chore(deps): "

# Create a group of dependencies to be updated together in one pull request
groups:
# Update all dependencies from redhat-actions together
redhat-actions:
patterns:
- "redhat-actions/*"

# Update all non-specified dependencies together
all:
patterns:
- "*"
124 changes: 83 additions & 41 deletions .github/workflows/container-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#
# SPDX-License-Identifier: Apache-2.0

name: 'Build and push anki-sync container'
name: 'Build and push container'

# run workflow on every branch, only upload on main (allow manual trigger)
on: [push, pull_request, workflow_dispatch]
Expand All @@ -14,6 +14,12 @@ jobs:

# use ubuntu as runner
runs-on: ubuntu-latest

strategy:
matrix:
# build for every application
app:
- anki-sync-server

permissions:
packages: write
Expand All @@ -26,30 +32,33 @@ jobs:
- name: Setup yq
uses: mikefarah/yq@v4

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Setup oras
if: github.event_name != 'pull_request' && github.ref == 'refs/heads/main'
uses: oras-project/setup-oras@v1

- name: Login to GitHub Container Registry
uses: redhat-actions/podman-login@v1
uses: docker/login-action@v3
if: github.event_name != 'pull_request' && github.ref == 'refs/heads/main'
with:
registry: ghcr.io
username: federdaemn
password: ${{ secrets.GITHUB_TOKEN }}

- name: Login to DockerHub
uses: redhat-actions/podman-login@v1
uses: docker/login-action@v3
if: github.event_name != 'pull_request' && github.ref == 'refs/heads/main'
with:
registry: docker.io
username: federdaemn
password: ${{ secrets.DOCKER_TOKEN }}

- name: Set outputs for later use
id: set-op
run: |
# extract version from ./values.yml
echo "anki-version=$(yq '.version.anki-version' ./values.yml)" \
echo "software-version=$(yq '.version.software-version' ./${{ matrix.app }}/values.yml)" \
>> $GITHUB_OUTPUT
# get current date+time
Expand All @@ -58,59 +67,92 @@ jobs:
# get current date+time docker tag compatible
echo "time-docker=$(date --utc +'%Y-%m-%dt%H-%M-%Sz')" >> $GITHUB_OUTPUT
- name: Build image
id: build_image
uses: redhat-actions/buildah-build@v2
- name: Build and push image in production
uses: docker/build-push-action@v5
if: github.event_name != 'pull_request' && github.ref == 'refs/heads/main'
with:
# directly push image
push: true

# use local repository
context: .

# which containerfile to build from
containerfiles: |
./containerfile
file: |
./${{ matrix.app }}/containerfile
# set labels to append to the image
# build args to pass to the build
build-args: |
software_version=${{ steps.set-op.outputs.software-version }}
# build for many platforms at the same time
platforms: |
linux/amd64
linux/arm64
linux/arm/v7
linux/arm/v6
# set general labels to append to all images
labels: |
# opencontainer labels specified
# https://github.com/opencontainers/image-spec/blob/main/annotations.md#pre-defined-annotation-keys
org.opencontainers.image.title=oci-anki-sync
org.opencontainers.image.description=Anki sync server (anki-sync-server) in a container
org.opencontainers.image.authors=Frederik Zorn <federdaemnmail.de>
org.opencontainers.image.title="${{ matrix.app }}"
org.opencontainers.image.authors=Frederik Zorn <federdaemn@mail.de>
org.opencontainers.image.created=${{ steps.set-op.outputs.time }}
org.opencontainers.image.version=${{ steps.set-op.outputs.anki-version }}
org.opencontainers.image.licenses=AGPL-3.0-or-later
org.opencontainers.image.url=https://github.com/federdaemn/oci-anki-sync
org.opencontainers.image.source=https://github.com/federdaemn/oci-anki-sync
org.opencontainers.image.version=${{ steps.set-op.outputs.software-version }}
org.opencontainers.image.source=https://github.com/federdaemn/container
# artfifacthub labels specified
# https://artifacthub.io/docs/topics/repositories/container-images/#image-metadata
io.artifacthub.package.readme-url=https://raw.githubusercontent.com/federdaemn/oci-anki-sync/main/README.md
io.artifacthub.package.readme-url=https://raw.githubusercontent.com/federdaemn/container/main/${{ matrix.app }}/README.md
io.artifacthub.package.maintainers=[{"name":"federdaemn","email":"federdaemn@mail.de"}]
io.artifacthub.package.keywords=anki,sync,server,anki-sync-server,anki-sync
io.artifacthub.package.logo-url=https://raw.githubusercontent.com/federdaemn/oci-anki-sync/main/imgs/anki/logo.png
io.artifacthub.package.alternative-locations=docker.io/federdaemn/oci-anki-sync
# build args to pass to the build
build-args: |
anki_version=${{ steps.set-op.outputs.anki-version }}
io.artifacthub.package.logo-url=https://raw.githubusercontent.com/federdaemn/container/main/${{ matrix.app }}/imgs/ah-logo.png
io.artifacthub.package.alternative-locations=docker.io/federdaemn/${{ matrix.app }}
# tags to build the image with
tags: |
ghcr.io/federdaemn/oci-anki-sync:latest
ghcr.io/federdaemn/oci-anki-sync:${{ steps.set-op.outputs.anki-version }}
ghcr.io/federdaemn/oci-anki-sync:${{ steps.set-op.outputs.time-docker }}
docker.io/federdaemn/oci-anki-sync:latest
docker.io/federdaemn/oci-anki-sync:${{ steps.set-op.outputs.anki-version }}
docker.io/federdaemn/oci-anki-sync:${{ steps.set-op.outputs.time-docker }}
- name: Push image
uses: redhat-actions/push-to-registry@v2
if: github.event_name != 'pull_request' && github.ref == 'refs/heads/main'
with:
tags: ${{ steps.build_image.outputs.tags }}
ghcr.io/federdaemn/${{ matrix.app }}:latest
ghcr.io/federdaemn/${{ matrix.app }}:${{ steps.set-op.outputs.software-version }}
ghcr.io/federdaemn/${{ matrix.app }}:${{ steps.set-op.outputs.time-docker }}
docker.io/federdaemn/${{ matrix.app }}:latest
docker.io/federdaemn/${{ matrix.app }}:${{ steps.set-op.outputs.software-version }}
docker.io/federdaemn/${{ matrix.app }}:${{ steps.set-op.outputs.time-docker }}
# use oras to push artifacthub metadata to ghcr.io
- name: Build image in testing only
uses: docker/build-push-action@v5
if: github.event_name == 'pull_request' && github.ref != 'refs/heads/main'
with:
# do not push image
push: false

# use local repository
context: .

# which containerfile to build from
file: |
./${{ matrix.app }}/containerfile
# build args to pass to the build
build-args: |
software_version=${{ steps.set-op.outputs.software-version }}
# build for many platforms at the same time
platforms: |
linux/amd64
linux/arm64
linux/arm/v7
linux/arm/v6
# use oras to push artifacthub metadata to registries
# source: https://artifacthub.io/docs/topics/repositories/container-images/#repository-metadata
- name: Push metadata
if: github.event_name != 'pull_request' && github.ref == 'refs/heads/main'
run: |
oras push \
ghcr.io/federdaemn/oci-anki-sync:artifacthub.io \
ghcr.io/federdaemn/${{ matrix.app }}:artifacthub.io \
--config /dev/null:application/vnd.cncf.artifacthub.config.v1+yaml \
${{ matrix.app }}/artifacthub-repo.yml:application/vnd.cncf.artifacthub.repository-metadata.layer.v1.yaml
oras push \
docker.io/federdaemn/${{ matrix.app }}:artifacthub.io \
--config /dev/null:application/vnd.cncf.artifacthub.config.v1+yaml \
artifacthub-repo.yml:application/vnd.cncf.artifacthub.repository-metadata.layer.v1.yaml
${{ matrix.app }}/artifacthub-repo.yml:application/vnd.cncf.artifacthub.repository-metadata.layer.v1.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#
# SPDX-License-Identifier: Apache-2.0

name: 'Update anki version in values.yml'
name: 'Update software version in values.yml (GH API)'

# run workflow every monday at 00:00 UTC
on:
Expand All @@ -12,11 +12,17 @@ on:

jobs:
update-version:
name: Update anki version in values.yml
name: Update software version in values.yml

# use ubuntu as runner
runs-on: ubuntu-latest

strategy:
matrix:
# check for every application using github releases
app:
- anki-sync-server

# add GH token to secrets as GH_ANKI_VERSION_TOKEN
# with write access to repository
# to allow workflow to write to repository
Expand All @@ -34,10 +40,12 @@ jobs:
- name: Setup yq
uses: mikefarah/yq@v4

- name: Get current anki version
id: anki-version
- name: Get current software version and correct repo
id: set-op
run: |
echo "anki-version=$(yq '.version.anki-version' ./values.yml)" \
echo "software-version=$(yq '.version.software-version' ./${{ matrix.app }}/values.yml)" \
>> $GITHUB_OUTPUT
echo "gh-repo=$(yq '.repository.software-repository' ./${{ matrix.app }}/values.yml)" \
>> $GITHUB_OUTPUT
- name: Fetch GH API and get tag_name from latest release
Expand All @@ -47,24 +55,24 @@ jobs:
tag_name=$(curl -L \
-H "Accept: application/vnd.github+json" \
-H "X-GitHub-Api-Version: 2022-11-28" \
https://api.github.com/repos/ankitects/anki/releases/latest |\
https://api.github.com/repos/${{ steps.set-op.outputs.gh-repo }}/releases/latest |\
yq '.tag_name')
# set output for later use
echo "name=$tag_name" >> $GITHUB_OUTPUT
- name: Set new anki version in values.yml
if: ${{ steps.anki-version.outputs.anki-version != steps.get-release.outputs.name }}
- name: Set new software version in values.yml
if: ${{ steps.set-op.outputs.software-version != steps.get-release.outputs.name }}
run: |
yq -i '.version.anki-version = "${{ steps.get-release.outputs.name }}"' \
./values.yml
yq -i '.version.software-version = "${{ steps.get-release.outputs.name }}"' \
./${{ matrix.app }}/values.yml
- name: Set up git email/name a. commit changes
if: ${{ steps.anki-version.outputs.anki-version != steps.get-release.outputs.name }}
if: ${{ steps.set-op.outputs.software-version != steps.get-release.outputs.name }}
run: |
git config user.name federdaemn-bot
git config user.email federdaemn@mail.de
git add ./values.yml
git commit -m "chore(anki): bump anki version to ${{ steps.get-release.outputs.name }}" \
git add ./${{ matrix.app }}/values.yml
git commit -m "chore(${{ matrix.app }}): bump version to ${{ steps.get-release.outputs.name }}" \
-m "Signed-off-by: github-actions in the name of Frederik Zorn <federdaemn@mail.de>"
git push origin main
6 changes: 3 additions & 3 deletions .reuse/dep5
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/
Upstream-Name: oci-anki-sync
Upstream-Name: container
Upstream-Contact: Frederik Zorn <federdaemn@mail.de>
Source: https://github.com/federdaemn/oci-anki-sync
Source: https://github.com/federdaemn/container

# Sample paragraph, commented out:
#
Expand All @@ -13,6 +13,6 @@ Files: .vscode/*
Copyright: 2023 Frederik Zorn <federdaemn@mail.de>
License: Apache-2.0

Files: imgs/anki/logo.png
Files: anki-sync-server/imgs/ah-logo.png
Copyright: Alex Fraser https://apps.ankiweb.net/
License: LicenseRef-anki-logo
55 changes: 22 additions & 33 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,56 +4,45 @@ SPDX-FileCopyrightText: 2023 Frederik Zorn <federdaemn@mail.de>
SPDX-License-Identifier: Apache-2.0
-->

# oci-anki-sync (anki-sync-server docker container) repository
# container repository

This contains a Dockerfile and Ci scripts to build a container image for
[Anki Sync Server](https://apps.ankiweb.net/) using a scratch image as base
image.
This contains dockerfiles and CI/CD scripts to build container images for
various tools.

## Updates and Versions
## Hosted Images

Currently I have these images built. Read more in the readme of the respective
folder.

* The container is auto-updated every Monday whenever a new version of anki is
released. This is done by a GitHub Action and happens without any manual
intervention or review.
* The actions are also auto-updated through dependabot.
* The image which is used to build is always the latest version of Debian Linux.
| software | official | auto-updates |
| --- | --- | --- |
| anki-sync-server | No | Yes |

## Updates and Versions

Result: The container is always up-to-date (at least after every Monday) and I
can forget this project exists :).
I try to set up auto-updates for every container but it's not always possible.
This is documented in the readme's of the folders.

## Hosting

### Git

This project is hosted on [GitHub](https://github.com) at the
[federdaemn/oci-anki-sync](https://github.com/federdaemn/oci-anki-sync) project.
[federdaemn/containers](https://github.com/federdaemn/containers) project. Every
tool has it's own folder with instructions.

### Container Registry

The container images are hosted on
[GitHub Container Registry](https://github.com/federdaemn/oci-anki-sync/pkgs/container/oci-anki-sync)
(recommended) and on
[Docker Hub](https://hub.docker.com/r/federdaemn/oci-anki-sync) for redundancy.
Additionally, the container images are also listed on
[artifacthub.io](https://artifacthub.io) with the package name
[`oci-anki-sync`](https://artifacthub.io/packages/container/oci-anki-sync/oci-anki-sync).

There are three tags available on both registries:

* `latest`: Always the latest version of anki.
* `<anki-version>`: The version specified of anki.
* `<time-of-build>`: The exact time(+date) when the container was built
(using (`date` syntax): %Y-%m-%dt%H-%M-%Sz).

## Setup

* See SETUP.md for detailed instructions.
[GitHub Container Registry](https://github.com/features/packages) (recommended)
and on [Docker Hub](https://hub.docker.com/) for redundancy. Additionally, the
images are listed on [Artifact Hub](https://artifacthub.io).

## Contributing

* Contributions for newer versions or files are gracefully accepted but the
scope is to only generate an auto-updating docker/oci container.
* Please try to wrap lines at 80 characters.
* Contributions for newer versions or files are gracefully accepted. Even things
like small speed improvements are helpfull.
* Please try to wrap all lines at 80 characters.

## License

Expand Down
Loading

0 comments on commit d7f6f16

Please sign in to comment.