diff --git a/.github/workflows/docker-publish.yml b/.github/workflows/docker-publish.yml index e60154e..a22ccf3 100644 --- a/.github/workflows/docker-publish.yml +++ b/.github/workflows/docker-publish.yml @@ -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 @@ -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: diff --git a/.github/workflows/initialize.yml b/.github/workflows/initialize.yml new file mode 100644 index 0000000..ac1506e --- /dev/null +++ b/.github/workflows/initialize.yml @@ -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 / + 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 github-actions@github.com + 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} \ No newline at end of file diff --git a/README.md b/README.md index bf180a1..3647ce1 100644 --- a/README.md +++ b/README.md @@ -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. @@ -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/nomad-measurements.git@v0.0.4 -``` -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 diff --git a/nomad-oasis_files/nomad-oasis.zip b/nomad-oasis_files/nomad-oasis.zip index 606a3de..1d6684e 100644 Binary files a/nomad-oasis_files/nomad-oasis.zip and b/nomad-oasis_files/nomad-oasis.zip differ diff --git a/nomad-oasis_files/nomad-oasis/configs/nomad.yaml b/nomad-oasis_files/nomad-oasis/configs/nomad.yaml index dc9f26c..6b03954 100644 --- a/nomad-oasis_files/nomad-oasis/configs/nomad.yaml +++ b/nomad-oasis_files/nomad-oasis/configs/nomad.yaml @@ -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 \ No newline at end of file + parsers/nomad_measurements/xrd: + python_package: nomad_measurements.xrd.parser \ No newline at end of file diff --git a/nomad-oasis_files/nomad-oasis/docker-compose.yaml b/nomad-oasis_files/nomad-oasis/docker-compose.yaml index 7768205..13f6179 100644 --- a/nomad-oasis_files/nomad-oasis/docker-compose.yaml +++ b/nomad-oasis_files/nomad-oasis/docker-compose.yaml @@ -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 @@ -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 @@ -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 @@ -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 diff --git a/nomad-oasis_files/scripts/update_nomad_oasis_dir.sh b/nomad-oasis_files/scripts/update_nomad_oasis_dir.sh deleted file mode 100755 index 11e286a..0000000 --- a/nomad-oasis_files/scripts/update_nomad_oasis_dir.sh +++ /dev/null @@ -1,20 +0,0 @@ -#!/bin/bash - -set -e - -working_dir=$(pwd) -project_dir=$(dirname $(dirname $(dirname $(realpath $0)))) - -cd $project_dir - -# Copy nomad.yaml to the configs directory -cp -rf nomad.yaml nomad-oasis_files/nomad-oasis/configs/nomad.yaml - -# Replace the default docker image path with the actual docker image path -if [[ -n $1 ]]; then - sed -i "s|hampusnasstrom/nomad-example-image|$1|g" nomad-oasis_files/nomad-oasis/docker-compose.yaml - sed -i "s|hampusnasstrom/nomad-example-image|$1|g" README.md -fi - -# Compress the nomad-oasis directory -zip -r nomad-oasis_files/nomad-oasis.zip nomad-oasis_files/nomad-oasis \ No newline at end of file diff --git a/nomad.yaml b/nomad.yaml index dc9f26c..6b03954 100644 --- a/nomad.yaml +++ b/nomad.yaml @@ -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 \ No newline at end of file + parsers/nomad_measurements/xrd: + python_package: nomad_measurements.xrd.parser \ No newline at end of file diff --git a/plugins.txt b/plugins.txt index bc92784..041a1f0 100644 --- a/plugins.txt +++ b/plugins.txt @@ -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 diff --git a/template_README.md b/template_README.md new file mode 100644 index 0000000..93282b5 --- /dev/null +++ b/template_README.md @@ -0,0 +1,86 @@ +![docker image](https://github.com/GITHUB_REPOSITORY/actions/workflows/docker-publish.yml/badge.svg) + +# GITHUB_REPOSITORY_OWNER's NOMAD Oasis Distribution + +This is the NOMAD Oasis distribution of GITHUB_REPOSITORY_OWNER. +Below are instructions for how to [deploy this image](#deploying-the-image) and how to +customize it through [adding plugins](#adding-a-plugin). + +> [!IMPORTANT] +> Depending on the settings of the owner of this repository, the distributed image might +> be private and require authentication to pull. +> If you are the owner you should make sure that your organization settings allow public +> packages and after that set this package public. +> You can read more about this in the GitHub docs [here](https://docs.github.com/en/packages/learn-github-packages/configuring-a-packages-access-control-and-visibility). + +## 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/GITHUB_REPOSITORY:main` +for the services `worker`, `app`, `north`, and `logtransfer`. + +Remember to also update the `nomad.yaml` config file to include the new plugins. + +### Quick-start + +- Find a linux computer. +- Make sure you have [docker](https://docs.docker.com/engine/install/) installed. +Docker nowadays comes with `docker compose` build in. Prior, you needed to +install the stand alone [docker-compose](https://docs.docker.com/compose/install/). +- Download the modified configuration files [nomad-oasis.zip](nomad-oasis_files/nomad-oasis.zip) from this repository. +- Run the following commands (skip `chown` on MacOS and Windows computers) + + +```sh +unzip nomad-oasis.zip +cd nomad-oasis +sudo chown -R 1000 .volumes +docker compose pull +docker compose up -d +curl localhost/nomad-oasis/alive +``` + +- Open [http://localhost/nomad-oasis](http://localhost/nomad-oasis) in your browser. + +To run NORTH (the NOMAD Remote Tools Hub), the `hub` container needs to run docker and +the container has to be run under the docker group. You need to replace the default group +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/nomad-measurements.git@v0.0.4 +``` +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 +``` + +If the plugin is new, you also need to add it under `plugins` in the [nomad.yaml](nomad.yaml) +config file that will be included in the image. +For example, if you have added a schema plugin `nomad_material_processing` you should add +the following: + +```yaml +plugins: + options: + schemas/nomad_material_processing: + python_package: nomad_material_processing +``` + +Once the changes have been committed to the main branch, the new image will automatically +be generated. \ No newline at end of file