Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix parameter to set the build image #3

Merged
merged 3 commits into from
Aug 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"]
13 changes: 12 additions & 1 deletion 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.mysql-server.network }}` in the workflow
that uses this Action.

## Outputs

## None
Expand All @@ -37,10 +46,12 @@ the container. Defaults to `".github/workflows/build.sh"`

```yaml
- name: "Build Package"
uses: wtsi-npg/build-irods-client-action@v1
uses: wtsi-npg/build-irods-client-action@v1.1.1
with:
build-image:
ghcr.io/wtsi-npg/ub-22.04-irods-clients-dev-4.3.2:latest
build-script:
.github/workflows/build.sh
docker-network:
service-network
```
34 changes: 18 additions & 16 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,26 +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
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:$PWD --workdir $PWD 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"