Skip to content

Commit

Permalink
Add github actions docker example
Browse files Browse the repository at this point in the history
  • Loading branch information
gcapes committed Oct 7, 2022
1 parent 4e9fb0d commit f360617
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 0 deletions.
20 changes: 20 additions & 0 deletions github-actions/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# syntax=docker/dockerfile:1.4.2

FROM ubuntu:20.04

## Install requirements

RUN apt-get update && DEBIAN_FRONTEND=noninteractive TZ=Etc/UTC \
apt-get install -y \
nodejs \
npm

## Install ro-crate-html-js
RUN npm install ro-crate-html-js
ENV PATH "/node_modules/.bin:$PATH"

## Copy code file from repo to Docker filesystem
COPY entrypoint.sh /entrypoint.sh

## Code to run when the docker container starts
ENTRYPOINT ["/entrypoint.sh"]
15 changes: 15 additions & 0 deletions github-actions/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
name: 'rocrate-to-html'
description: 'This creates a preview html file from the rocrate json metadata file'
inputs:
crate_path:
description: 'Path to ro-crate-metadata.json'
required: false
default: '.'
outputs:
preview:
description: 'HTML preview of the RO Crate'
runs:
using: 'docker'
image: 'Dockerfile'
args:
- ${{ inputs.crate_path }}
21 changes: 21 additions & 0 deletions github-actions/docker.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Github actions

## Local action using Docker

A local github action requires an [`action.yml`](action.yml) (in the root directory of the repo) which shows the tool to be used and its inputs and outputs.

## The [Dockerfile](Dockerfile)

This needs to copy an [`entrypoint.sh`](entrypoint.sh) file to the container and run it using an `ENTRYPOINT` command. `entrypoint.sh` contains the commands you want to run in the container. This is instead of building the `docker run` command yourself on a command line.

## GitHub workflows

In order to actually run the action, you also need a file in the `.github/workflows/` directory. The name of the file isn't important.

This file details which actions trigger the workflow (e.g. push on a named branch) and which jobs to run. [Example file](rocrate_to_pages.yml)

## Deploying html to github pages

Use this [gh-pages-deploy](https://github.com/JamesIves/github-pages-deploy-action) action to deploy the html generated by the workflow. It will commit changes generated by previous steps to your `gh-pages` branch, and render them.

In brief, this step goes at the end of your workflow. [YouTube tutorial](https://youtu.be/jBZfo2Mj1mY)
3 changes: 3 additions & 0 deletions github-actions/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/sh -l
rochtml $1/ro-crate-metadata.json
echo "::set-output name=preview::ro-crate-preview.html"
22 changes: 22 additions & 0 deletions github-actions/rocrate_to_pages.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: RoCrate to GitHub Pages
on:
push:
branches:
- test
pull_request:
jobs:
build-and-deploy:
runs-on: ubuntu-20.04
concurrency: ci-${{github.ref}}
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Build RO Crate Preview
uses: ./ # Uses an action in the root directory

- name: Deploy
uses: JamesIves/github-pages-deploy-action@v4
with:
folder: .
branch: gh-pages

0 comments on commit f360617

Please sign in to comment.