Skip to content

Commit

Permalink
Automated ARM64 builds using GitHub Actions (#3)
Browse files Browse the repository at this point in the history
* feat: Automated ARM64 builds using GitHub Actions

* WIP continued

* WIP

* Add --load

* Specify the platform in the Tutor build step

* Build both nightly and regular Tutor versions

* Build the full Open edX image, and do it every day

* We don't need to use the "-oracle" tag for MySQL on ARM anymore
  • Loading branch information
bradenmacdonald authored Apr 19, 2023
1 parent 2d35230 commit bc941a7
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 11 deletions.
48 changes: 48 additions & 0 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
name: Build ARM64 Tutor Docker images

on:
# Run every day:
schedule:
- cron: "0 0 * * *"
# Run on all pull requests against the main branch
pull_request:
branches: [ main ]

jobs:
build-openedx-images:
runs-on: ubuntu-latest
strategy:
matrix:
tutor_version: [master, nightly]
steps:
- uses: actions/checkout@v3
- name: Set up QEMU for cross-platform builds
uses: docker/setup-qemu-action@v2
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
with:
# This doesn't seem to have any effect but we may as well specify it.
platforms: linux/arm64/v8
# (What _does_ have effect is passing --platform in the build command,
# which this plugin does using a filter if the environment variable
# TUTOR_ARM64_FORCE_BUILDX_ARM64 is set.)
- name: Check out Tutor
run: git clone --branch ${{ matrix.tutor_version }} https://github.com/overhangio/tutor
- name: Install tutor
run: pip install -e ./tutor
- name: Install this ARM64 plugin
run: pip install -e .
- name: Enable this ARM64 plugin
run: tutor plugins enable arm64
- name: Generate Tutor Config
run: tutor config save
- name: Log in to registry
run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u $ --password-stdin
- name: Build openedx image
run: TUTOR_ARM64_FORCE_BUILDX_ARM64=true tutor images build openedx
- name: Build openedx-permissions image
run: TUTOR_ARM64_FORCE_BUILDX_ARM64=true tutor images build permissions
- name: Push openedx image
run: tutor images push openedx
- name: Push openedx-permissions image
run: tutor images push permissions
2 changes: 1 addition & 1 deletion tutor_arm64/__about__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.1.0"
__version__ = "0.2.0"
27 changes: 17 additions & 10 deletions tutor_arm64/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,9 @@
import pkg_resources

from tutor import hooks
from tutor.__about__ import __version_suffix__ as tutor_version_suffix

from .__about__ import __version__

# We currently do not have a CI pipeline set up to build an ARM image for every
# new Tutor release automatically, so for now we have to settle for grabbing the
# latest image of the right type (either nightly or regular)
DOCKER_IMAGE_TAG = tutor_version_suffix or "latest"

################# Configuration
config = {
"defaults": {
Expand All @@ -25,16 +19,29 @@
# Note: For Maple and earlier, MySQL 8 won't work so "mariadb:10.4" can be used; it also has ARM support.
# If you are upgrading from a previous version of this plugin which used mariadb, you may need to override this
# setting to use "mariadb:10.4" so that you'll still have the same MySQL data.
"DOCKER_IMAGE_MYSQL": "mysql:8.0-oracle",
"DOCKER_IMAGE_MYSQL": "docker.io/mysql:8.0",
# The official overhang.io docker repo doesn't have arm64 images so we
# need to use a separate repo that's related to this plugin, which does:
"DOCKER_IMAGE_OPENEDX": "docker.io/opencraft/openedx-arm64:" + DOCKER_IMAGE_TAG,
"DOCKER_IMAGE_OPENEDX_DEV": "docker.io/opencraft/openedx-arm64-dev:" + DOCKER_IMAGE_TAG,
"DOCKER_IMAGE_PERMISSIONS": "docker.io/opencraft/openedx-permissions-arm64:" + DOCKER_IMAGE_TAG,
"DOCKER_IMAGE_OPENEDX": "ghcr.io/open-craft/openedx-arm64:{{ TUTOR_VERSION }}",
"DOCKER_IMAGE_OPENEDX_DEV": "ghcr.io/open-craft/openedx-arm64-dev:{{ TUTOR_VERSION }}",
"DOCKER_IMAGE_PERMISSIONS": "ghcr.io/open-craft/openedx-permissions-arm64:{{ TUTOR_VERSION }}",
},
}


@hooks.Filters.DOCKER_BUILD_COMMAND.add()
def modify_build_command(cmd_args: list[str]):
""" Replace 'build' with 'buildx build'"""
# cmd_args is e.g. ["build", "-t", "(tag)", ...]
# There is no way to inspect the tutor config here ? So use an env variable.
# We want to modify DOCKER_BUILD_COMMAND for automated builds on GitHub but
# not for local builds on a developer's machine, which should work the same
# way as normal.
if os.environ.get("TUTOR_ARM64_FORCE_BUILDX_ARM64"):
return ["buildx"] + cmd_args + ["--load", "--platform=linux/arm64/v8"]
return cmd_args


################# You don't really have to bother about what's below this line,
################# except maybe for educational purposes :)

Expand Down

0 comments on commit bc941a7

Please sign in to comment.