Skip to content

Commit

Permalink
merge test and docker build jobs
Browse files Browse the repository at this point in the history
  • Loading branch information
aperrin66 committed Nov 16, 2023
1 parent 903f91b commit 8c7a64b
Showing 1 changed file with 44 additions and 69 deletions.
113 changes: 44 additions & 69 deletions .github/workflows/tests_build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,35 @@ env:
BASE_IMAGE_NAME: "${{ secrets.DOCKER_ORG }}/nansat_base"
BASE_IMAGE_TAG: '0.0.18'
jobs:
tests:
name: 'Run unit tests'
tests_and_docker_build:
name: 'Run unit tests and build docker image'
runs-on: 'ubuntu-20.04'
strategy:
matrix:
tag_suffix:
- ''
- '-slim'
python_version:
- '3.7'
- '3.8'
- '3.9'
- '3.10'
- '3.11'
version:
- {'python': '3.7', 'latest': false}
- {'python': '3.8', 'latest': false}
- {'python': '3.9', 'latest': false}
- {'python': '3.10', 'latest': false}
- {'python': '3.11', 'latest': true}
steps:
- name: 'Checkout repository'
uses: actions/checkout@v4

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

- name: Cache Docker layers
uses: actions/cache@v3
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx${{ matrix.tag_suffix }}-python${{ matrix.version.python }}-${{ github.sha }}
restore-keys: |
${{ runner.os }}-buildx${{ matrix.tag_suffix }}-python${{ matrix.version.python }}-
- name: Login to DockerHub
uses: docker/login-action@v3
with:
Expand All @@ -48,7 +59,7 @@ jobs:
-e "GITHUB_REPOSITORY=$GITHUB_REPOSITORY"
-e "GITHUB_RUN_ID=$GITHUB_RUN_ID"
-e "GITHUB_TOKEN=$GITHUB_TOKEN"
"${BASE_IMAGE_NAME}:${BASE_IMAGE_TAG}${{ matrix.tag_suffix }}-python${{ matrix.python_version }}"
"${BASE_IMAGE_NAME}:${BASE_IMAGE_TAG}${{ matrix.tag_suffix }}-python${{ matrix.version.python }}"
bash -c "
apt update && apt install -y g++ &&
python setup.py sdist &&
Expand All @@ -64,10 +75,33 @@ jobs:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: pip install coveralls && coveralls --service=github

- name: Build docker image
uses: docker/build-push-action@v5
with:
context: .
build-args: |
BASE_IMAGE=${{ env.BASE_IMAGE_NAME }}:${{ env.BASE_IMAGE_TAG }}${{ matrix.tag_suffix }}-python${{ matrix.version.python }}
NANSAT_RELEASE=${{ env.TAG == 'tmp' && '0.0.0' || env.TAG }}
push: ${{ github.ref_type == 'tag' }}
tags: |
${{ env.IMAGE_NAME }}:${{ env.TAG }}${{ matrix.tag_suffix }}-python${{ matrix.version.python }}
${{ env.IMAGE_NAME }}:latest${{ matrix.tag_suffix }}-python${{ matrix.version.python }}
${{ matrix.version.latest && format('latest{0}', matrix.tag_suffix) || '' }}
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache-new

# Temp fix
# https://github.com/docker/build-push-action/issues/252
# https://github.com/moby/buildkit/issues/1896
- name: Move cache
run: |
rm -rf /tmp/.buildx-cache
mv /tmp/.buildx-cache-new /tmp/.buildx-cache
publish_python_package:
name: Publish the Python package to PyPI
runs-on: 'ubuntu-20.04'
needs: 'tests'
needs: 'tests_and_docker_build'
if: github.event_name == 'release'
steps:
- name: 'Checkout repository'
Expand All @@ -89,63 +123,4 @@ jobs:
# publishing to the test PyPI from forks easy
repository_url: ${{ secrets.PYPI_REPOSITORY_URL }}
password: ${{ secrets.PYPI_TOKEN }}


build_docker_images:
runs-on: 'ubuntu-20.04'
needs: 'tests'
strategy:
matrix:
tag_suffix:
- ''
- '-slim'
version:
- {'python': '3.7', 'latest': false}
- {'python': '3.8', 'latest': false}
- {'python': '3.9', 'latest': false}
- {'python': '3.10', 'latest': false}
- {'python': '3.11', 'latest': true}
steps:
- name: 'Checkout repository'
uses: actions/checkout@v4

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

- name: Cache Docker layers
uses: actions/cache@v3
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx${{ matrix.tag_suffix }}-python${{ matrix.version.python }}-${{ github.sha }}
restore-keys: |
${{ runner.os }}-buildx${{ matrix.tag_suffix }}-python${{ matrix.version.python }}-
- name: Login to DockerHub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USER }}
password: ${{ secrets.DOCKER_PASS }}

- name: Build docker image
uses: docker/build-push-action@v5
with:
context: .
build-args: |
BASE_IMAGE=${{ env.BASE_IMAGE_NAME }}:${{ env.BASE_IMAGE_TAG }}${{ matrix.tag_suffix }}-python${{ matrix.version.python }}
NANSAT_RELEASE=${{ env.TAG == 'tmp' && '0.0.0' || env.TAG }}
push: ${{ github.ref_type == 'tag' }}
tags: |
${{ env.IMAGE_NAME }}:${{ env.TAG }}${{ matrix.tag_suffix }}-python${{ matrix.version.python }}
${{ env.IMAGE_NAME }}:latest${{ matrix.tag_suffix }}-python${{ matrix.version.python }}
${{ matrix.version.latest && format('latest{0}', matrix.tag_suffix) || '' }}
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache-new

# Temp fix
# https://github.com/docker/build-push-action/issues/252
# https://github.com/moby/buildkit/issues/1896
- name: Move cache
run: |
rm -rf /tmp/.buildx-cache
mv /tmp/.buildx-cache-new /tmp/.buildx-cache
...

0 comments on commit 8c7a64b

Please sign in to comment.