-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #640 from DeepRank/529_add_docker_testing_action_g…
…croci2 ci: add action for releasing new docker image and testing it
- Loading branch information
Showing
24 changed files
with
2,215 additions
and
1,991 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 |
---|---|---|
@@ -0,0 +1,70 @@ | ||
# SPDX-FileCopyrightText: 2022 Dusan Mijatovic (dv4all) | ||
# SPDX-FileCopyrightText: 2022 dv4all | ||
# SPDX-FileCopyrightText: 2024 Ewan Cahen (Netherlands eScience Center) <e.cahen@esciencecenter.nl> | ||
# 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 |
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
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
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
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
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
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
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
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
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
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
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
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
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,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." |
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
Oops, something went wrong.