Skip to content

Commit

Permalink
Merge pull request #74 from octodns/multiarch
Browse files Browse the repository at this point in the history
  • Loading branch information
parkr authored Sep 11, 2024
2 parents 74682a1 + 9394d63 commit 9bd3f1e
Show file tree
Hide file tree
Showing 5 changed files with 187 additions and 49 deletions.
49 changes: 35 additions & 14 deletions .github/workflows/publish-on-push-to-main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,38 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- env:
DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }}
DOCKER_REGISTRY_URL: docker.io
DOCKER_USERNAME: octodns
name: Docker Login
run: bash -c 'echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin
"$DOCKER_REGISTRY_URL"'
- name: Publish octodns
run: script/release ${{matrix.flavor}} octodns/${{matrix.flavor}}
- env:
DOCKER_REGISTRY_URL: docker.io
name: Docker Logout
run: docker logout "$DOCKER_REGISTRY_URL"
- uses: docker/setup-qemu-action@v2
with:
platforms: arm64,arm
- uses: docker/setup-buildx-action@v2
with:
platforms: linux/amd64,linux/arm64
- id: meta
name: create metadata (tags and labels)
uses: docker/metadata-action@v4
with:
flavor: latest=false
images: octodns/${{matrix.flavor}}
labels: org.opencontainers.image.documentation=https://github.com/octodns/octodns#readme
org.opencontainers.image.licenses=MIT
tags: type=raw,value={{date 'YYYY.MM'}} type=raw,value=latest,enable={{is_default_branch}}
- name: login to docker.io registry
uses: docker/login-action@v2
with:
password: ${{ secrets.DOCKER_PASSWORD }}
registry: docker.io
username: octodns
- name: build & push image for all supported platforms
uses: docker/build-push-action@v4
with:
build-args: OCTODNS_FLAVOR=${{ matrix.flavor }}
cache-from: type=gha
cache-to: type=gha,mode=max
context: all
labels: ${{ steps.meta.outputs.labels }}
platforms: linux/amd64,linux/arm64
push: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }}
tags: ${{ steps.meta.outputs.tags }}
strategy:
matrix:
flavor:
Expand Down Expand Up @@ -45,9 +64,11 @@ jobs:
- selectel
- transip
- ultra
name: Publish to Docker Hub on push to main
name: Publish to Docker Hub
'on':
push:
branches:
- main
- github-actions
- multiarch
workflow_dispatch: {}
35 changes: 33 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,35 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: script/cibuild ${{matrix.flavor}} ${{matrix.flavor}}
- uses: docker/setup-qemu-action@v2
with:
platforms: arm64,arm
- uses: docker/setup-buildx-action@v2
with:
platforms: linux/amd64,linux/arm64
- id: meta
name: create metadata (tags and labels)
uses: docker/metadata-action@v4
with:
flavor: latest=false
images: octodns/${{matrix.flavor}}
labels: org.opencontainers.image.documentation=https://github.com/octodns/octodns#readme
org.opencontainers.image.licenses=MIT
tags: type=raw,value={{date 'YYYY.MM'}}
- name: build image on all platforms
uses: docker/build-push-action@v4
with:
build-args: OCTODNS_FLAVOR=${{ matrix.flavor }}
cache-from: type=gha
cache-to: type=gha,mode=max
context: all
labels: ${{ steps.meta.outputs.labels }}
platforms: linux/amd64,linux/arm64
tags: ${{ steps.meta.outputs.tags }}
- name: script/build
run: script/build ${{ matrix.flavor }} ${{ steps.meta.outputs.tags }}
- name: script/test
run: script/test ${{ steps.meta.outputs.tags }}
strategy:
matrix:
flavor:
Expand Down Expand Up @@ -34,4 +62,7 @@ jobs:
- transip
- ultra
name: Test
'on': push
'on':
pull_request:
branches:
- main
26 changes: 19 additions & 7 deletions all/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,12 +1,24 @@
FROM python:3.12.6-slim as build
RUN set -ex \
&& apt-get -y update \
&& apt-get -y install --no-install-recommends git \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
FROM python:3.12.6-slim AS build

WORKDIR /opt/octodns
COPY requirements.txt requirements.txt

COPY requirements.txt all-requirements.txt

ARG OCTODNS_FLAVOR=octodns

RUN set -ex; \
if [ "${OCTODNS_FLAVOR}" != "octodns" ] ; then \
head -n1 all-requirements.txt >> requirements.txt \
&& grep "${OCTODNS_FLAVOR}" all-requirements.txt >> requirements.txt; \
else \
cp all-requirements.txt requirements.txt; \
fi

RUN set -ex \
&& apt-get update \
&& apt-get install git build-essential libffi-dev rustc cargo --no-install-recommends -y \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* \
&& python -m venv env \
&& . env/bin/activate \
&& pip install --no-cache-dir -r requirements.txt
Expand Down
17 changes: 2 additions & 15 deletions script/build
Original file line number Diff line number Diff line change
Expand Up @@ -20,25 +20,12 @@ test -z "$TAG" && {

set -ex

if ! [ -d "${script_dir}/../${FLAVOR}" ]; then
mkdir "${script_dir}/../${FLAVOR}"
fi

if ! [ -f "${script_dir}/../${FLAVOR}/Dockerfile" ]; then
cp "${script_dir}/../all/Dockerfile" "${script_dir}/../${FLAVOR}/Dockerfile"
fi

if ! [ -f "${script_dir}/../${FLAVOR}/requirements.txt" ]; then
head -n1 "${script_dir}/../all/requirements.txt" > "${script_dir}/../${FLAVOR}/requirements.txt"
grep "$FLAVOR" "${script_dir}/../all/requirements.txt" >> "${script_dir}/../${FLAVOR}/requirements.txt"
cat "${script_dir}/../${FLAVOR}/requirements.txt"
fi

docker build --tag "$TAG" \
--label org.opencontainers.image.created="$(date --rfc-3339=seconds)" \
--label org.opencontainers.image.url="https://github.com/${GITHUB_REPOSITORY}" \
--label org.opencontainers.image.documentation="https://github.com/octodns/octodns#readme" \
--label org.opencontainers.image.source="https://github.com/${GITHUB_REPOSITORY}" \
--label org.opencontainers.image.revision="$GITHUB_SHA" \
--label org.opencontainers.image.licenses=MIT \
"$FLAVOR"
--build-arg OCTODNS_FLAVOR="$FLAVOR" \
all
109 changes: 98 additions & 11 deletions script/generate-workflow-files
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import sys

PLATFORMS = 'linux/amd64,linux/arm64'

try:
import yaml
except ModuleNotFoundError:
Expand All @@ -24,14 +26,55 @@ def write_test_workflow(flavors):
}
},
'steps': [
{'uses': 'actions/checkout@v3'},
{'run': 'script/cibuild ${{matrix.flavor}} ${{matrix.flavor}}'}
{'uses': 'actions/checkout@v4'},
{
'uses': 'docker/setup-qemu-action@v2',
'with': {'platforms': 'arm64,arm'}
},
{
'uses': 'docker/setup-buildx-action@v2',
'with': {'platforms': PLATFORMS}
},
{
'name': 'create metadata (tags and labels)',
'uses': 'docker/metadata-action@v4',
'id': 'meta',
'with': {
'images': 'octodns/${{matrix.flavor}}',
'flavor': 'latest=false',
'tags': 'type=raw,value={{date \'YYYY.MM\'}}',
'labels': ''
'org.opencontainers.image.documentation=https://github.com/octodns/octodns#readme'
' org.opencontainers.image.licenses=MIT'
}
},
{
'name': 'build image on all platforms',
'uses': 'docker/build-push-action@v4',
'with': {
'context': 'all',
'platforms': PLATFORMS,
'tags': '${{ steps.meta.outputs.tags }}',
'labels': '${{ steps.meta.outputs.labels }}',
'build-args': 'OCTODNS_FLAVOR=${{ matrix.flavor }}',
'cache-from': 'type=gha',
'cache-to': 'type=gha,mode=max'
}
},
{
'name': 'script/build',
'run': 'script/build ${{ matrix.flavor }} ${{ steps.meta.outputs.tags }}'
},
{
'name': 'script/test',
'run': 'script/test ${{ steps.meta.outputs.tags }}'
}
]
}
}
with open(".github/workflows/test.yml", 'w', encoding='UTF-8') as f:
yaml.dump({
'on': 'push',
'on': {'pull_request': {'branches': ['main']}},
'name': 'Test',
'jobs': jobs,
}, f)
Expand All @@ -47,21 +90,65 @@ def write_publish_workflow(flavors):
}
},
'steps': [
{'uses': 'actions/checkout@v3'},
{'uses': 'actions/checkout@v4'},
{
'uses': 'docker/setup-qemu-action@v2',
'with': {'platforms': 'arm64,arm'}
},
{
'uses': 'docker/setup-buildx-action@v2',
'with': {'platforms': PLATFORMS}
},
{
'name': 'Docker Login',
'run': 'bash -c \'echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin "$DOCKER_REGISTRY_URL"\'',
'env': {'DOCKER_USERNAME': 'octodns', 'DOCKER_PASSWORD': '${{ secrets.DOCKER_PASSWORD }}', 'DOCKER_REGISTRY_URL': 'docker.io'}
'name': 'create metadata (tags and labels)',
'uses': 'docker/metadata-action@v4',
'id': 'meta',
'with': {
'images': 'octodns/${{matrix.flavor}}',
'flavor': 'latest=false',
'tags': ''
# set dated tag
'type=raw,value={{date \'YYYY.MM\'}}'
# set latest tag for default branch
' type=raw,value=latest,enable={{is_default_branch}}',
'labels': ''
'org.opencontainers.image.documentation=https://github.com/octodns/octodns#readme'
' org.opencontainers.image.licenses=MIT'
}
},
{'name': 'Publish octodns', 'run': 'script/release ${{matrix.flavor}} octodns/${{matrix.flavor}}'},
{'name': 'Docker Logout', 'run': 'docker logout "$DOCKER_REGISTRY_URL"', 'env': {'DOCKER_REGISTRY_URL': 'docker.io'}}
{
'name': 'login to docker.io registry',
'uses': 'docker/login-action@v2',
'with': {
'registry': 'docker.io',
'username': 'octodns',
'password': '${{ secrets.DOCKER_PASSWORD }}'
}
},
{
'name': 'build & push image for all supported platforms',
'uses': 'docker/build-push-action@v4',
'with': {
'context': 'all',
'push': '${{ github.event_name == \'push\' && github.ref == \'refs/heads/main\' }}',
'tags': '${{ steps.meta.outputs.tags }}',
'labels': '${{ steps.meta.outputs.labels }}',
'build-args': 'OCTODNS_FLAVOR=${{ matrix.flavor }}',
'cache-from': 'type=gha',
'cache-to': 'type=gha,mode=max',
'platforms': PLATFORMS
}
}
]
}
}
with open(".github/workflows/publish-on-push-to-main.yml", 'w', encoding='UTF-8') as f:
yaml.dump({
'on': {'push': { 'branches': ['main', 'github-actions'] }},
'name': 'Publish to Docker Hub on push to main',
'on': {
'push': { 'branches': ['main', 'github-actions', 'multiarch'] },
'workflow_dispatch': {},
},
'name': 'Publish to Docker Hub',
'jobs': jobs,
}, f)

Expand Down

0 comments on commit 9bd3f1e

Please sign in to comment.