Skip to content

Commit

Permalink
Merge pull request earthobservations#172 from earthobservations/test-…
Browse files Browse the repository at this point in the history
…docker

Build and publish Docker images
  • Loading branch information
gutzbenj committed Sep 21, 2020
2 parents eaca235 + d473584 commit 53631bf
Show file tree
Hide file tree
Showing 7 changed files with 211 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .github/release/full.test.yml
@@ -0,0 +1,4 @@
sut:
build: full
# TODO: We might went to improve this. Just say "wetterdienst about system" here.
command: python -c 'import wradlib; print(wradlib.__version__)'
40 changes: 40 additions & 0 deletions .github/release/full/Dockerfile
@@ -0,0 +1,40 @@
# 1. Build GDAL-python
FROM python:3.8.5-slim as build-step

# TODO: This currently installs GDAL==2.4.0. For a more recent version, ...
#
# - Maybe use "ubuntu:focal" already?
# https://github.com/thinkWhere/GDAL-Docker/blob/develop/3.8-ubuntu/Dockerfile
#
# - See also:
# https://github.com/andrejreznik/docker-python-gdal
#

ENV DEBIAN_FRONTEND noninteractive
ENV TERM linux

# Install GDAL.
RUN apt-get update
RUN apt-get --yes install build-essential libgdal-dev

# Make sure you have numpy installed before you attempt to install the GDAL Python bindings.
# https://gis.stackexchange.com/a/274328
RUN pip install numpy
RUN pip install GDAL==$(gdal-config --version)

# Install wradlib.
RUN pip install wradlib


# 2. Main
FROM python:3.8.5-slim

# Install libgdal.
RUN apt-get update
RUN apt-get --yes install libgdal20

# Copy build artefacts from first build step.
COPY --from=build-step /usr/local/lib /usr/local/lib

# Install Wetterdienst.
RUN pip install wetterdienst[excel]
3 changes: 3 additions & 0 deletions .github/release/standard.test.yml
@@ -0,0 +1,3 @@
sut:
build: standard
command: wetterdienst about parameters
6 changes: 6 additions & 0 deletions .github/release/standard/Dockerfile
@@ -0,0 +1,6 @@
FROM python:3.8.5-slim

ENV DEBIAN_FRONTEND noninteractive
ENV TERM linux

RUN pip install wetterdienst[excel]
4 changes: 4 additions & 0 deletions .github/workflows/README.md
Expand Up @@ -2,3 +2,7 @@ Check out the guide that was used to create the CI environment including setting

- https://medium.com/@cjolowicz/hypermodern-python-d44485d9d769
- https://cjolowicz.github.io/posts/hypermodern-python-01-setup/

- https://docs.github.com/en/actions/creating-actions/creating-a-docker-container-action
- https://docs.github.com/en/actions/creating-actions/dockerfile-support-for-github-actions
- https://docs.github.com/en/actions/guides/publishing-docker-images
77 changes: 77 additions & 0 deletions .github/workflows/docker-publish-full.yml
@@ -0,0 +1,77 @@
name: Docker Full

on:
push:
# Publish `master` as Docker `latest` image.
branches:
- master
- test-docker

# Publish `v1.2.3` tags as releases.
tags:
- v*

# Run tests for any PRs.
pull_request:

env:
IMAGE_NAME: wetterdienst-full

jobs:
# Run tests.
# See also https://docs.docker.com/docker-hub/builds/automated-testing/
test:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2

- name: Run tests
run: |
if [[ -f .github/release/full.test.yml ]]; then
docker-compose --file .github/release/full.test.yml build
docker-compose --file .github/release/full.test.yml run sut
fi
# Push image to GitHub Packages.
# See also https://docs.docker.com/docker-hub/builds/
push:
# Ensure test job passes before pushing image.
needs: test

runs-on: ubuntu-latest
if: github.event_name == 'push'

steps:
- uses: actions/checkout@v2

- name: Build image
run: docker build . --file .github/release/full/Dockerfile --tag $IMAGE_NAME

- name: Log into GitHub Container Registry
# TODO: Create a PAT with `read:packages` and `write:packages` scopes and save it as an Actions secret `CR_PAT`
run: echo "${{ secrets.CR_PAT }}" | docker login https://ghcr.io -u ${{ github.actor }} --password-stdin

- name: Push image to GitHub Container Registry
run: |
IMAGE_ID=ghcr.io/${{ github.repository_owner }}/$IMAGE_NAME
# Change all uppercase to lowercase
IMAGE_ID=$(echo $IMAGE_ID | tr '[A-Z]' '[a-z]')
# Strip git ref prefix from version
VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,')
# Strip "v" prefix from tag name
[[ "${{ github.ref }}" == "refs/tags/"* ]] && VERSION=$(echo $VERSION | sed -e 's/^v//')
# Use Docker `latest` tag convention
[ "$VERSION" == "master" ] && VERSION=latest
echo IMAGE_ID=$IMAGE_ID
echo VERSION=$VERSION
docker tag $IMAGE_NAME $IMAGE_ID:$VERSION
docker push $IMAGE_ID:$VERSION
echo "Published image $IMAGE_ID:$VERSION"
77 changes: 77 additions & 0 deletions .github/workflows/docker-publish-standard.yml
@@ -0,0 +1,77 @@
name: Docker Standard

on:
push:
# Publish `master` as Docker `latest` image.
branches:
- master
- test-docker

# Publish `v1.2.3` tags as releases.
tags:
- v*

# Run tests for any PRs.
pull_request:

env:
IMAGE_NAME: wetterdienst-standard

jobs:
# Run tests.
# See also https://docs.docker.com/docker-hub/builds/automated-testing/
test:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2

- name: Run tests
run: |
if [[ -f .github/release/standard.test.yml ]]; then
docker-compose --file .github/release/standard.test.yml build
docker-compose --file .github/release/standard.test.yml run sut
fi
# Push image to GitHub Packages.
# See also https://docs.docker.com/docker-hub/builds/
push:
# Ensure test job passes before pushing image.
needs: test

runs-on: ubuntu-latest
if: github.event_name == 'push'

steps:
- uses: actions/checkout@v2

- name: Build image
run: docker build . --file .github/release/standard/Dockerfile --tag $IMAGE_NAME

- name: Log into GitHub Container Registry
# TODO: Create a PAT with `read:packages` and `write:packages` scopes and save it as an Actions secret `CR_PAT`
run: echo "${{ secrets.CR_PAT }}" | docker login https://ghcr.io -u ${{ github.actor }} --password-stdin

- name: Push image to GitHub Container Registry
run: |
IMAGE_ID=ghcr.io/${{ github.repository_owner }}/$IMAGE_NAME
# Change all uppercase to lowercase
IMAGE_ID=$(echo $IMAGE_ID | tr '[A-Z]' '[a-z]')
# Strip git ref prefix from version
VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,')
# Strip "v" prefix from tag name
[[ "${{ github.ref }}" == "refs/tags/"* ]] && VERSION=$(echo $VERSION | sed -e 's/^v//')
# Use Docker `latest` tag convention
[ "$VERSION" == "master" ] && VERSION=latest
echo IMAGE_ID=$IMAGE_ID
echo VERSION=$VERSION
docker tag $IMAGE_NAME $IMAGE_ID:$VERSION
docker push $IMAGE_ID:$VERSION
echo "Published image $IMAGE_ID:$VERSION"

0 comments on commit 53631bf

Please sign in to comment.