Skip to content

fix command for json format #339

fix command for json format

fix command for json format #339

Workflow file for this run

name: Docker
# This workflow uses actions that are not certified by GitHub.
# They are provided by a third-party and are governed by
# separate terms of service, privacy policy, and support
# documentation.
on:
push:
branches: [ "master", "*" ]
# Publish semver tags as releases.
tags: [ 'v*.*.*' ]
paths-ignore:
- 'README.md'
pull_request:
branches: [ "*" ]
# Publish semver tags as releases.
tags: [ 'v*.*.*' ]
paths-ignore:
- 'README.md'
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
jobs:
# adapted from https://docs.github.com/en/actions/learn-github-actions/expressions#example-returning-a-json-object
metadata:
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.generate-matrix.outputs.matrix }} # contains a list of the module names encoded as json
modulenames: ${{ steps.generate-matrix.outputs.modulenames }} # contains a simple, space-separated list of the module names
steps:
- name: Checkout
uses: actions/checkout@v3
- name: generate matrix
id: generate-matrix
# adapted from https://stackoverflow.com/a/74829694
# modulenames="$(ls *.yml | sed 's/.yml//' | paste -s -d ' ')"
run: |
modulenames="chipseq gwas"
echo "modulenames=$modulenames" >> $GITHUB_OUTPUT
# echo $modulenames | tr ' ' '\n' | sed 's/^/type=gha,scope=builder-/' | paste -s
matrix=$(echo $modulenames | jq -R 'split(" ") | map({modulename: .})')
echo "matrix=$(echo $matrix | jq -c)" >> $GITHUB_OUTPUT
build-module-images:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
needs: [metadata]
strategy:
matrix: ${{ fromJson(needs.metadata.outputs.matrix) }}
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Log in to the Container registry
uses: docker/login-action@v2
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v4
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
- name: prune
run: docker system prune -af
- name: Builder Docker image
id: builder
uses: docker/build-push-action@v3
with:
context: .
file: Dockerfile
push: false
#tags: ${{ steps.meta.outputs.tags }} # TODO: do we need this?
cache-to: type=gha,mode=max
target: builder
builder-args: |
"modulename=${{ matrix.modulename }}"
build-and-push-image:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
needs: [metadata, build-module-images]
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Log in to the Container registry
uses: docker/login-action@v2
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v4
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
- name: prune
run: docker system prune -af
- name: Patch Dockerfile
id: patch-dockerfile
# use sed to add instructions to our Dockerfile
run: |
DOCKERFILE_CODE="# copy each of the modules into the current image"
for module in ${{ needs.metadata.outputs.modulenames }}; do
DOCKERFILE_CODE="$DOCKERFILE_CODE\nCOPY --from=builder-$module /opt/env /opt/conda/envs/$module"
DOCKERFILE_CODE="$DOCKERFILE_CODE\nENV PATH=\"/opt/conda/envs/$module/bin:\${PATH}\""
done
awk -v r="$DOCKERFILE_CODE" '{gsub(/^#KEEP.*$/,r)}1' Dockerfile > Dockerfile.patch
- name: Primary Docker image
id: primary
uses: docker/builder-push-action@v3
with:
context: .
file: Dockerfile.patch
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
target: primary