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

Update Image to Template Version 2.0.0 #1

Merged
merged 55 commits into from
Oct 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
55 commits
Select commit Hold shift + click to select a range
c00fc04
Initial commit
hampusnasstrom Jan 25, 2024
300ff08
Added dockerfile, plugins, and nomad config
hampusnasstrom Jan 25, 2024
f4e1d22
Create docker-publish.yml
hampusnasstrom Jan 25, 2024
66859cc
Create zip-config.yml
hampusnasstrom Jan 25, 2024
b3f3a9d
Update zip-config.yml
hampusnasstrom Jan 25, 2024
966c68c
Update zip-config.yml
hampusnasstrom Jan 25, 2024
db39cca
Update zip-config.yml
hampusnasstrom Jan 25, 2024
e6811e6
Delete .github/workflows/zip-config.yml
hampusnasstrom Jan 25, 2024
986a71a
Updated nomad config
hampusnasstrom Jan 25, 2024
5a1c116
Changed dockerfile to use nomad user for pip install
hampusnasstrom Jan 25, 2024
bf48677
Update ikz_pld plugin version
hampusnasstrom Jan 25, 2024
ead8ebc
Added README
hampusnasstrom Jan 25, 2024
d499af2
Added docker action badge
hampusnasstrom Jan 26, 2024
3e2e065
Update plugins.txt
hampusnasstrom Feb 1, 2024
51aff83
Update plugins.txt
hampusnasstrom Feb 1, 2024
568d1c3
Update plugins.txt
hampusnasstrom Feb 2, 2024
074969d
Update plugins.txt
hampusnasstrom Feb 2, 2024
8c6e769
Use old nomad version
hampusnasstrom Feb 2, 2024
73b7241
Reverted Dockerfile to latest nomad-lab
hampusnasstrom Feb 2, 2024
39da6f8
Update ikz_pld plugin
hampusnasstrom Feb 2, 2024
aa371c5
Revert to last working plugins
hampusnasstrom Feb 5, 2024
f8b9f6f
Update plugins to latest versions
hampusnasstrom Feb 5, 2024
6d04d0d
Changed to use release-ikz image of nomad-lab
hampusnasstrom Feb 5, 2024
9a86f3a
Testing fix in nomad-lab
hampusnasstrom Feb 8, 2024
8517ea5
Reverted Dockerfile to nomad-lab develop tag
hampusnasstrom Feb 8, 2024
17214b6
Update README.md
hampusnasstrom Feb 20, 2024
c08e465
Update plugins.txt
hampusnasstrom Feb 21, 2024
0cf384e
Removed nomad-measurements
hampusnasstrom Feb 22, 2024
2da99b5
Added nomad-measurements plugin
hampusnasstrom Feb 22, 2024
85f72dc
Add nomad.yaml file
hampusnasstrom Feb 23, 2024
cf53403
Updated nomad-oasis.zip with script
hampusnasstrom Feb 23, 2024
9444ab8
Moved nomad-oasis example to nomad-oasis_files
hampusnasstrom Feb 26, 2024
43bab0c
Update docker-publish.yml
hampusnasstrom Feb 26, 2024
4023151
1 make into template (#2)
hampusnasstrom Mar 6, 2024
636eca5
Fix wrong path in initialize.yml workflow
hampusnasstrom Mar 6, 2024
f2f0bbb
Fixed sed argument in initialize.yml workflow
hampusnasstrom Mar 6, 2024
630e3a5
Fixed typo in initialize.yml workflow
hampusnasstrom Mar 6, 2024
81210d7
Move files to top level and update README (#4)
hampusnasstrom Mar 7, 2024
6f8b8bb
Update README.md
Pepe-Marquez Mar 7, 2024
0ce9363
Update template_README.md (#6)
hampusnasstrom Mar 7, 2024
66b3b17
Update oragnization and repo name to be in lower case (#8)
hampusnasstrom Mar 18, 2024
7b62b4e
Remove cosign from docker workflow (#13)
hampusnasstrom Apr 3, 2024
b5ce5ef
Update readme with curl instructions (#10)
hampusnasstrom Apr 3, 2024
01f9d99
Added information on package access rights (#15)
hampusnasstrom Apr 3, 2024
3fb9a4c
Added instructions for if initialize workflow fails to run (#18)
hampusnasstrom May 16, 2024
c6ac447
Update to the new distro mechanism (#23)
blueraft Sep 23, 2024
95e1921
Revert image name change (#26)
blueraft Sep 30, 2024
60766a0
Disallow prereleas versions (#27)
blueraft Sep 30, 2024
0bde3dd
Combine READMEs and add migration instructions (#29)
hampusnasstrom Oct 1, 2024
e75ce30
Install using apt-get (#32)
blueraft Oct 1, 2024
ee64b69
33 add jupyter dependencies (#34)
hampusnasstrom Oct 1, 2024
c3bb619
Updated to template version 2.0.0
fabianschoeppach Oct 1, 2024
579a6e9
nomad.yaml now in config and referenced by docker-compose.yaml
fabianschoeppach Oct 1, 2024
4219675
Update lockfile
invalid-email-address Oct 1, 2024
0a8e386
Update README.md
fabianschoeppach Oct 1, 2024
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
96 changes: 64 additions & 32 deletions .github/workflows/docker-publish.yml
Original file line number Diff line number Diff line change
@@ -1,62 +1,94 @@
name: Docker

# This workflow uses actions that are not certified by GitHub.
# They are provided by a third-party and are governed by
# separate terms of service, privacy policy, and support
# documentation.
# Build and publish a Docker image.
name: Build and publish docker images

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

env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}

permissions:
contents: write
packages: write
attestations: write
id-token: write

jobs:
build:
# Job 1: Update Lock File
update-lockfile:
name: Update Python Lock File
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- name: Checkout repository
uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
submodules: True

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Login
uses: docker/login-action@v3
ref: ${{ github.head_ref || github.ref_name }}
submodules: true

- name: Install uv
uses: astral-sh/setup-uv@v2

- uses: actions/setup-python@v5
with:
python-version: "3.11"

- name: Update lock file
run: uv lock --upgrade-package nomad-lab

# Commits any changes made to the lockfile
- name: Commit lock file changes
run: |
git config --global user.name github-actions
git config --global user.email [email protected]
git add uv.lock
if [[ `git status --porcelain` ]]; then
git commit -m "Update lockfile"
git push origin -o ci.skip # prevent triggering the pipeline again
fi

# Job 2: Build and Push Docker Image
docker-publish:
name: Build Docker Image
runs-on: ubuntu-latest
needs: update-lockfile

strategy:
fail-fast: false
matrix:
service: [app, jupyter]
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.head_ref || github.ref_name }}
submodules: true

- uses: docker/setup-buildx-action@v3

- uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Extract Docker metadata
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}

- name: Build and push
id: build-and-push
images: ${{ env.REGISTRY }}/${{ github.repository }}${{ matrix.service == 'jupyter' && '/jupyter' || '' }}

- name: Build and push Docker image
uses: docker/build-push-action@v5
with:
context: .
cache-from: type=gha
cache-to: type=gha,mode=max
target: ${{ matrix.service == 'jupyter' && 'jupyter' || 'final' }}
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
60 changes: 60 additions & 0 deletions .github/workflows/initialize.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
name: Template Repository Initialization

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

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 "/# NOMAD Oasis Distribution/,/button on the right./d" README.md
export image_name="${{ github.repository }}"
sed -i "s|fairmat-nfdi/nomad-distribution-template|${image_name,,}|g" README.md
sed -i "s|FAIRmat-NFDI/nomad-distribution-template|${{ github.repository }}|g" README.md
sed -i "s|FAIRmat-NFDI|${{ github.repository_owner }}|g" README.md
sed -i "s|nomad-distribution-template|${{ github.event.repository.name }}|g" README.md
sed -i "s|template https://github.com/${{ github.repository }}|template https://github.com/FAIRmat-NFDI/nomad-distribution-template|g" README.md
sed -i "s|${{ github.repository }}/releases/latest|FAIRmat-NFDI/nomad-distribution-template/releases/latest|g" README.md
sed -i "s|@ git+https://github.com/${{ github.repository_owner }}|@ git+https://github.com/FAIRmat-NFDI|g" README.md

# Replaces the template repository name in the docker config file with the new one
- name: Update docker-compose.yaml
run: |
export image_name="${{ github.repository }}"
sed -i "s|fairmat-nfdi/nomad-distribution-template|${image_name,,}|g" docker-compose.yaml

# Replaces the template repository name in the nomad config with the new one
- name: Update nomad.yaml
run: |
export image_name="${{ github.repository }}"
sed -i "s|fairmat-nfdi/nomad-distribution-template|${image_name,,}|g" configs/nomad.yaml

# 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
2 changes: 2 additions & 0 deletions .volumes/fs/north/users/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*
!.gitignore
2 changes: 2 additions & 0 deletions .volumes/fs/public/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*
!.gitignore
2 changes: 2 additions & 0 deletions .volumes/fs/staging/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*
!.gitignore
2 changes: 2 additions & 0 deletions .volumes/fs/tmp/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*
!.gitignore
2 changes: 2 additions & 0 deletions .volumes/mongo/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*
!.gitignore
156 changes: 149 additions & 7 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,8 +1,150 @@
FROM gitlab-registry.mpcdf.mpg.de/nomad-lab/nomad-fair:v1.3.1
USER root
RUN apt-get update
RUN apt-get -y install git
# syntax=docker/dockerfile:1

# Comments are provided throughout this file to help you get started.
# If you need more help, visit the Dockerfile reference guide at
# https://docs.docker.com/engine/reference/builder/

ARG PYTHON_VERSION=3.12

FROM python:${PYTHON_VERSION}-slim AS base

# Keeps Python from buffering stdout and stderr to avoid situations where
# the application crashes without emitting any logs due to buffering.
ENV PYTHONUNBUFFERED=1
ENV VIRTUAL_ENV=/opt/venv \
PATH="/opt/venv/bin:$PATH" \
UV_LINK_MODE=copy \
UV_PROJECT_ENVIRONMENT=/opt/venv

# Final stage to create the runnable image with minimal size
FROM base AS base_final

WORKDIR /app

RUN apt-get update \
&& apt-get install --yes --quiet --no-install-recommends \
libgomp1 \
libmagic1 \
curl \
zip \
unzip \
nodejs \
npm \
&& npm install -g configurable-http-proxy@^4.2.0 \
# clean cache and logs
&& rm -rf /var/lib/apt/lists/* /var/log/* /var/tmp/* ~/.npm

# Activate the virtualenv in the container
# See here for more information:
# https://pythonspeed.com/articles/multi-stage-docker-python/
ENV PATH="/opt/venv/bin:$PATH"

# Create a non-privileged user that the frenrug will run under.
# See https://docs.docker.com/develop/develop-images/dockerfile_best-practices/#user
ARG UID=1000
RUN adduser \
--disabled-password \
--gecos "" \
--home "/nonexistent" \
--shell "/sbin/nologin" \
--no-create-home \
--uid "${UID}" \
nomad

FROM base AS builder

# Prevents Python from writing pyc files.
ENV PYTHONDONTWRITEBYTECODE=1

ENV RUNTIME=docker

WORKDIR /app

RUN apt-get update \
&& apt-get install --yes --quiet --no-install-recommends \
libgomp1 \
libmagic1 \
file \
gcc \
build-essential \
curl \
zip \
unzip \
git \
&& rm -rf /var/lib/apt/lists/*

# Create a non-privileged user that the frenrug will run under.
# See https://docs.docker.com/develop/develop-images/dockerfile_best-practices/#user
ARG UID=1000
RUN adduser \
--disabled-password \
--gecos "" \
--home "/nonexistent" \
--shell "/sbin/nologin" \
--no-create-home \
--uid "${UID}" \
nomad


# Install UV
COPY --from=ghcr.io/astral-sh/uv:0.4 /uv /bin/uv

RUN --mount=type=cache,target=/root/.cache/uv \
--mount=type=bind,source=uv.lock,target=uv.lock \
--mount=type=bind,source=pyproject.toml,target=pyproject.toml \
uv sync --extra plugins --frozen --no-install-project


COPY scripts ./scripts

FROM base_final AS final

COPY --chown=nomad:1000 --from=builder /opt/venv /opt/venv
COPY --chown=nomad:1000 scripts/run.sh .
COPY --chown=nomad:1000 scripts/run-worker.sh .
COPY configs/nomad.yaml nomad.yaml

RUN mkdir -p /app/.volumes/fs \
&& chown -R nomad:1000 /app \
&& chown -R nomad:1000 /opt/venv \
&& mkdir nomad \
&& cp /opt/venv/lib/python3.12/site-packages/nomad/jupyterhub_config.py nomad/

USER nomad
COPY plugins.txt plugins.txt
RUN pip install -r plugins.txt
COPY nomad.yaml nomad.yaml

# The application ports
EXPOSE 8000
EXPOSE 9000

VOLUME /app/.volumes/fs


FROM jupyter/datascience-notebook:lab-3.6.2 AS jupyter

# Fix: https://github.com/hadolint/hadolint/wiki/DL4006
# Fix: https://github.com/koalaman/shellcheck/wiki/SC3014
SHELL ["/bin/bash", "-o", "pipefail", "-c"]

USER root

RUN apt-get update \
&& apt-get install --yes --quiet --no-install-recommends \
libmagic1 \
# clean cache and logs
&& rm -rf /var/lib/apt/lists/* /var/log/* /var/tmp/* ~/.npm

# Switch back to jovyan to avoid accidental container runs as root
USER ${NB_UID}
WORKDIR "${HOME}"

COPY --from=ghcr.io/astral-sh/uv:0.4 /uv /bin/uv

RUN --mount=type=cache,target=/root/.cache/uv \
--mount=type=bind,source=uv.lock,target=uv.lock \
--mount=type=bind,source=pyproject.toml,target=pyproject.toml \
uv export --extra plugins --extra jupyter | uv pip install -r /dev/stdin --system


# Get rid ot the following message when you open a terminal in jupyterlab:
# groups: cannot find name for group ID 11320
RUN touch ${HOME}/.hushlogin
Loading