Skip to content

Commit

Permalink
Fix Docker mirroring job for release context (#4303)
Browse files Browse the repository at this point in the history
and secure job input parameters
  • Loading branch information
nvuillam authored Nov 23, 2024
1 parent 9cb4ec7 commit 9824f37
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 5 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/deploy-RELEASE-flavors.yml
Original file line number Diff line number Diff line change
Expand Up @@ -112,17 +112,19 @@ jobs:
with:
workflow: mirror-docker-image.yml
inputs: '{ "source-image": "ghcr.io/oxsecurity/megalinter-${{ matrix.flavor }}:v8", "target-image": "docker.io/oxsecurity/megalinter-${{ matrix.flavor }}:v8" }'
ref: main
- name: Invoke Mirror docker image workflow (Main image)
uses: benc-uk/workflow-dispatch@v1
with:
workflow: mirror-docker-image.yml
inputs: '{ "source-image": "ghcr.io/oxsecurity/megalinter-${{ matrix.flavor }}:v8", "target-image": "docker.io/oxsecurity/megalinter-${{ matrix.flavor }}:${{ github.event.release.tag_name }}" }'
ref: main
- name: Invoke Mirror docker image workflow (Main image)
uses: benc-uk/workflow-dispatch@v1
with:
workflow: mirror-docker-image.yml
inputs: '{ "source-image": "ghcr.io/oxsecurity/megalinter-${{ matrix.flavor }}:v8", "target-image": "docker.io/oxsecurity/megalinter-${{ matrix.flavor }}:latest" }'

ref: main
# - name: Build Worker Image
# uses: docker/build-push-action@v6
# with:
Expand Down
4 changes: 3 additions & 1 deletion .github/workflows/deploy-RELEASE-linters.yml
Original file line number Diff line number Diff line change
Expand Up @@ -219,17 +219,19 @@ jobs:
with:
workflow: mirror-docker-image.yml
inputs: '{ "source-image": "ghcr.io/oxsecurity/megalinter-only-${{ matrix.linter }}:v8", "target-image": "docker.io/oxsecurity/megalinter-only-${{ matrix.linter }}:v8" }'
ref: main
- name: Invoke Mirror docker image workflow (Standalone image)
uses: benc-uk/workflow-dispatch@v1
with:
workflow: mirror-docker-image.yml
inputs: '{ "source-image": "ghcr.io/oxsecurity/megalinter-only-${{ matrix.linter }}:v8", "target-image": "docker.io/oxsecurity/megalinter-only-${{ matrix.linter }}:${{ github.event.release.tag_name }}" }'
ref: main
- name: Invoke Mirror docker image workflow (Standalone image)
uses: benc-uk/workflow-dispatch@v1
with:
workflow: mirror-docker-image.yml
inputs: '{ "source-image": "ghcr.io/oxsecurity/megalinter-only-${{ matrix.linter }}:v8", "target-image": "docker.io/oxsecurity/megalinter-only-${{ matrix.linter }}:latest" }'

ref: main
#####################################
# Run Linter test cases #
#####################################
Expand Down
4 changes: 3 additions & 1 deletion .github/workflows/deploy-RELEASE.yml
Original file line number Diff line number Diff line change
Expand Up @@ -108,17 +108,19 @@ jobs:
with:
workflow: mirror-docker-image.yml
inputs: '{ "source-image": "ghcr.io/oxsecurity/megalinter:v8", "target-image": "docker.io/oxsecurity/megalinter:v8" }'
ref: main
- name: Invoke Mirror docker image workflow (Main image)
uses: benc-uk/workflow-dispatch@v1
with:
workflow: mirror-docker-image.yml
inputs: '{ "source-image": "ghcr.io/oxsecurity/megalinter:v8", "target-image": "docker.io/oxsecurity/megalinter:${{ github.event.release.tag_name }}" }'
ref: main
- name: Invoke Mirror docker image workflow (Main image)
uses: benc-uk/workflow-dispatch@v1
with:
workflow: mirror-docker-image.yml
inputs: '{ "source-image": "ghcr.io/oxsecurity/megalinter:v8", "target-image": "docker.io/oxsecurity/megalinter:latest" }'

ref: main
# - name: Build Worker Image
# uses: docker/build-push-action@v6
# with:
Expand Down
31 changes: 29 additions & 2 deletions .github/workflows/mirror-docker-image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ on:
jobs:

copy-to-docker-hub-alpha:
if: github.ref_name == 'alpha'
if: github.ref_name == 'alpha' && endsWith(github.event.inputs.source-image,'alpha') && endsWith(github.event.inputs.target-image,'alpha')
runs-on: ubuntu-latest
environment:
name: alpha
Expand All @@ -44,7 +44,7 @@ jobs:
run: docker push "${{ github.event.inputs.target-image }}"

copy-to-docker-hub-main:
if: github.ref_name == 'main' || startsWith(github.ref_name, 'v')
if: github.ref_name == 'main' && endsWith(github.event.inputs.source-image,'beta') && endsWith(github.event.inputs.target-image,'beta')
runs-on: ubuntu-latest
environment:
name: beta
Expand All @@ -69,3 +69,30 @@ jobs:
run: docker tag "${{ github.event.inputs.source-image }}" "${{ github.event.inputs.target-image }}"
- name: Push image to Docker Hub
run: docker push "${{ github.event.inputs.target-image }}"

copy-to-docker-hub-release:
if: github.ref_name == 'main' && contains(github.event.inputs.source-image,'v8') && (contains(github.event.inputs.target-image,'v8') || contains(github.event.inputs.target-image,'latest'))
runs-on: ubuntu-latest
environment:
name: release
steps:
# Free disk space
- name: Free Disk space
if: github.event.inputs.free-space-before == 'true'
shell: bash
run: |
sudo rm -rf /usr/local/lib/android # will release about 10 GB if you don't need Android
sudo rm -rf /usr/share/dotnet # will release about 20GB if you don't need .NET
# Login to docker hub
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
# Copy ghrc.io image to Docker Hub
- name: Pull image from GHCR
run: docker pull "${{ github.event.inputs.source-image }}"
- name: Tag image for Docker Hub
run: docker tag "${{ github.event.inputs.source-image }}" "${{ github.event.inputs.target-image }}"
- name: Push image to Docker Hub
run: docker push "${{ github.event.inputs.target-image }}"
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ Note: Can be used with `oxsecurity/megalinter@beta` in your GitHub Action mega-l
- Flavors

- CI
- Fix Docker mirroring job for release context

- mega-linter-runner

Expand Down

0 comments on commit 9824f37

Please sign in to comment.