-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
186 additions
and
0 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,43 @@ | ||
name: Docker Build All and Push | ||
|
||
on: | ||
workflow_dispatch: | ||
|
||
jobs: | ||
generate-matrix: | ||
runs-on: ubuntu-latest | ||
outputs: | ||
matrix: ${{ steps.set-matrix.outputs.matrix }} | ||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v3 | ||
- name: Set Matrix | ||
id: set-matrix | ||
run: | | ||
echo "matrix=$(python3 bin/generate_matrix.py ${{ secrets.DOCKER_USERNAME_SUBMITTY }} true)" >> $GITHUB_OUTPUT | ||
- name: List Matrix | ||
run: | | ||
echo ${{ steps.set-matrix.outputs.matrix }} | ||
docker: | ||
needs: | ||
- generate-matrix | ||
runs-on: ubuntu-latest | ||
strategy: | ||
fail-fast: true | ||
matrix: ${{ fromJson(needs.generate-matrix.outputs.matrix) }} | ||
steps: | ||
- name: Check out repo | ||
uses: actions/checkout@v3 | ||
- name: Docker Hub login | ||
uses: docker/login-action@releases/v1 | ||
with: | ||
username: ${{ secrets.DOCKER_USERNAME_SUBMITTYRPI }} | ||
password: ${{ secrets.DOCKER_PASSWORD_SUBMITTYRPI }} | ||
- name: Build and push docker | ||
uses: docker/build-push-action@v4 | ||
with: | ||
context: ${{ matrix.context }} | ||
push: true | ||
tags: ${{ matrix.tags }} | ||
platforms: linux/amd64,linux/arm64 | ||
|
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,47 @@ | ||
name: Docker Build and Push | ||
|
||
on: | ||
# push: temporarily disable | ||
# branches: | ||
# - "main" | ||
|
||
jobs: | ||
generate-matrix: | ||
runs-on: ubuntu-latest | ||
outputs: | ||
matrix: ${{ steps.set-matrix.outputs.matrix }} | ||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v3 | ||
with: | ||
fetch-depth: ${{ github.event_name == 'pull_request' && 2 || 0 }} | ||
- name: Set Matrix | ||
id: set-matrix | ||
run: | | ||
echo "matrix=$(python3 bin/generate_matrix.py ${{ secrets.DOCKER_USERNAME_SUBMITTY }} false ${{ github.event.before }} ${{ github.event.after }})" >> $GITHUB_OUTPUT | ||
- name: List Matrix | ||
run: | | ||
echo ${{ steps.set-matrix.outputs.matrix }} | ||
docker: | ||
needs: | ||
- generate-matrix | ||
runs-on: ubuntu-latest | ||
strategy: | ||
fail-fast: true | ||
matrix: ${{ fromJson(needs.generate-matrix.outputs.matrix) }} | ||
steps: | ||
- name: Check out repo | ||
uses: actions/checkout@v3 | ||
- name: Docker Hub login | ||
uses: docker/login-action@releases/v1 | ||
with: | ||
username: ${{ secrets.DOCKER_USERNAME_SUBMITTYRPI }} | ||
password: ${{ secrets.DOCKER_PASSWORD_SUBMITTYRPI }} | ||
- name: Build and push docker | ||
uses: docker/build-push-action@v4 | ||
with: | ||
context: ${{ matrix.context }} | ||
push: true | ||
tags: ${{ matrix.tags }} | ||
platforms: linux/amd64,linux/arm64 | ||
|
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,87 @@ | ||
import json | ||
import os | ||
import subprocess | ||
import sys | ||
from pathlib import Path | ||
|
||
if len(sys.argv) > 5: | ||
print("Too many arguments!", file=sys.stderr) | ||
exit(1) | ||
elif len(sys.argv) < 3: | ||
print("Not enough arguments!", file=sys.argv) | ||
exit(1) | ||
|
||
if not os.path.isdir("dockerfiles"): | ||
print("dockerfiles missing!", file=sys.stderr) | ||
exit(1) | ||
|
||
username = sys.argv[1] | ||
build_all = sys.argv[2] | ||
|
||
to_build = [] | ||
|
||
if build_all == "false": | ||
hash_before = sys.argv[3] | ||
hash_after = sys.argv[4] | ||
|
||
# Get list of all changed files between 2 commits | ||
output = subprocess.check_output(["git", "--no-pager", "diff", "--name-only", hash_before, hash_after]) | ||
paths_updated = output.decode("utf-8").splitlines() | ||
|
||
for path in paths_updated: | ||
parts = Path(path).parts | ||
# Only rebuild if modified files were in dockerfiles | ||
if parts[0] != "dockerfiles": | ||
continue | ||
|
||
metadata = json.loads(open(Path(parts[0]) / parts[1] / "metadata.json").read()) | ||
|
||
push_latest = False | ||
|
||
if metadata["pushLatest"]: | ||
if metadata["latestImage"] == parts[2]: | ||
push_latest = True | ||
|
||
tags = f"{username}/{parts[1]}:{parts[2]}" | ||
if push_latest: | ||
tags += f",{username}/{parts[1]}:latest" | ||
to_build.append( | ||
{ | ||
"tags": tags, | ||
"context": str(os.path.dirname(path)) | ||
} | ||
) | ||
elif build_all == "true": | ||
images = os.listdir("dockerfiles") | ||
for image in images: | ||
path = Path("dockerfiles") / image | ||
if not path.is_dir(): | ||
continue | ||
|
||
metadata = json.loads(open(path / "metadata.json").read()) | ||
|
||
tags = os.listdir(path) | ||
for tag in tags: | ||
newpath = path / tag | ||
if not newpath.is_dir(): | ||
continue | ||
|
||
push_latest = False | ||
if metadata["pushLatest"]: | ||
if metadata["latestImage"] == tag: | ||
push_latest = True | ||
|
||
tags = f"{username}/{image}:{tag}" | ||
if push_latest: | ||
tags += f",{username}/{image}:latest" | ||
to_build.append( | ||
{ | ||
"tags": tags, | ||
"context": str(newpath) | ||
} | ||
) | ||
|
||
|
||
finobj = {"include": to_build} | ||
|
||
print(json.dumps(finobj)) |
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,3 @@ | ||
{ | ||
"pushLatest": false | ||
} |
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,6 @@ | ||
FROM submitty/python | ||
|
||
RUN pip3 install scipy | ||
|
||
# Will eventually be removed | ||
RUN ln -s /usr/local/bin/python3 /usr/bin/python3 |