Skip to content

Commit

Permalink
Add container build/push actions (#260)
Browse files Browse the repository at this point in the history
* `singularity`: push built container to https://ghcr.io
Fixes #256

* bump apt package versions

* trigger on PR

* build gwas container

* trigger build

* trigger on any change

* build python3 and r containers

* trigger on reopened PR

* bump libssl-dev version

* don't set GITHUB_TOKEN

* add GITHUB_TOKEN to Dockerfile ENV

* secrets

* bump action version

* no github_token file?

* bump git version

* lowercase

* GITHUB_PAT

* test sleep

* something else

* secrets

* libgomp1 version up; redundant install removed

* expose to env, fixes

* `singularity`: push built container to https://ghcr.io
Fixes #256

* explicit install of deps from GitHub sources

* comma

* update INSTALL.md

* edits

* fixes
  • Loading branch information
espenhgn authored Jun 25, 2024
1 parent f5c9793 commit 47ca5b8
Show file tree
Hide file tree
Showing 20 changed files with 692 additions and 45 deletions.
53 changes: 53 additions & 0 deletions .github/workflows/docker_build_gwas.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# action to build the gwas Docker image at each commit without pushing it
name: build gwas Docker image

on:
pull_request:
branches:
- 'main'
push:
branches:
- 'main'
tags:
- "v*.*.*"

jobs:
docker:
runs-on: ubuntu-latest
steps:
-
name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
images: |
ghcr.io/${{ github.repository_owner }}/containers
tags: |
type=ref,event=branch
type=semver,pattern={{version}}
type=sha
type=raw,value=latest,enable={{is_default_branch}}
-
name: Set up QEMU
uses: docker/setup-qemu-action@v3
-
name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
-
name: Login to GitHub Container Registry
if: github.event_name != 'pull_request'
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
-
name: Build and push
uses: docker/build-push-action@v5
with:
context: "{{defaultContext}}:docker"
push: False
tags: ${{ steps.meta.outputs.tags }}
file:
./dockerfiles/gwas/Dockerfile
platforms: linux/amd64
53 changes: 53 additions & 0 deletions .github/workflows/docker_build_hello.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# action to build the hello Docker image at each commit without pushing it
name: build hello Docker image

on:
pull_request:
branches:
- 'main'
push:
branches:
- 'main'
tags:
- "v*.*.*"

jobs:
docker:
runs-on: ubuntu-latest
steps:
-
name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
images: |
ghcr.io/${{ github.repository_owner }}/containers
tags: |
type=ref,event=branch
type=semver,pattern={{version}}
type=sha
type=raw,value=latest,enable={{is_default_branch}}
-
name: Set up QEMU
uses: docker/setup-qemu-action@v3
-
name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
-
name: Login to GitHub Container Registry
if: github.event_name != 'pull_request'
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
-
name: Build and push
uses: docker/build-push-action@v5
with:
context: "{{defaultContext}}:docker"
push: False
tags: ${{ steps.meta.outputs.tags }}
file:
./dockerfiles/hello/Dockerfile
platforms: linux/amd64
84 changes: 84 additions & 0 deletions .github/workflows/docker_build_push_gwas.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
# action to build and push the gwas Docker and Singularity image at each tag (for release)
name: container build push

on:
push:
tags:
- "v*.*.*"

jobs:
docker:
runs-on: ubuntu-latest
steps:
-
name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
images: |
ghcr.io/${{ github.repository_owner }}/containers
tags: |
type=ref,event=branch
type=semver,pattern={{version}}
type=sha
type=raw,value=latest,enable={{is_default_branch}}
-
name: Set up QEMU
uses: docker/setup-qemu-action@v3
-
name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
-
name: Login to GitHub Container Registry
if: github.event_name != 'pull_request'
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
-
name: Build and push
uses: docker/build-push-action@v5
with:
context: "{{defaultContext}}:docker"
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
file:
./dockerfiles/gwas/Dockerfile
platforms: linux/amd64

build-apptainer-container:
needs: docker
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
name: Build Apptainer Container
steps:
- name: Check out code for the container builds
uses: actions/checkout@v4
- name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
images: |
ghcr.io/${{ github.repository_owner }}/gwas
tags: |
type=semver,pattern={{version}}
type=ref,event=branch
type=sha
type=raw,value=latest,enable={{is_default_branch}}
- name: Build and push Apptainer container
run: |
tags="${{ steps.meta.outputs.tags }}"
csv_tags=$(printf "%s\n" "$tags" | awk -F: 'NR==1{printf "%s,", $0; next} {printf "%s,", $NF}' | sed 's/,$//')
IFS= read -r first_tag <<EOF
$tags
EOF
push_tags="$(printf $csv_tags | sed -e "s/gwas/gwas_sif/g")"
echo ${{ secrets.GITHUB_TOKEN }} | oras login --username ${{ github.repository_owner }} --password-stdin ghcr.io
docker pull kaczmarj/apptainer:latest
docker run --rm --privileged -v $(pwd):/work kaczmarj/apptainer build gwas.sif docker://"$first_tag"
oras push "$push_tags" --artifact-type application/vnd.acme.rocket.config gwas.sif
rm gwas.sif
shell: sh
84 changes: 84 additions & 0 deletions .github/workflows/docker_build_push_hello.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
# action to build and push the hello Docker and Singularity image at each tag (for release)
name: container build push

on:
push:
tags:
- "v*.*.*"

jobs:
docker:
runs-on: ubuntu-latest
steps:
-
name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
images: |
ghcr.io/${{ github.repository_owner }}/containers
tags: |
type=ref,event=branch
type=semver,pattern={{version}}
type=sha
type=raw,value=latest,enable={{is_default_branch}}
-
name: Set up QEMU
uses: docker/setup-qemu-action@v3
-
name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
-
name: Login to GitHub Container Registry
if: github.event_name != 'pull_request'
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
-
name: Build and push
uses: docker/build-push-action@v5
with:
context: "{{defaultContext}}:docker"
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
file:
./dockerfiles/hello/Dockerfile
platforms: linux/amd64

build-apptainer-container:
needs: docker
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
name: Build Apptainer Container
steps:
- name: Check out code for the container builds
uses: actions/checkout@v4
- name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
images: |
ghcr.io/${{ github.repository_owner }}/hello
tags: |
type=semver,pattern={{version}}
type=ref,event=branch
type=sha
type=raw,value=latest,enable={{is_default_branch}}
- name: Build and push Apptainer container
run: |
tags="${{ steps.meta.outputs.tags }}"
csv_tags=$(printf "%s\n" "$tags" | awk -F: 'NR==1{printf "%s,", $0; next} {printf "%s,", $NF}' | sed 's/,$//')
IFS= read -r first_tag <<EOF
$tags
EOF
push_tags="$(printf $csv_tags | sed -e "s/hello/hello_sif/g")"
echo ${{ secrets.GITHUB_TOKEN }} | oras login --username ${{ github.repository_owner }} --password-stdin ghcr.io
docker pull kaczmarj/apptainer:latest
docker run --rm --privileged -v $(pwd):/work kaczmarj/apptainer build hello.sif docker://"$first_tag"
oras push "$push_tags" --artifact-type application/vnd.acme.rocket.config hello.sif
rm hello.sif
shell: sh
84 changes: 84 additions & 0 deletions .github/workflows/docker_build_push_python3.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
# action to build and push the python3 Docker and Singularity image at each tag (for release)
name: container build push

on:
push:
tags:
- "v*.*.*"

jobs:
docker:
runs-on: ubuntu-latest
steps:
-
name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
images: |
ghcr.io/${{ github.repository_owner }}/containers
tags: |
type=ref,event=branch
type=semver,pattern={{version}}
type=sha
type=raw,value=latest,enable={{is_default_branch}}
-
name: Set up QEMU
uses: docker/setup-qemu-action@v3
-
name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
-
name: Login to GitHub Container Registry
if: github.event_name != 'pull_request'
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
-
name: Build and push
uses: docker/build-push-action@v5
with:
context: "{{defaultContext}}:docker"
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
file:
./dockerfiles/python3/Dockerfile
platforms: linux/amd64

build-apptainer-container:
needs: docker
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
name: Build Apptainer Container
steps:
- name: Check out code for the container builds
uses: actions/checkout@v4
- name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
images: |
ghcr.io/${{ github.repository_owner }}/python3
tags: |
type=semver,pattern={{version}}
type=ref,event=branch
type=sha
type=raw,value=latest,enable={{is_default_branch}}
- name: Build and push Apptainer container
run: |
tags="${{ steps.meta.outputs.tags }}"
csv_tags=$(printf "%s\n" "$tags" | awk -F: 'NR==1{printf "%s,", $0; next} {printf "%s,", $NF}' | sed 's/,$//')
IFS= read -r first_tag <<EOF
$tags
EOF
push_tags="$(printf $csv_tags | sed -e "s/python3/python3_sif/g")"
echo ${{ secrets.GITHUB_TOKEN }} | oras login --username ${{ github.repository_owner }} --password-stdin ghcr.io
docker pull kaczmarj/apptainer:latest
docker run --rm --privileged -v $(pwd):/work kaczmarj/apptainer build python3.sif docker://"$first_tag"
oras push "$push_tags" --artifact-type application/vnd.acme.rocket.config python3.sif
rm python3.sif
shell: sh
Loading

0 comments on commit 47ca5b8

Please sign in to comment.