-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Reorganize dockerfiles and build and deploy workflows
- Loading branch information
Showing
5 changed files
with
251 additions
and
53 deletions.
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,18 +1,149 @@ | ||
name: Docker Image CI | ||
# Build PyGeoC docker images based on TauDEM_ext | ||
|
||
name: Build PyGeoC based on TauDEM_ext | ||
|
||
on: | ||
push: | ||
branches: [ "master" ] | ||
pull_request: | ||
branches: [ "master" ] | ||
push: | ||
branches: | ||
- 'master' | ||
- 'dev' | ||
pull_request: | ||
workflow_dispatch: | ||
|
||
env: | ||
# Container registry domain, and a name for the Docker image that this workflow builds. | ||
IMAGE_NAME: pygeoc | ||
# github container registry | ||
REGISTRY: ghcr.io | ||
NAMESPACE: ${{ github.repository_owner }} | ||
# aliyun ACR | ||
REGION_ID_ACR: cn-hangzhou | ||
REGISTRY_ACR: registry.cn-hangzhou.aliyuncs.com | ||
LOGIN_SERVER: https://registry.cn-hangzhou.aliyuncs.com | ||
NAMESPACE_ACR: ljzhu-geomodels | ||
# dockerfiles and tags | ||
ALPINE_DOCKERFILE: Dockerfile.alpine | ||
ALPINE_IMAGE_TAG: ${{ github.ref == 'refs/heads/master' && 'alpine' || 'dev-alpine' }} | ||
UBUNTU_DOCKERFILE: Dockerfile.ubuntu | ||
UBUNTU_IMAGE_TAG: ${{ github.ref == 'refs/heads/master' && 'ubuntu' || 'dev-ubuntu' }} | ||
|
||
jobs: | ||
deploy-alpine: | ||
runs-on: ubuntu-22.04 | ||
# Sets the permissions granted to the `GITHUB_TOKEN` for the actions in this job. | ||
permissions: | ||
contents: read | ||
packages: write | ||
attestations: write | ||
id-token: write | ||
|
||
steps: | ||
- uses: actions/checkout@v4 | ||
# login alibaba Container Registry | ||
- name: Login to ACR | ||
uses: aliyun/acr-login@v1 | ||
with: | ||
login-server: ${{ env.LOGIN_SERVER }} | ||
region-id: ${{ env.REGION_ID_ACR }} | ||
username: ${{ secrets.ACR_USERNAME }} | ||
password: ${{ secrets.ACR_PASSWORD }} | ||
# login ghcr.io | ||
- name: Log in to the Container registry | ||
uses: docker/login-action@v3 | ||
with: | ||
registry: ${{ env.REGISTRY }} | ||
username: ${{ github.actor }} | ||
password: ${{ secrets.GITHUB_TOKEN }} | ||
|
||
build: | ||
# This step uses [docker/metadata-action](https://github.com/docker/metadata-action#about) to extract tags and labels that will be applied to the specified image. The `id` "meta" allows the output of this step to be referenced in a subsequent step. The `images` value provides the base name for the tags and labels. | ||
- name: Extract metadata (tags, labels) for Docker | ||
id: meta | ||
uses: docker/metadata-action@v5 | ||
with: | ||
images: | | ||
${{ env.REGISTRY_ACR }}/${{ env.NAMESPACE_ACR }}/${{ env.IMAGE_NAME }} | ||
${{ env.REGISTRY }}/${{ env.NAMESPACE }}/${{ env.IMAGE_NAME }} | ||
tags: | | ||
type=ref,event=branch | ||
type=ref,event=pr | ||
type=semver,pattern={{version}} | ||
type=semver,pattern={{major}}.{{minor}} | ||
runs-on: ubuntu-latest | ||
# This step uses the `docker/build-push-action` action to build the image, based on your repository's `Dockerfile`. If the build succeeds, it pushes the image to GitHub Packages. | ||
# It uses the `context` parameter to define the build's context as the set of files located in the specified path. For more information, see "[Usage](https://github.com/docker/build-push-action#usage)" in the README of the `docker/build-push-action` repository. | ||
# It uses the `tags` and `labels` parameters to tag and label the image with the output from the "meta" step. | ||
# https://github.com/marketplace/actions/docker-setup-buildx | ||
- uses: docker/setup-buildx-action@v3 | ||
- name: Build based on alpine | ||
uses: docker/build-push-action@v5 | ||
with: | ||
context: . | ||
file: ./docker/${{ env.ALPINE_DOCKERFILE }} | ||
push: true | ||
platforms: linux/amd64,linux/arm64 | ||
provenance: false | ||
tags: | | ||
${{ env.REGISTRY_ACR }}/${{ env.NAMESPACE_ACR }}/${{ env.IMAGE_NAME }}:${{ env.ALPINE_IMAGE_TAG }} | ||
${{ env.REGISTRY }}/${{ env.NAMESPACE }}/${{ env.IMAGE_NAME }}:${{ env.ALPINE_IMAGE_TAG }} | ||
cache-from: type=gha | ||
cache-to: type=gha,mode=max | ||
|
||
deploy-ubuntu: | ||
runs-on: ubuntu-22.04 | ||
# Sets the permissions granted to the `GITHUB_TOKEN` for the actions in this job. | ||
permissions: | ||
contents: read | ||
packages: write | ||
attestations: write | ||
id-token: write | ||
|
||
steps: | ||
- uses: actions/checkout@v3 | ||
- name: Build the Docker image | ||
run: docker build . --file Dockerfile --tag pygeoc:$(date +%s) | ||
- uses: actions/checkout@v4 | ||
# login alibaba Container Registry | ||
- name: Login to ACR | ||
uses: aliyun/acr-login@v1 | ||
with: | ||
login-server: ${{ env.LOGIN_SERVER }} | ||
region-id: ${{ env.REGION_ID_ACR }} | ||
username: ${{ secrets.ACR_USERNAME }} | ||
password: ${{ secrets.ACR_PASSWORD }} | ||
# login ghcr.io | ||
- name: Log in to the Container registry | ||
uses: docker/login-action@v3 | ||
with: | ||
registry: ${{ env.REGISTRY }} | ||
username: ${{ github.actor }} | ||
password: ${{ secrets.GITHUB_TOKEN }} | ||
|
||
# This step uses [docker/metadata-action](https://github.com/docker/metadata-action#about) to extract tags and labels that will be applied to the specified image. The `id` "meta" allows the output of this step to be referenced in a subsequent step. The `images` value provides the base name for the tags and labels. | ||
- name: Extract metadata (tags, labels) for Docker | ||
id: meta | ||
uses: docker/metadata-action@v5 | ||
with: | ||
images: | | ||
${{ env.REGISTRY_ACR }}/${{ env.NAMESPACE_ACR }}/${{ env.IMAGE_NAME }} | ||
${{ env.REGISTRY }}/${{ env.NAMESPACE }}/${{ env.IMAGE_NAME }} | ||
tags: | | ||
type=ref,event=branch | ||
type=ref,event=pr | ||
type=semver,pattern={{version}} | ||
type=semver,pattern={{major}}.{{minor}} | ||
# This step uses the `docker/build-push-action` action to build the image, based on your repository's `Dockerfile`. If the build succeeds, it pushes the image to GitHub Packages. | ||
# It uses the `context` parameter to define the build's context as the set of files located in the specified path. For more information, see "[Usage](https://github.com/docker/build-push-action#usage)" in the README of the `docker/build-push-action` repository. | ||
# It uses the `tags` and `labels` parameters to tag and label the image with the output from the "meta" step. | ||
# https://github.com/marketplace/actions/docker-setup-buildx | ||
- uses: docker/setup-buildx-action@v3 | ||
- name: Build based on ubuntu | ||
uses: docker/build-push-action@v5 | ||
with: | ||
context: . | ||
file: ./docker/${{ env.UBUNTU_DOCKERFILE }} | ||
push: true | ||
platforms: linux/amd64,linux/arm64 | ||
provenance: false | ||
tags: | | ||
${{ env.REGISTRY_ACR }}/${{ env.NAMESPACE_ACR }}/${{ env.IMAGE_NAME }}:${{ env.UBUNTU_IMAGE_TAG }} | ||
${{ env.REGISTRY }}/${{ env.NAMESPACE }}/${{ env.IMAGE_NAME }}:${{ env.UBUNTU_IMAGE_TAG }} | ||
cache-from: type=gha | ||
cache-to: type=gha,mode=max |
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,63 @@ | ||
## | ||
# docker pull ghcr.io/lreis2415/pygeoc:0.3.5-alpine | ||
# or | ||
# docker pull registry.cn-hangzhou.aliyuncs.com/ljzhu-geomodels/pygeoc:0.3.5-alpine | ||
# | ||
# Build by yourself (DO NOT MISSING the dot at the end of the line): | ||
# > cd PyGeoC | ||
# > docker build -t pygeoc:0.3.5-alpine -f docker/Dockerfile.alpine . | ||
# | ||
# Test examples: | ||
# > docker pull ghcr.io/lreis2415/pygeoc:0.3.5-alpine | ||
# > cd PyGeoC | ||
# > docker run -v $(pwd):/pygeoc ghcr.io/lreis2415/pygeoc:0.3.5-alpine /pygeoc/examples/ex01_begin_with_pygeoc.py | ||
# > docker run -v $(pwd):/pygeoc ghcr.io/lreis2415/pygeoc:0.3.5-alpine /pygeoc/examples/ex02_taudem_simple_usage.py | ||
# | ||
# Copyright 2022-2024 Liang-Jun Zhu <zlj@lreis.ac.cn> | ||
# | ||
ARG GDAL_VERSION=3.9.2 | ||
# PyGeoC depends on TauDEM_ext (https://github.com/lreis2415/TauDEM_ext). | ||
# Copy TauDEM_ext executables of the latest TauDEM_ext image based on alpine to the runner | ||
FROM ghcr.io/lreis2415/taudem_ext:alpine AS builtexec | ||
|
||
# Use the corresponding gdal:alpine-normal-${GDAL_VERSION} with the taudem_ext:alpine | ||
# see https://github.com/OSGeo/gdal/pkgs/container/gdal/versions?filters%5Bversion_type%5D=tagged | ||
FROM ghcr.io/osgeo/gdal:alpine-normal-${GDAL_VERSION} AS builder | ||
|
||
# RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.tuna.tsinghua.edu.cn/g' /etc/apk/repositories && \ | ||
# RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories && \ | ||
RUN apk update && apk upgrade && \ | ||
apk add --no-cache py3-pip | ||
|
||
WORKDIR /pygeoc | ||
COPY . . | ||
# Install pygeoc to .local directory | ||
RUN pip install --user --break-system-packages . | ||
|
||
FROM ghcr.io/osgeo/gdal:alpine-normal-${GDAL_VERSION} AS runner | ||
|
||
# Running TauDEM_ext requires openmpi, omp, and openssh | ||
# Running PyGeoC requires GDAL, numpy, and matplotlib, now we only need to add py3-matplotlib | ||
|
||
# Replace alpine repository source cdn to accelarate access speed and setup build env, when necessary | ||
# RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.tuna.tsinghua.edu.cn/g' /etc/apk/repositories && \ | ||
# RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories && \ | ||
RUN apk update && apk upgrade && \ | ||
apk add --no-cache py3-matplotlib \ | ||
openmpi libgomp tini openssh && \ | ||
rm -rf /var/cache/apk/* | ||
|
||
# Copy pygeoc from builder | ||
RUN mkdir /root/.local | ||
COPY --from=builder /root/.local/ /root/.local/ | ||
# Make sure scripts in .local are usable: | ||
ENV PATH=/root/.local/bin:$PATH | ||
|
||
# Copy taudem_ext from builtexec | ||
COPY --from=builtexec /usr/local/bin/ /usr/local/bin/ | ||
COPY --from=builtexec /docker-entrypoint.sh / | ||
ENV OMPI_ALLOW_RUN_AS_ROOT=1 | ||
ENV OMPI_ALLOW_RUN_AS_ROOT_CONFIRM=1 | ||
|
||
ENTRYPOINT [ "python" ] | ||
CMD ["-c", "import pygeoc; print('PyGeoC v%s installed' % pygeoc.__version__)"] |
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 |
---|---|---|
@@ -0,0 +1,45 @@ | ||
## | ||
# docker pull ghcr.io/lreis2415/pygeoc:0.3.5-ubuntu | ||
# or | ||
# docker pull registry.cn-hangzhou.aliyuncs.com/ljzhu-geomodels/pygeoc:0.3.5-ubuntu | ||
# | ||
# Build by yourself (DO NOT MISSING the dot at the end of the line): | ||
# > cd PyGeoC | ||
# > docker build -t pygeoc:0.3.5-ubuntu -f docker/Dockerfile.ubuntu . | ||
# | ||
# Test examples: | ||
# > docker pull ghcr.io/lreis2415/pygeoc:0.3.5-ubuntu | ||
# > cd PyGeoC | ||
# > docker run -v $(pwd):/pygeoc ghcr.io/lreis2415/pygeoc:0.3.5-ubuntu /pygeoc/examples/ex01_begin_with_pygeoc.py | ||
# > docker run -v $(pwd):/pygeoc ghcr.io/lreis2415/pygeoc:0.3.5-ubuntu /pygeoc/examples/ex02_taudem_simple_usage.py | ||
# | ||
# Copyright 2022-2024 Liang-Jun Zhu <zlj@lreis.ac.cn> | ||
# | ||
ARG GDAL_VERSION=3.9.2 | ||
# PyGeoC depends on TauDEM_ext (https://github.com/lreis2415/TauDEM_ext). | ||
# Use TauDEM_ext executables of the latest TauDEM_ext image based on gdal:ubuntu-small-${GDAL_VERSION} as the runner | ||
# Use the same gdal:ubuntu-small-${GDAL_VERSION} with the taudem_ext:ubuntu as builder | ||
# see https://github.com/OSGeo/gdal/pkgs/container/gdal/versions?filters%5Bversion_type%5D=tagged | ||
FROM ghcr.io/osgeo/gdal:ubuntu-small-${GDAL_VERSION} AS builder | ||
|
||
RUN apt-get update -q -y && \ | ||
apt-get install -q -y --no-install-recommends \ | ||
python3-pip && \ | ||
apt-get clean && \ | ||
rm -rf /var/lib/apt/lists/* | ||
|
||
WORKDIR /pygeoc | ||
COPY . . | ||
# Install pygeoc to .local directory | ||
RUN pip install --user --break-system-packages . | ||
|
||
FROM ghcr.io/lreis2415/taudem_ext:ubuntu AS runner | ||
|
||
# Copy pygeoc from builder | ||
RUN mkdir /root/.local | ||
COPY --from=builder /root/.local/ /root/.local/ | ||
# Make sure scripts in .local are usable: | ||
ENV PATH=/root/.local/bin:$PATH | ||
|
||
ENTRYPOINT [ "python" ] | ||
CMD ["-c", "import pygeoc; print('PyGeoC v%s installed' % pygeoc.__version__)"] |
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