diff --git a/.github/workflows/docker-build-all.yml b/.github/workflows/docker-build-all.yml new file mode 100644 index 0000000..8ece15a --- /dev/null +++ b/.github/workflows/docker-build-all.yml @@ -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 + diff --git a/.github/workflows/docker-build-push.yml b/.github/workflows/docker-build-push.yml new file mode 100644 index 0000000..e8327cb --- /dev/null +++ b/.github/workflows/docker-build-push.yml @@ -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 + diff --git a/bin/generate_matrix.py b/bin/generate_matrix.py new file mode 100644 index 0000000..3e077e3 --- /dev/null +++ b/bin/generate_matrix.py @@ -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)) diff --git a/dockerfiles/mane2110/metadata.json b/dockerfiles/mane2110/metadata.json new file mode 100644 index 0000000..99c1ffc --- /dev/null +++ b/dockerfiles/mane2110/metadata.json @@ -0,0 +1,3 @@ +{ + "pushLatest": false +} diff --git a/dockerfiles/mane2110/scipy/Dockerfile b/dockerfiles/mane2110/scipy/Dockerfile new file mode 100644 index 0000000..fae1cc2 --- /dev/null +++ b/dockerfiles/mane2110/scipy/Dockerfile @@ -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