Skip to content

Commit

Permalink
1 make into template (#2)
Browse files Browse the repository at this point in the history
* Updated README and default plugins

* Updated nomad-oasis.zip

* Update cron schedule for Docker workflow

* Add manual workflow dispatch option

* Add repository initialization workflow and build workflow
  • Loading branch information
hampusnasstrom authored Mar 6, 2024
1 parent 43bab0c commit 4023151
Show file tree
Hide file tree
Showing 10 changed files with 239 additions and 80 deletions.
15 changes: 3 additions & 12 deletions .github/workflows/docker-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@ name: Docker

on:
schedule:
- cron: '43 11 * * *'
- cron: '00 03 * * 0'
push:
branches: [ "main" ]
# Publish semver tags as releases.
tags: [ 'v*.*.*' ]
pull_request:
branches: [ "main" ]
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:

env:
# Use docker.io for Docker Hub if empty
Expand All @@ -23,17 +25,6 @@ env:


jobs:
compress:

name: Compress nomad-oasis configs
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Updated and compress the nomad-oasis directory
run: bash ${PWD}/nomad-oasis_files/scripts/update_nomad_oasis_dir.sh ${{ github.repository }}

build:

Expand Down
124 changes: 124 additions & 0 deletions .github/workflows/initialize.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@

name: Template Repository Initialization

on:
# Triggers the workflow on creation of repository
create:

env:
# Use docker.io for Docker Hub if empty
REGISTRY: ghcr.io
# github.repository as <account>/<repo>
IMAGE_NAME: ${{ github.repository }}

permissions:
contents: write

jobs:
initialize_repository:
if: github.repository != 'FAIRmat-NFDI/nomad-distribution-template'
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3

# Replaces the template repository name in the README with the new one
- name: Update README
run: |
sed -i "s|GITHUB_REPOSITORY_OWNER|${{ github.repository_owner }}|g" template_README.md
sed -i "s|GITHUB_REPOSITORY|${{ github.repository }}|g" template_README.md
mv template_README.md README.md
# Replaces the template repository name in the docker config file with the new one
- name: Update docker-compose.yml
run: |
cd nomad-oasis_files
sed -i "s|FAIRMAT_NFDI/nomad-distribution-template|${{ github.repository }}|g" docker-compose.yml
zip -r nomad-oasis.zip nomad-oasis
cd ..
# Deletes this workflow file to prevent it from running on branch creation
- name: Delete initialization workflow
run: rm .github/workflows/initialize.yml

# Commits all changes
- name: Commit repository initialization
run: |
git config --global user.name github-actions
git config --global user.email [email protected]
git commit -am "Repository initialization"
git push
build:
if: github.repository != 'FAIRmat-NFDI/nomad-distribution-template'
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
# This is used to complete the identity challenge
# with sigstore/fulcio when running outside of PRs.
id-token: write

steps:
- name: Checkout repository
uses: actions/checkout@v3

# Install the cosign tool except on PR
# https://github.com/sigstore/cosign-installer
- name: Install cosign
if: github.event_name != 'pull_request'
uses: sigstore/cosign-installer@6e04d228eb30da1757ee4e1dd75a0ec73a653e06 #v3.1.1
with:
cosign-release: 'v2.1.1'

# Set up BuildKit Docker container builder to be able to build
# multi-platform images and export cache
# https://github.com/docker/setup-buildx-action
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@f95db51fddba0c2d1ec667646a06c2ce06100226 # v3.0.0

# Login against a Docker registry except on PR
# https://github.com/docker/login-action
- name: Log into registry ${{ env.REGISTRY }}
if: github.event_name != 'pull_request'
uses: docker/login-action@343f7c4344506bcbf9b4de18042ae17996df046d # v3.0.0
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

# Extract metadata (tags, labels) for Docker
# https://github.com/docker/metadata-action
- name: Extract Docker metadata
id: meta
uses: docker/metadata-action@96383f45573cb7f253c731d3b3ab81c87ef81934 # v5.0.0
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}

# Build and push Docker image with Buildx (don't push on PR)
# https://github.com/docker/build-push-action
- name: Build and push Docker image
id: build-and-push
uses: docker/build-push-action@0565240e2d4ab88bba5387d719585280857ece09 # v5.0.0
with:
context: .
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max

# Sign the resulting Docker image digest except on PRs.
# This will only write to the public Rekor transparency log when the Docker
# repository is public to avoid leaking data. If you would like to publish
# transparency data even for private images, pass --force to cosign below.
# https://github.com/sigstore/cosign
- name: Sign the published Docker image
if: ${{ github.event_name != 'pull_request' }}
env:
# https://docs.github.com/en/actions/security-guides/security-hardening-for-github-actions#using-an-intermediate-environment-variable
TAGS: ${{ steps.meta.outputs.tags }}
DIGEST: ${{ steps.build-and-push.outputs.digest }}
# This step uses the identity token to provision an ephemeral certificate
# against the sigstore community Fulcio instance.
run: echo "${TAGS}" | xargs -I {} cosign sign --yes {}@${DIGEST}
45 changes: 12 additions & 33 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
![docker image](https://github.com/hampusnasstrom/nomad-example-image/actions/workflows/docker-publish.yml/badge.svg)
# nomad-example-image
An example repository for creating a nomad image with custom plugins.
![docker image](https://github.com/FAIRmat-NFDI/nomad-distribution-template/actions/workflows/docker-publish.yml/badge.svg)

> [!IMPORTANT]
> The templated repository will run a GitHub action on creation which might take a few momements.
> After the workflow finishes you should refresh the page and this message should disappear.
# NOMAD Oasis Distribution *Template*
This repository is a template for creating your own custom NOMAD Oasis distribution image.
Click [here](https://github.com/new?template_name=nomad-distribution-template&template_owner=FAIRmat-NFDI)
to use this template, or click the `Use this template` button in the upper right corner of
the main GitHub page for this template.

## Deploying the image

To deploy this NOMAD Oasis image you should follow the instructions on [nomad-lab.eu/prod/v1/docs/oasis/install.html](https://nomad-lab.eu/prod/v1/docs/oasis/install.html) but replace the Docker image in `docker-compose.yaml` with `ghcr.io/hampusnasstrom/nomad-example-image:main` for the services `worker`, `app`, `north`, and `logtransfer`.
To deploy this NOMAD Oasis image you should follow the instructions on [nomad-lab.eu/prod/v1/docs/oasis/install.html](https://nomad-lab.eu/prod/v1/docs/oasis/install.html) but replace the Docker image in `docker-compose.yaml` with `ghcr.io/FAIRmat-NFDI/nomad-distribution-template:main` for the services `worker`, `app`, `north`, and `logtransfer`.

Remember to also update the `nomad.yaml` config file to include the new plugins.

Expand Down Expand Up @@ -34,32 +42,3 @@ the container has to be run under the docker group. You need to replace the defa
id `991` in the `docker-compose.yaml`'s `hub` section with your systems docker group id.
Run `id` if you are a docker user, or `getent group | grep docker` to find our your
systems docker gid. The user id 1000 is used as the nomad user inside all containers.

## Adding a plugin

To add a new plugin to the docker image you should add it to the [plugins.txt](plugins.txt) file.

Here you can put either plugins distributed to PyPI, e.g.
```
nomad-material-processing
```
or plugins in a git repository with either the commit hash
```
git+https://github.com/FAIRmat-NFDI/nomad-measurements.git@71b7e8c9bb376ce9e8610aba9a20be0b5bce6775
```
or with a tag
```
git+https://github.com/FAIRmat-NFDI/[email protected]
```
To add a plugin in a subdirectory of a git repository you can use the `subdirectory` option, e.g.
```
git+https://github.com/FAIRmat-NFDI/AreaA-data_modeling_and_schemas.git@30fc90843428d1b36a1d222874803abae8b1cb42#subdirectory=PVD/PLD/jeremy_ikz/ikz_pld_plugin
```

Once the changes have been committed to the main branch, the new image will automatically be generated.

## Create your own image

To create your own custom NOMAD Oasis image you can fork this repository and publish your own docker image.
1. Fork repository
2. Enable the GitHub workflow action
Binary file modified nomad-oasis_files/nomad-oasis.zip
Binary file not shown.
8 changes: 4 additions & 4 deletions nomad-oasis_files/nomad-oasis/configs/nomad.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ elastic:

plugins:
options:
parsers/nomad_measurements/xrd:
python_package: nomad_measurements.xrd
schemas/nomad_material_processing:
python_package: nomad_material_processing
schemas/nomad_measurements:
python_package: nomad_measurements
schemas/ikz_pld:
python_package: ikz_pld
parsers/nomad_measurements/xrd:
python_package: nomad_measurements.xrd.parser
8 changes: 4 additions & 4 deletions nomad-oasis_files/nomad-oasis/docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ services:
# nomad worker (processing)
worker:
restart: unless-stopped
image: ghcr.io/hampusnasstrom/nomad-example-image:main
image: ghcr.io/FAIRmat-NFDI/nomad-distribution-template:main
container_name: nomad_oasis_worker
environment:
NOMAD_SERVICE: nomad_oasis_worker
Expand All @@ -93,7 +93,7 @@ services:
# nomad app (api + proxy)
app:
restart: unless-stopped
image: ghcr.io/hampusnasstrom/nomad-example-image:main
image: ghcr.io/FAIRmat-NFDI/nomad-distribution-template:main
container_name: nomad_oasis_app
environment:
NOMAD_SERVICE: nomad_oasis_app
Expand Down Expand Up @@ -132,7 +132,7 @@ services:
# nomad remote tools hub (JupyterHUB, e.g. for AI Toolkit)
north:
restart: unless-stopped
image: ghcr.io/hampusnasstrom/nomad-example-image:main
image: ghcr.io/FAIRmat-NFDI/nomad-distribution-template:main
container_name: nomad_oasis_north
environment:
NOMAD_SERVICE: nomad_oasis_north
Expand Down Expand Up @@ -167,7 +167,7 @@ services:
# to enable the logtransfer service run "docker compose --profile with_logtransfer up"
logtransfer:
restart: unless-stopped
image: ghcr.io/hampusnasstrom/nomad-example-image:main
image: ghcr.io/FAIRmat-NFDI/nomad-distribution-template:main
container_name: nomad_oasis_logtransfer
environment:
NOMAD_SERVICE: nomad_oasis_logtransfer
Expand Down
20 changes: 0 additions & 20 deletions nomad-oasis_files/scripts/update_nomad_oasis_dir.sh

This file was deleted.

8 changes: 4 additions & 4 deletions nomad.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ elastic:

plugins:
options:
parsers/nomad_measurements/xrd:
python_package: nomad_measurements.xrd
schemas/nomad_material_processing:
python_package: nomad_material_processing
schemas/nomad_measurements:
python_package: nomad_measurements
schemas/ikz_pld:
python_package: ikz_pld
parsers/nomad_measurements/xrd:
python_package: nomad_measurements.xrd.parser
5 changes: 2 additions & 3 deletions plugins.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
git+https://github.com/FAIRmat-NFDI/nomad-material-processing.git@55918771f1191ac31ae5e0d06a579b513886f3b2
git+https://github.com/FAIRmat-NFDI/AreaA-data_modeling_and_schemas.git@bb8422d5aefe114ae7e4e677262e99fecf26dcaf#subdirectory=PVD/PLD/jeremy_ikz/ikz_pld_plugin
git+https://github.com/FAIRmat-NFDI/nomad-measurements.git@50f199830517ae9753c5fccea1efe2983ed7781f
nomad-measurements
nomad-material-processing
Loading

0 comments on commit 4023151

Please sign in to comment.