-
Notifications
You must be signed in to change notification settings - Fork 822
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feat(github-actions): add multi-platform build (raspberry pi support) #245
Open
kalioz
wants to merge
4
commits into
atmoz:master
Choose a base branch
from
kalioz:fix_atmoz_only
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
.git | ||
tests | ||
# Use whitelisting instead of blacklisting | ||
* | ||
! files |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,30 +27,81 @@ jobs: | |
uses: ludeeus/action-shellcheck@master | ||
with: | ||
ignore: tests/shunit2 | ||
|
||
# get the date for the docker labels | ||
- name: Prepare environment variables | ||
id: rfc_date | ||
run: | | ||
echo "rfc_date=$(date --rfc-3339=seconds)" >> $GITHUB_ENV | ||
echo "gh_server_url=$GITHUB_SERVER_URL" >> $GITHUB_ENV # because I can't seem to get it with ${{ env.GITHUB_SERVER_URL }} | ||
|
||
# QEMU is needeed for multi-arch build | ||
- name: Set up QEMU | ||
uses: docker/setup-qemu-action@v1 | ||
|
||
# Buildx is the tool used for multi-arch build | ||
- name: Set up Docker Buildx | ||
uses: docker/setup-buildx-action@v1 | ||
|
||
- name: Login to DockerHub | ||
uses: docker/login-action@v1 | ||
with: | ||
username: ${{ secrets.DOCKER_HUB_USERNAME }} | ||
password: ${{ secrets.DOCKER_HUB_PASSWORD }} | ||
|
||
# note: you should use ghcr.io instead of docker.pkg.github.com because the latest is in depreciation | ||
# however i'm not able to get it to work reliably and it's still in beta | ||
- name: Login to GitHub Container Registry | ||
uses: docker/login-action@v1 | ||
with: | ||
registry: docker.pkg.github.com | ||
username: ${{ github.actor }} | ||
password: ${{ secrets.GITHUB_TOKEN }} | ||
|
||
# Build docker image single platform for the tests | ||
- name: Build debian image | ||
run: | | ||
docker build . \ | ||
--pull=true \ | ||
--file=Dockerfile \ | ||
--tag="$IMAGE_NAME:latest" \ | ||
--tag="$IMAGE_NAME:debian" \ | ||
--label="org.opencontainers.image.source=$GITHUB_SERVER_URL/$GITHUB_REPOSITORY" \ | ||
--label="org.opencontainers.image.revision=$GITHUB_SHA" \ | ||
--label="org.opencontainers.image.created=$(date --rfc-3339=seconds)" | ||
uses: docker/build-push-action@v2 | ||
with: | ||
context: . | ||
file: ./Dockerfile | ||
platforms: linux/amd64 | ||
push: false # don't push to registry | ||
load: true # load the final result in the docker machine. note this does'nt (yet) work with multiple platforms defined. | ||
cache-from: | | ||
${{ env.IMAGE_NAME }}:latest | ||
${{ env.IMAGE_NAME }}:debian | ||
tags: | | ||
${{ env.IMAGE_NAME }}:latest | ||
${{ env.IMAGE_NAME }}:debian | ||
ghcr.io/${{ github.repository }}:latest | ||
ghcr.io/${{ github.repository }}:debian | ||
|
||
labels: | | ||
org.opencontainers.image.source=${{ env.gh_server_url }}/${{ github.repository }} | ||
org.opencontainers.image.revision=${{ github.sha }} | ||
org.opencontainers.image.created=${{ env.rfc_date }} | ||
|
||
- name: Test debian image | ||
run: tests/run $IMAGE_NAME:debian | ||
|
||
# Build docker image single platform for the tests | ||
- name: Build alpine image | ||
run: | | ||
docker build . \ | ||
--pull=true \ | ||
--file=Dockerfile-alpine \ | ||
--tag="$IMAGE_NAME:alpine" \ | ||
--label="org.opencontainers.image.source=$GITHUB_SERVER_URL/$GITHUB_REPOSITORY" \ | ||
--label="org.opencontainers.image.revision=$GITHUB_SHA" \ | ||
--label="org.opencontainers.image.created=$(date --rfc-3339=seconds)" | ||
uses: docker/build-push-action@v2 | ||
with: | ||
context: . | ||
file: ./Dockerfile-alpine | ||
platforms: linux/amd64 | ||
push: false # don't push to registry | ||
load: true # load the final result in the docker machine. note this does'nt (yet) work with multiple platforms defined. | ||
cache-from: | | ||
${{ env.IMAGE_NAME }}:alpine | ||
tags: | | ||
${{ env.IMAGE_NAME }}:alpine | ||
ghcr.io/${{ github.repository }}:alpine | ||
labels: | | ||
org.opencontainers.image.source=${{ env.gh_server_url }}/${{ github.repository }} | ||
org.opencontainers.image.revision=${{ github.sha }} | ||
org.opencontainers.image.created=${{ env.rfc_date }} | ||
|
||
- name: Test alpine image | ||
run: tests/run $IMAGE_NAME:alpine | ||
|
@@ -61,26 +112,54 @@ jobs: | |
with: | ||
import-github-users: atmoz | ||
|
||
- name: Push images to Docker Hub registry | ||
# Build & push docker image multi-platform | ||
# note: the linux/amd64 image is not rebuilt, the cache is still present from the previous steps. | ||
- name: Build & Push debian image to dockerhub | ||
if: github.ref == 'refs/heads/master' | ||
run: | | ||
echo "${{ secrets.DOCKER_HUB_PASSWORD }}" | docker login \ | ||
-u ${{ secrets.DOCKER_HUB_USERNAME }} --password-stdin | ||
uses: docker/build-push-action@v2 | ||
with: | ||
context: . | ||
file: ./Dockerfile | ||
platforms: linux/386,linux/amd64,linux/arm/v6,linux/arm/v7,linux/arm64,linux/ppc64le,linux/s390x | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this can be specified as a newline separated list, which is a bit more readable. platforms: |
linux/386
linux/amd64
linux/arm/v6
linux/arm/v7
linux/arm64
linux/ppc64le
linux/s390x |
||
push: true # push to registry | ||
cache-from: | | ||
${{ env.IMAGE_NAME }}:latest | ||
${{ env.IMAGE_NAME }}:debian | ||
tags: | | ||
${{ env.IMAGE_NAME }}:latest | ||
${{ env.IMAGE_NAME }}:debian | ||
|
||
labels: | | ||
org.opencontainers.image.source=${{ env.gh_server_url }}/${{ github.repository }} | ||
org.opencontainers.image.revision=${{ github.sha }} | ||
org.opencontainers.image.created=${{ env.rfc_date }} | ||
|
||
docker push $IMAGE_NAME # no tags specified to include all tags | ||
docker logout | ||
# Build & push docker image multi-platform | ||
- name: Build & Push alpine image to dockerhub | ||
if: github.ref == 'refs/heads/master' | ||
uses: docker/build-push-action@v2 | ||
with: | ||
context: . | ||
file: ./Dockerfile-alpine | ||
platforms: linux/386,linux/amd64,linux/arm/v6,linux/arm/v7,linux/arm64,linux/ppc64le,linux/s390x | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same as previous |
||
push: true # push to registry | ||
cache-from: | | ||
${{ env.IMAGE_NAME }}:alpine | ||
tags: | | ||
${{ env.IMAGE_NAME }}:alpine | ||
|
||
labels: | | ||
org.opencontainers.image.source=${{ env.gh_server_url }}/${{ github.repository }} | ||
org.opencontainers.image.revision=${{ github.sha }} | ||
org.opencontainers.image.created=${{ env.rfc_date }} | ||
|
||
# Push to github registry | ||
- name: Push images to GitHub registry | ||
if: github.ref == 'refs/heads/master' | ||
run: | | ||
echo "${{ secrets.GITHUB_TOKEN }}" | docker login docker.pkg.github.com \ | ||
-u ${{ github.actor }} --password-stdin | ||
|
||
TAG_DEBIAN=docker.pkg.github.com/$GITHUB_REPOSITORY/debian | ||
TAG_ALPINE=docker.pkg.github.com/$GITHUB_REPOSITORY/alpine | ||
docker tag $IMAGE_NAME:debian $TAG_DEBIAN | ||
docker tag $IMAGE_NAME:alpine $TAG_ALPINE | ||
docker push $TAG_DEBIAN | ||
docker push $TAG_ALPINE | ||
docker logout docker.pkg.github.com | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can be omitted, so it will use underlying runner architecture