Skip to content

Commit

Permalink
Workaround
Browse files Browse the repository at this point in the history
  • Loading branch information
kjsanger committed Aug 19, 2024
1 parent c8f89ad commit 0b4c124
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 26 deletions.
8 changes: 5 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
ARG BASE_IMAGE

FROM $BASE_IMAGE
FROM alpine:latest

COPY docker-action /docker-action
COPY entrypoint.sh /entrypoint.sh

RUN apk add --update --no-cache docker
RUN ["chmod", "+x", "/entrypoint.sh"]

ENTRYPOINT ["/entrypoint.sh"]
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,15 @@ the container. Defaults to `".github/workflows/build.sh"`
**Required** The iRODS client builder image to use as a base image. Defaults to
`"ghcr.io/wtsi-npg/ub-18.04-irods-clients-dev-4.2.11:latest"`

## `docker-network`

**Required** The Docker network on which to run the jobs. Defaults to "host".
Use this if your calling workflow has configured some services that are running
in Docker containers. The correct value is available in the job context. E.g.
if you have a service called "mysql-server" then the Docker network name will
be available as `${{ job.services.myswl-server.network }}` in the workflow
that uses this Action.

## Outputs

## None
Expand All @@ -43,4 +52,6 @@ the container. Defaults to `".github/workflows/build.sh"`
ghcr.io/wtsi-npg/ub-22.04-irods-clients-dev-4.3.2:latest
build-script:
.github/workflows/build.sh
docker-network:
service-network
```
36 changes: 18 additions & 18 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,28 +11,28 @@ inputs:
description: "Build script to run in the container"
required: true
default: ".github/workflows/build.sh"
docker-network:
description: "Docker network to use for the container"
required: false
default: "host"

# The simple approach to implementing this Action described here:
# https://docs.github.com/en/actions/creating-actions/creating-a-docker-container-action
# does not work because value given in input.build-image is not available to the
# does not work because a value given in input.build-image is not available to the
# run.image field.
#
# One workaround is to use a composite run action, although that's not very well
# documented and I maye be doing it wrong.
# One workaround is described here:
# https://github.com/JavierZolotarchuk/parameterizable-docker-action-example
#
# Credit to JavierZolotarchuk for the workaround described in the link above. I've used
# it here. In order for the Action to be able to use Docker services set up by the calling
# workflow, it must know the name of the Docker network to use. This is passed in as a
# another parameter.

runs:
using: "composite"
steps:
- name: "Build a new image for this run"
env:
BASE_IMAGE: ${{ inputs.build-image }}
run: |
docker pull $BASE_IMAGE
pwd
ls -l
docker build --build-arg BASE_IMAGE=$BASE_IMAGE -t test-img-${{github.run_id}} .
shell: bash
- name: "Run the client build in the new image"
run: |
docker run --rm -t -v $(pwd):/github/workspace --workdir /github/workspace test-img-${{github.run_id}} ${{ inputs.build-script }}
shell: bash
using: 'docker'
image: 'Dockerfile'
args:
- ${{ inputs.build-image }}
- ${{ inputs.build-script }}
- ${{ inputs.docker-network }}
9 changes: 9 additions & 0 deletions docker-action/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
ARG BASE_IMAGE

FROM $BASE_IMAGE

COPY entrypoint.sh /entrypoint.sh

RUN ["chmod", "+x", "/entrypoint.sh"]

ENTRYPOINT ["/entrypoint.sh"]
8 changes: 8 additions & 0 deletions docker-action/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/bash -l

set -x

echo $PWD
ls -l

exec "$1"
27 changes: 22 additions & 5 deletions entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,25 @@
#!/bin/bash -l
#!/bin/sh -l

set -x
set -ex

echo $PWD
ls -l
BASE_IMAGE=$1
BUILD_SCRIPT=$2
NETWORK=$3

exec "$1"
cd /docker-action

echo "Creating Docker image from: $BASE_IMAGE"
docker build -t docker-action --build-arg BASE_IMAGE="$BASE_IMAGE" .

# Credit to https://github.com/zmingxie/packer-ami-builder for the following
# logic to determine the workspace directory
REPO_NAME=$(basename $RUNNER_WORKSPACE)
WORKSPACE="$RUNNER_WORKSPACE/$REPO_NAME"

echo "Using Docker network: $NETWORK"

echo "Running build script: $BUILD_SCRIPT"
docker run -t -v $WORKSPACE:$GITHUB_WORKSPACE \
--workdir $GITHUB_WORKSPACE \
--network $NETWORK \
docker-action "$BUILD_SCRIPT"

0 comments on commit 0b4c124

Please sign in to comment.