Skip to content

Commit

Permalink
installing the script with python -m pip install instead of downloadi…
Browse files Browse the repository at this point in the history
…ng the whole repo
  • Loading branch information
ThomasCardin committed Feb 6, 2024
1 parent 38e3394 commit f5c6ce4
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 99 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ merge a pull request, the workflow will be triggered and will start 2 jobs.
The first job will build and push the new image with 2 tags. The first tag is
the pull request number, and the second tag is the commit that triggered the
action. The second job will remove the previous image based on the previous
tag using [this script](/scripts/remove-old-image.py). If no Dockerfile is found
tag. If no Dockerfile is found
at the root of the repository, the workflow will be cancelled.
- **Required Secrets:**
- None
23 changes: 11 additions & 12 deletions .github/workflows/workflow-build-push-container-github-registry.yml
Original file line number Diff line number Diff line change
Expand Up @@ -104,27 +104,26 @@ jobs:
runs-on: ubuntu-latest
needs: build-push-image
steps:
- name: Check Out Repo
uses: actions/checkout@v4

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

- name: Set up Python
uses: actions/setup-python@v3
with:
python-version: 3.8

- name: Install Python dependencies
run: pip install requests
- name: Install the remove-previous-image from github.com/ai-cfia/devops inside the user-site
run: python -m pip install --user git+https://$USER:$USER_TOKEN@github.com/ai-cfia/devops.git@26-as-a-devops-i-want-to-create-unit-tests-for-the-remove-previous-imagepy-script
env:
USER: ${{ secrets.USER }}
USER_TOKEN: ${{ secrets.USER_TOKEN }}

- name: Download the python script from https://github.com/ai-cfia/github-workflows to delete the previous image
- name: Access user site-packages
run: |
curl -LO https://raw.githubusercontent.com/ai-cfia/github-workflows/63-as-a-devops-i-would-like-to-create-a-workflow-to-push-images-to-this-organisation-docker-registry/scripts/remove-old-image.py
USER_SITE=$(python -m site --user-site)
echo "Path to site-packages is $USER_SITE"
echo "USER_SITE=$USER_SITE" >> $GITHUB_ENV
- name: Delete the previous image (unmerged pull request)
if: github.event.pull_request.merged == false
run: python remove-old-image.py
run: python $USER_SITE/remove-previous-image/remove_previous_image.py
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
REGISTRY: ${{ inputs.registry }}
Expand All @@ -135,7 +134,7 @@ jobs:

- name: Delete the previous image (merged pull request)
if: github.event.pull_request.merged == true
run: python remove-old-image.py
run: python $USER_SITE/remove-previous-image/remove_previous_image.py
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
REGISTRY: ${{ inputs.registry }}
Expand Down
86 changes: 0 additions & 86 deletions scripts/remove-old-image.py

This file was deleted.

0 comments on commit f5c6ce4

Please sign in to comment.