Skip to content
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

Switch to buildx for github actions #394

Merged
merged 6 commits into from
Oct 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .github/workflows/Binder.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
name: Binder
on: [push]

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
# NOTE: look into doing this for pangeo-binders too!
Create-MyBinderOrg-Cache:
Expand Down
70 changes: 39 additions & 31 deletions .github/workflows/Build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,29 +30,34 @@ jobs:
CALVER="$( date -u '+%Y.%m.%d' )"
SHA7="${GITHUB_SHA::7}"
DOCKER_TAG=$SHA7
IMAGE_SPEC="${DOCKER_ORG}/${{ env.IMAGE }}:${DOCKER_TAG}"
echo "DOCKER_TAG=${DOCKER_TAG}" >> $GITHUB_ENV
echo "IMAGE_SPEC=${IMAGE_SPEC}" >> $GITHUB_ENV

- name: Build and Publish to DockerHub
uses: elgohr/Publish-Docker-Github-Action@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2

- name: Login to Docker Hub
uses: docker/login-action@v2
with:
name: ${{env.DOCKER_ORG}}/${{ env.IMAGE }}
username: ${{ secrets.DOCKERHUB_USER }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
workdir: ${{ env.IMAGE }}
tags: "master, ${{env.DOCKER_TAG}}"

- name: Also Push To quay.io
id: push-to-quay
uses: redhat-actions/push-to-registry@v2

- name: Login to Quay.io
uses: docker/login-action@v2
with:
image: ${{env.DOCKER_ORG}}/${{ env.IMAGE }}
tags: master ${{env.DOCKER_TAG}}
registry: quay.io
username: ${{ secrets.QUAY_USERNAME }}
password: ${{ secrets.QUAY_PASSWORD }}
username: ${{ secrets.QUAY_USER }}
password: ${{ secrets.QUAY_TOKEN }}

- name: Build and push
uses: docker/build-push-action@v3
with:
context: ${{ env.IMAGE }}
push: true
tags: |
${{env.DOCKER_ORG}}/${{ env.IMAGE }}:master
${{env.DOCKER_ORG}}/${{ env.IMAGE }}:${{env.DOCKER_TAG}}
quay.io/${{env.DOCKER_ORG}}/${{ env.IMAGE }}:master
Comment on lines +57 to +59
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just flagging the use of master as the docker image tag... I suppose this is just following the git repo's master branch right now, and latest needs to be explicitly tagged (i.e. latest is semi-stable)?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

quay.io/${{env.DOCKER_ORG}}/${{ env.IMAGE }}:${{env.DOCKER_TAG}}

matrix-build:
needs: base-image
Expand All @@ -70,9 +75,7 @@ jobs:
run: |
SHA7="${GITHUB_SHA::7}"
DOCKER_TAG=$SHA7
IMAGE_SPEC="${DOCKER_ORG}/${{ matrix.IMAGE }}:${DOCKER_TAG}"
echo "DOCKER_TAG=${DOCKER_TAG}" >> $GITHUB_ENV
echo "IMAGE_SPEC=${IMAGE_SPEC}" >> $GITHUB_ENV

# https://github.com/actions/runner-images/issues/2840#issuecomment-790492173
- name: Free up disk space
Expand All @@ -83,27 +86,32 @@ jobs:
sudo rm -rf /usr/local/lib/android /usr/share/dotnet /opt/ghc
df -h

- name: Build and Publish to DockerHub
uses: elgohr/Publish-Docker-Github-Action@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2

- name: Login to Docker Hub
uses: docker/login-action@v2
with:
name: ${{env.DOCKER_ORG}}/${{ matrix.IMAGE }}
username: ${{ secrets.DOCKERHUB_USER }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
workdir: ${{ matrix.IMAGE }}
tags: "master, ${{env.DOCKER_TAG}}"

- name: Also Push To quay.io
id: push-to-quay
uses: redhat-actions/push-to-registry@v2
- name: Login to Quay.io
uses: docker/login-action@v2
with:
image: ${{env.DOCKER_ORG}}/${{ matrix.IMAGE }}
tags: master ${{env.DOCKER_TAG}}
registry: quay.io
username: ${{ secrets.QUAY_USERNAME }}
password: ${{ secrets.QUAY_PASSWORD }}
username: ${{ secrets.QUAY_USER }}
password: ${{ secrets.QUAY_TOKEN }}

- name: Print image url
run: echo "Image pushed to ${{ steps.push-to-quay.outputs.registry-paths }}"
- name: Build and push
uses: docker/build-push-action@v3
with:
context: ${{ matrix.IMAGE }}
push: true
tags: |
${{env.DOCKER_ORG}}/${{ matrix.IMAGE }}:master
${{env.DOCKER_ORG}}/${{ matrix.IMAGE }}:${{env.DOCKER_TAG}}
quay.io/${{env.DOCKER_ORG}}/${{ matrix.IMAGE }}:master
quay.io/${{env.DOCKER_ORG}}/${{ matrix.IMAGE }}:${{env.DOCKER_TAG}}

- name: Export Full Conda Environment
run: |
Expand Down
40 changes: 26 additions & 14 deletions .github/workflows/Publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,27 +39,39 @@ jobs:
echo "SHA7=${SHA7}" >> $GITHUB_ENV
echo "TAG=${TAG}" >> $GITHUB_ENV

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

- name: Login to Docker Hub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USER }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Login to Quay.io
uses: docker/login-action@v2
with:
registry: quay.io
username: ${{ secrets.QUAY_USER }}
password: ${{ secrets.QUAY_TOKEN }}

- name: Pull Image for Corresponding GitHub Commit
run: |
docker pull ${DOCKER_ORG}/${{ matrix.IMAGE }}:${SHA7}

- name: Authenticate with DockerHub
run: |
echo ${{ secrets.DOCKERHUB_TOKEN }} | docker login -u ${{ secrets.DOCKERHUB_USER }} --password-stdin

- name: Retag and Push Image to DockerHub
- name: Retag Images
run: |
docker tag ${DOCKER_ORG}/${{ matrix.IMAGE }}:${SHA7} ${DOCKER_ORG}/${{ matrix.IMAGE }}:latest
docker tag ${DOCKER_ORG}/${{ matrix.IMAGE }}:${SHA7} ${DOCKER_ORG}/${{ matrix.IMAGE }}:${TAG}
docker tag ${DOCKER_ORG}/${{ matrix.IMAGE }}:${SHA7} quay.io/${DOCKER_ORG}/${{ matrix.IMAGE }}:latest
docker tag ${DOCKER_ORG}/${{ matrix.IMAGE }}:${SHA7} quay.io/${DOCKER_ORG}/${{ matrix.IMAGE }}:${TAG}

- name: Push Tags to Docker Hub
run: |
docker push ${DOCKER_ORG}/${{ matrix.IMAGE }}:latest
docker push ${DOCKER_ORG}/${{ matrix.IMAGE }}:${TAG}

- name: Also Push To quay.io
id: push-to-quay
uses: redhat-actions/push-to-registry@v2
with:
image: ${{env.DOCKER_ORG}}/${{ matrix.IMAGE }}
tags: latest ${{env.TAG}}
registry: quay.io
username: ${{ secrets.QUAY_USERNAME }}
password: ${{ secrets.QUAY_PASSWORD }}
- name: Push Tags To Quay.io
run: |
docker push quay.io/${DOCKER_ORG}/${{ matrix.IMAGE }}:latest
docker push quay.io/${DOCKER_ORG}/${{ matrix.IMAGE }}:${TAG}
70 changes: 34 additions & 36 deletions .github/workflows/Test.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
# Any PR opened, build images and run tests
name: Test

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

on:
pull_request:
types: [opened, synchronize, reopened]
Expand All @@ -11,59 +15,53 @@ env:
GITHUB_REF: ${{ github.ref }}

jobs:
base-image:
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v3

- name: Build Base Image
run: |
cd base-image
docker build -t ${DOCKER_ORG}/base-image:PR .

- name: Save Docker Image
run: |
docker save ${DOCKER_ORG}/base-image:PR | gzip > base-image.tar.gz

- name: Upload Base Image
uses: actions/upload-artifact@v3
with:
name: base-image
path: base-image.tar.gz

matrix-build:
needs: base-image
strategy:
fail-fast: false
matrix:
IMAGE: [base-notebook, pangeo-notebook, ml-notebook, pytorch-notebook, forge]
name: ${{ matrix.IMAGE }}
runs-on: ubuntu-latest
services:
# https://github.com/docker/build-push-action/blob/master/docs/advanced/local-registry.md#local-registry
registry:
image: registry:2
ports:
- 5000:5000

steps:
- name: Checkout Repository
uses: actions/checkout@v3

- name: Download Base Docker Image
uses: actions/download-artifact@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
with:
name: base-image
path: ./artifact

- name: Load Docker Image
run: |
docker load < ./artifact/base-image.tar.gz
driver-opts: network=host

- name: Build base-image
uses: docker/build-push-action@v3
with:
context: base-image
tags: localhost:5000/pangeo/base-image:PR
push: true
cache-from: type=gha
cache-to: type=gha,mode=max

- name: Build Image
run: |
cd ${{ matrix.IMAGE }}
docker build --build-arg PANGEO_BASE_IMAGE_TAG=PR -t ${DOCKER_ORG}/${{ matrix.IMAGE }}:PR .
- name: Build Only
uses: docker/build-push-action@v3
with:
context: ${{ matrix.IMAGE }}
push: true
tags: localhost:5000/${{env.DOCKER_ORG}}/${{ matrix.IMAGE }}:PR
build-args: PANGEO_BASE_IMAGE_TAG=PR
build-contexts: |
pangeo/base-image:PR=docker-image://localhost:5000/pangeo/base-image:PR

- name: Report Image Size and Conda Packages
run: |
docker images
docker run ${DOCKER_ORG}/${{ matrix.IMAGE }}:PR conda list --export
docker run localhost:5000/${DOCKER_ORG}/${{ matrix.IMAGE }}:PR conda list --export

- name: Test Image
run: |
docker run -u 1000 -w /srv/test -v $PWD:/srv/test ${DOCKER_ORG}/${{ matrix.IMAGE }}:PR ./run_tests.sh ${{ matrix.IMAGE }}
docker run -u 1000 -w /srv/test -v $PWD:/srv/test localhost:5000/${DOCKER_ORG}/${{ matrix.IMAGE }}:PR ./run_tests.sh ${{ matrix.IMAGE }}