Skip to content

Commit

Permalink
adding simpledeploy example (#2)
Browse files Browse the repository at this point in the history
Signed-off-by: vsoch <vsoch@users.noreply.github.com>
Co-authored-by: vsoch <vsoch@users.noreply.github.com>
  • Loading branch information
vsoch and vsoch committed Nov 13, 2021
1 parent c975562 commit 5ac54b8
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 1 deletion.
61 changes: 61 additions & 0 deletions .github/workflows/simple-build-deploy.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
name: Simple Build Containers
on:
workflow_dispatch: []
pull_request: []
push:
branches:
- main

jobs:
build:
runs-on: ubuntu-latest
permissions:
packages: write
strategy:
fail-fast: false
matrix:

# This is an example Dockerfile matrix - you could imagine extending it to different bases, etc.
# You could also generate this dynamically and pipe in the json. See
# https://github.com/buildsi/spack-containers/blob/11cbac76201e963006b2321e30b153f38687505f/.github/workflows/build-containers.yaml#L24

# base image # dockerfile
container: [["ubuntu:20.04", Dockerfile]]

name: Build ${{ matrix.container[0] }} ${{ matrix.arch }}
steps:
- name: Checkout
uses: actions/checkout@v2

- name: Set Container Name
env:
base: ${{ matrix.container[0] }}
run: |
base=$(echo ${base/:/-})
container="ghcr.io/vsoch/spack-simple-${base}:latest"
echo "container=${container}" >> $GITHUB_ENV
- name: Log in to GitHub Container Registry
uses: docker/login-action@v1
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Simple Docker Build
run: |
docker build -t ${{ env.container }} --build-arg base=${{ matrix.container[0] }} .
- name: Label
run: |
docker run -i --rm ${{ env.container }} spack compiler list --flat > compilers.txt
labels=$(echo $(tr '\r\n' ',' < compilers.txt))
labels="org.spack.compilers=${labels}"
printf "Saving compiler labels ${labels}\n"
echo "FROM ${{ env.container }}" > Dockerfile.tmp
docker build -t ${{ env.container }} -f Dockerfile.tmp --label ${labels} .
- name: Deploy
if: ${{ github.event_name != 'pull_request' }}
run: |
docker push ${{ env.container }}
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ others. The example here will build a simple container with spack, and then
generate (and apply) some labels after the fact. This works doing the following:

1. Define a [Dockerfile](Dockerfile) with something that warrants post-labeling. I chose spack compilers.
2. Use the [GitHub Workflow](.github/workflows/build-deploy.yaml) to build a matrix of containers and apply the label post build.
2. Use the [GitHub Workflow](.github/workflows/build-deploy.yaml) to build a matrix of containers and apply the label post build for multiple arches, or a [simpler workflow](.github/workflows/simple-build-deploy.yaml) that does the same.

The workflow uses buildx, but separates arches into separate builds, each with a different container
architecture (and tagged appropriately).
Expand Down

0 comments on commit 5ac54b8

Please sign in to comment.