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

ci: add action for releasing new docker image and testing it #640

Merged
merged 44 commits into from
Sep 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
7b25a14
add action for releasing new docker image
gcroci2 Sep 4, 2024
ded33a7
add todo
gcroci2 Sep 4, 2024
d8165c1
add logs
gcroci2 Sep 4, 2024
385a748
remove unsupported commands
gcroci2 Sep 4, 2024
ed3b17d
specify platform for building the image in the action
gcroci2 Sep 4, 2024
56d4f77
add tags and multiarch build
gcroci2 Sep 4, 2024
c464425
add debug runs
gcroci2 Sep 4, 2024
5b93d05
restore the inital file
gcroci2 Sep 4, 2024
d33106f
point to the current branch
gcroci2 Sep 4, 2024
03014a8
try rsd workflow
gcroci2 Sep 4, 2024
4547855
remove skip
gcroci2 Sep 4, 2024
f01cfc3
fix base_image_name
gcroci2 Sep 4, 2024
92e4be6
use latest
gcroci2 Sep 4, 2024
ff9d1a9
lowercase
gcroci2 Sep 4, 2024
394c132
move ghcr to actions/ folder
gcroci2 Sep 5, 2024
0051d34
fix folders structure
gcroci2 Sep 5, 2024
0bb5a1b
move actions to workflows
gcroci2 Sep 5, 2024
56b5e87
fix action error
gcroci2 Sep 5, 2024
77c4f01
restore old folder
gcroci2 Sep 5, 2024
24eea90
reindent yml content
gcroci2 Sep 5, 2024
6218944
fix path
gcroci2 Sep 5, 2024
45fa50a
fix _ghcr link
gcroci2 Sep 5, 2024
a647d75
add tag based on software version
gcroci2 Sep 5, 2024
a1ec7e5
lowercase the organization
gcroci2 Sep 5, 2024
bcb67b2
try to increase patch version
gcroci2 Sep 5, 2024
82ea4bc
move docker upload to release.yml
gcroci2 Sep 5, 2024
389548a
fix ubuntu to 22.04
gcroci2 Sep 5, 2024
3f91ab0
add test for docker image
gcroci2 Sep 5, 2024
65b123c
debug docker container running
gcroci2 Sep 5, 2024
22745b6
copy tests folder recursively
gcroci2 Sep 5, 2024
de8c626
print copied tests folder
gcroci2 Sep 5, 2024
f61f7c1
try to copy the whole repo
gcroci2 Sep 5, 2024
243721a
try to fix work dire
gcroci2 Sep 5, 2024
0660c5a
try to copy tests only again
gcroci2 Sep 5, 2024
fcd14eb
remove duplicated run
gcroci2 Sep 5, 2024
233fb77
add project dir
gcroci2 Sep 5, 2024
1955300
remove debugging comment and trigger wf only when release is completed
gcroci2 Sep 5, 2024
6bcb480
fix tutorials add
gcroci2 Sep 6, 2024
f931154
update zenodo address
gcroci2 Sep 6, 2024
3d784ca
update zenodo address
gcroci2 Sep 6, 2024
b61662b
update docs
gcroci2 Sep 6, 2024
55bd679
update target values file for svr
gcroci2 Sep 6, 2024
d65507b
add suggestions
gcroci2 Sep 13, 2024
ca9adbe
merge with dev
gcroci2 Sep 13, 2024
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
70 changes: 70 additions & 0 deletions .github/workflows/_ghcr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
# SPDX-FileCopyrightText: 2022 Dusan Mijatovic (dv4all)
# SPDX-FileCopyrightText: 2022 dv4all
# SPDX-FileCopyrightText: 2024 Ewan Cahen (Netherlands eScience Center) <[email protected]>
# SPDX-FileCopyrightText: 2024 Netherlands eScience Center
#
# SPDX-License-Identifier: Apache-2.0

name: reusable ghcr.io module

on:
workflow_call:
inputs:
ghcr_user:
required: true
description: User for logging to ghcr.io (use github.actor)
type: string
base_image_name:
required: true
description: Base image name incl. ghcr.io
type: string
image_tag:
required: true
description: Image tag (version)
type: string
dockerfile:
required: true
description: Location and name of docker file
type: string
docker_context:
required: true
description: Docker context for the build command
type: string
secrets:
token:
required: true
outputs:
image_created:
description: Full image name after upload to ghcr.io
value: ${{jobs.build_and_push.outputs.image_build}}
image_uploaded:
description: Confirmation that image is uploaded to ghcr.io
value: ${{jobs.build_and_push.outputs.image_pushed}}

jobs:
build_and_push:
name: build and push image
runs-on: ubuntu-22.04
outputs:
image_build: ${{steps.build_image.outputs.image_build}}
image_pushed: ${{steps.build_image.outputs.image_pushed}}
steps:
- name: checkout
# https://github.com/actions/checkout
uses: actions/checkout@v4
- name: build
id: build_image
run: |
IMAGE_TAG_VERSION=${{inputs.base_image_name}}:${{inputs.image_tag}}
IMAGE_TAG_LASTEST=${{inputs.base_image_name}}:latest
echo image_tag_version $IMAGE_TAG_VERSION
docker build -t $IMAGE_TAG_VERSION -t $IMAGE_TAG_LASTEST -f ${{inputs.dockerfile}} ${{inputs.docker_context}}
echo "{image_build}={$IMAGE_TAG_VERSIONvalue}" >> $GITHUB_OUTPUT
- name: push to ghcr.io
id: push_image
run: |
echo login
echo "${{secrets.token}}" | docker login https://ghcr.io -u ${{inputs.ghcr_user}} --password-stdin
echo push auth image with all tags
docker push ${{inputs.base_image_name}} --all-tags
echo "{image_build}={$IMAGE_TAG_VERSIONvalue}" >> $GITHUB_OUTPUT
4 changes: 2 additions & 2 deletions .github/workflows/build-latest-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: build (latest release)
# Only trigger, when the release workflow succeeded
on:
workflow_run:
workflows: ["Build and upload to PyPI"]
workflows: ["Build and upload to PyPI and ghcr.io"]
types:
- completed

Expand All @@ -15,7 +15,7 @@ jobs:
strategy:
fail-fast: false
matrix:
os: ["ubuntu-latest"]
os: ["ubuntu-22.04"]
python-version: ["3.10"] # ["3.10", "3.11"]

# https://github.com/marketplace/actions/setup-miniconda#use-a-default-shell
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/build-repo-frozen-env.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ jobs:
strategy:
fail-fast: false
matrix:
os: ["ubuntu-latest"]
os: ["ubuntu-22.04"]
python-version: ["3.10"] # ["3.10", "3.11"]

# https://github.com/marketplace/actions/setup-miniconda#use-a-default-shell
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/build-repo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ jobs:
strategy:
fail-fast: false
matrix:
os: ["ubuntu-latest"]
os: ["ubuntu-22.04"]
python-version: ["3.10"] # ["3.10", "3.11"]

# https://github.com/marketplace/actions/setup-miniconda#use-a-default-shell
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/cffconvert.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ on:
jobs:
validate:
name: "validate"
runs-on: ubuntu-latest
runs-on: ubuntu-22.04
steps:
- name: Check out a copy of the repository
uses: actions/checkout@v3
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/coveralls.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ jobs:
strategy:
fail-fast: false
matrix:
os: ["ubuntu-latest"]
os: ["ubuntu-22.04"]
python-version: ["3.10"]

# https://github.com/marketplace/actions/setup-miniconda#use-a-default-shell
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/draft-pdf.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ on:

jobs:
paper:
runs-on: ubuntu-latest
runs-on: ubuntu-22.04
name: Paper Draft
steps:
- name: Checkout
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/fair-software.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
verify:
if: github.event.pull_request.draft == false
name: "fair-software"
runs-on: ubuntu-latest
runs-on: ubuntu-22.04
steps:
- uses: fair-software/[email protected]
name: Measure compliance with fair-software.eu recommendations
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/linting.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ jobs:
strategy:
fail-fast: false
matrix:
os: ["ubuntu-latest"]
os: ["ubuntu-22.04"]
python-version: ["3.10"]

# https://github.com/marketplace/actions/setup-miniconda#use-a-default-shell
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/markdown-link-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
markdown-link-check:
if: github.event.pull_request.draft == false
name: Check markdown links
runs-on: ubuntu-latest
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v3
- uses: gaurav-nelson/github-action-markdown-link-check@v1
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/notebooks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ jobs:
strategy:
fail-fast: false
matrix:
os: ["ubuntu-latest"]
os: ["ubuntu-22.04"]
python-version: ["3.10"] # ["3.10", "3.11"]

# https://github.com/marketplace/actions/setup-miniconda#use-a-default-shell
Expand Down
48 changes: 42 additions & 6 deletions .github/workflows/release_pypi.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Build and upload to PyPI
name: Build and upload to PyPI and ghcr.io

on:
workflow_dispatch:
Expand All @@ -14,7 +14,7 @@ jobs:
strategy:
fail-fast: false
matrix:
os: ["ubuntu-latest"]
os: ["ubuntu-22.04"]
python-version: ["3.10"]

# https://github.com/marketplace/actions/setup-miniconda#use-a-default-shell
Expand All @@ -36,8 +36,8 @@ jobs:
path: dist/*

upload_test_pypi:
needs: [build]
runs-on: ubuntu-latest
needs: build
runs-on: ubuntu-22.04
if: github.event_name == 'workflow_dispatch'
steps:
- uses: actions/download-artifact@v3
Expand All @@ -51,8 +51,8 @@ jobs:
repository_url: https://test.pypi.org/legacy/

upload_pypi:
needs: [build]
runs-on: ubuntu-latest
needs: build
runs-on: ubuntu-22.04
if: github.event_name == 'release' && github.event.action == 'published'
steps:
- uses: actions/download-artifact@v3
Expand All @@ -63,3 +63,39 @@ jobs:
with:
user: __token__
password: ${{ secrets.PYPI_TOKEN_DEEPRANK2 }}

read_only_version:
needs: upload_pypi
name: Read version from TOML
runs-on: ubuntu-22.04
outputs:
version: ${{ steps.get_version.outputs.VERSION }}
repo_lowercase: ${{ steps.repo_lowercase.outputs.REPO_LOWERCASE }}
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Read version from TOML
id: get_version
run: |
VERSION=$(grep '^version =' pyproject.toml | awk -F '"' '{print $2}')
echo "VERSION=$VERSION" >> $GITHUB_OUTPUT

- name: Convert repository name to lowercase
id: repo_lowercase
run: |
REPO_LOWERCASE=$(echo "${{ github.repository }}" | tr '[:upper:]' '[:lower:]')
echo "REPO_LOWERCASE=$REPO_LOWERCASE" >> $GITHUB_OUTPUT

upload_docker_image:
needs: read_only_version
name: Upload Docker image to ghcr.io
uses: ./.github/workflows/_ghcr.yml
with:
ghcr_user: ${{github.actor}}
base_image_name: ghcr.io/${{ needs.read_only_version.outputs.repo_lowercase }}
image_tag: ${{ needs.read_only_version.outputs.version }}
dockerfile: ./Dockerfile
docker_context: .
secrets:
token: ${{secrets.GITHUB_TOKEN}}
2 changes: 1 addition & 1 deletion .github/workflows/stale_issue_pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ on:

jobs:
close-issues:
runs-on: ubuntu-latest
runs-on: ubuntu-22.04
permissions:
issues: write
pull-requests: write
Expand Down
64 changes: 64 additions & 0 deletions .github/workflows/test-docker-image.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
name: test latest docker image

# Only trigger, when the release workflow succeeded
on:
workflow_run:
workflows: ["Build and upload to PyPI and ghcr.io"]
types:
- completed

jobs:
test_latest_docker_image:
runs-on: ubuntu-22.04
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Pull latest Docker image
run: |
REPO_LOWERCASE=$(echo "${{ github.repository }}" | tr '[:upper:]' '[:lower:]')
docker pull ghcr.io/$REPO_LOWERCASE:latest

- name: Run tests in Docker container
run: |

REPO_LOWERCASE=$(echo "${{ github.repository }}" | tr '[:upper:]' '[:lower:]')
docker run --name test_container -d ghcr.io/$REPO_LOWERCASE:latest tail -f /dev/null

PROJECT_DIR="/app"
TEST_DIR="$PROJECT_DIR/tests"
echo "Project directory: $PROJECT_DIR"
echo "Tests directory: $TEST_DIR"

# Create project directory and copy tests folder
docker exec test_container mkdir -p $PROJECT_DIR
docker cp tests test_container:$TEST_DIR

# Verify the directory structure
echo "Contents of project directory:"
docker exec test_container ls -la $PROJECT_DIR
echo "Contents of tests directory:"
docker exec test_container ls -la $TEST_DIR

# Install pytest
docker exec test_container pip install pytest

# Run pytest from the project directory
echo "Running pytest from the project directory:"
docker exec -w $PROJECT_DIR test_container python -m pytest tests -v

# Clean up
docker stop test_container
docker rm test_container

- name: Output test results
if: failure()
run: |
echo "Tests failed. Please check the test output above for more details."
7 changes: 3 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ RUN \
echo ". ${CONDA_DIR}/etc/profile.d/conda.sh && conda activate base" >> /etc/skel/.bashrc && \
echo ". ${CONDA_DIR}/etc/profile.d/conda.sh && conda activate base" >> ~/.bashrc

ADD ./env/deeprank2.yml /home/deeprank2
ADD ./env/deeprank2.yml /home/deeprank2/
ADD ./tutorials /home/deeprank2/tutorials

RUN \
## Create the environment and install the dependencies
Expand All @@ -35,7 +36,7 @@ RUN \
# Get the data for running the tutorials
if [ -d "/home/deeprank2/tutorials/data_raw" ]; then rm -Rf /home/deeprank2/tutorials/data_raw; fi && \
if [ -d "/home/deeprank2/tutorials/data_processed" ]; then rm -Rf /home/deeprank2/tutorials/data_processed; fi && \
wget https://zenodo.org/records/8349335/files/data_raw.zip && \
wget https://zenodo.org/records/13709906/files/data_raw.zip && \
unzip data_raw.zip -d data_raw && \
mv data_raw /home/deeprank2/tutorials && \
apt-get clean && \
Expand All @@ -45,8 +46,6 @@ RUN \
find ${CONDA_DIR} -follow -type f -name '*.pyc' -delete && \
conda clean --force-pkgs-dirs --all --yes

ADD ./tutorials /home/deeprank2/tutorials

ENV PATH /opt/conda/envs/deeprank2/bin:$PATH

# Define working directory
Expand Down
Loading
Loading