Skip to content

Commit

Permalink
Merge pull request #47 from FREVA-CLINT/fix-merge
Browse files Browse the repository at this point in the history
Fix merge
  • Loading branch information
antarcticrainforest authored Mar 25, 2024
2 parents 15e67b8 + 9f7d21b commit 1ef65ba
Show file tree
Hide file tree
Showing 50 changed files with 308 additions and 220 deletions.
6 changes: 3 additions & 3 deletions .ci/install_conda.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
"""Deploy the evaluation_system / core."""

import argparse
import logging
from pathlib import Path
import shlex
from subprocess import CalledProcessError, PIPE, run
import urllib.request
from pathlib import Path
from subprocess import PIPE, CalledProcessError, run
from tempfile import TemporaryDirectory


MINICONDA_URL = "https://repo.anaconda.com/miniconda/Miniconda3-latest"

logging.basicConfig(format="%(name)s - %(levelname)s - %(message)s", level=logging.INFO)
Expand Down
41 changes: 36 additions & 5 deletions .github/workflows/build_job.yml
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
name: Build and publish the container image
run-name: ${{ github.actor }} is building the container
run-name: ${{ github.actor }} is createing a new release

"on":
workflow_dispatch:
push:
tags:
- '*'
branches:
- 'main'
- 'v*.*.*'

jobs:
lint:
uses: ./.github/workflows/test_job.yml
build-and-push-image:
runs-on: ubuntu-latest
needs: lint
permissions:
contents: read
packages: write
Expand All @@ -26,7 +27,7 @@ jobs:
name: Get tag
id: repository
run: |
echo "tag=v$(cat package.json|jq -r .version)" >> $GITHUB_OUTPUT
echo "tag=$(cat package.json|jq -r .version)" >> $GITHUB_OUTPUT
echo "repo=$(echo ${{ github.repository }}|tr 'A-Z' 'a-z')" >> $GITHUB_OUTPUT
-
Expand All @@ -51,7 +52,37 @@ jobs:
with:
context: .
platforms: linux/amd64
build-args: VERSION=${{steps.repository.outputs.tag}}
push: true
tags: |
ghcr.io/${{ steps.repository.outputs.repo }}:${{ steps.repository.outputs.tag }}
ghcr.io/${{ steps.repository.outputs.repo }}:latest
bump-web-version:
runs-on: ubuntu-latest
needs: [build-and-push-image, lint]
permissions:
contents: read
packages: write
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Set up Python 3
uses: actions/setup-python@v4
with:
python-version: "3.X"

- name: Get tag
id: repository
run: |
echo "repo=$(echo ${{ github.repository }}|tr 'A-Z' 'a-z')" >> $GITHUB_OUTPUT
echo "tag=$(cat package.json|jq -r .version)" >> $GITHUB_OUTPUT
- name: Do the release job
run: make release
env:
GITHUB_TOKEN: ${{secrets.ACCESS_TOKEN}}
REPO_VERSION: ${{ steps.repository.outputs.tag }}
6 changes: 1 addition & 5 deletions .github/workflows/test_job.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
name: Tests
run-name: ${{ github.actor }} is doing some smoke tests

on:
push:
pull_request:
workflow_dispatch:

on: [push, pull_request, workflow_call]
jobs:
Smoke-tests:
runs-on: ubuntu-latest
Expand Down
23 changes: 23 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Changelog

All notable changes to this project will be documented in this file.
## [v2403.0.0]

### Added
- Change lock file, to keep track of changes.


# Template:
## [Unreleased]

### Added
- New feature X.
- New feature Y.

### Changed
- Improved performance in component A.
- Updated dependency B to version 2.0.0.

### Fixed
- Fixed issue causing application crash on startup.
- Fixed bug preventing users from logging in.
30 changes: 17 additions & 13 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,26 +1,30 @@
ARG CONDA_ENV_DIR=/opt/condaenv
ARG FREVA_WEB_DIR=/opt/freva_web
ARG VERSION

FROM condaforge/mambaforge
LABEL maintainer="DRKZ-CLINT"
LABEL repository="https://github.com/FREVA-CLINT/freva-web"

LABEL org.opencontainers.image.authors="DRKZ-CLINT"
LABEL org.opencontainers.image.source="https://github.com/FREVA-CLINT/freva-web"
LABEL org.opencontainers.image.version="$VERSION"
ARG CONDA_ENV_DIR
ARG FREVA_WEB_DIR

RUN set -e && \
groupadd -r -g 1000 freva && \
adduser --uid 1000 --gid 1000 --gecos "Freva user" \
--shell /bin/bash --disabled-password freva --home ${FREVA_WEB_DIR} &&\
mkdir -p ${CONDA_ENV_DIR} && chown -R freva:freva $CONDA_ENV_DIR
WORKDIR ${FREVA_WEB_DIR}
COPY . .

ENV PATH=$CONDA_ENV_DIR/bin:$PATH\
DJANGO_SUPERUSER_EMAIL=freva@dkrz.de

RUN set -e \
&& mamba env create -p ${CONDA_ENV_DIR} -f conda-env.yml \
&& npm install && npm run build-production \
&& mamba clean -afy \
&& rm -rf node_modules \
&& echo "export PATH=${PATH}" >> /root/.bashrc

RUN set -e && \
mamba env create -y -p ${CONDA_ENV_DIR} -f conda-env.yml &&\
mamba clean -afy &&\
npm install && npm run build-production &&\
rm -rf node_modules &&\
echo "export PATH=${PATH}" >> ${FREVA_WEB_DIR}/.bashrc &&\
chown -R freva:freva ${FREVA_WEB_DIR}
USER freva
EXPOSE 8000

CMD ./init_django.sh
8 changes: 7 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,16 @@ run: runfrontend runserver
lint: setup-node
npm run lint-format
npm run lint
black -t py310 --check .
isort -c --profile black -t py312 .

tests: setup-node
npm run build-production
npm run build
rm -rf node_modules
pytest -vv $(PWD) tests/

release:
pip install git-python requests packaging tomli
curl -H 'Cache-Control: no-cache' -Ls -o bump.py https://raw.githubusercontent.com/FREVA-CLINT/freva-deployment/versions/release.py
python3 bump.py tag django_evaluation -b version
rm bump.py
20 changes: 7 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -171,18 +171,12 @@ it to the registry. To do so please follow the following steps.
```json
"version": "2023.07.19"
```
- After you have push the version changes to the main branch you can create
a new tag with the same version:
- After you have pushed the version changes to the main branch you can trigger
the release procedure:
```console
git tag -a vVERSION -m "comment"
make release
```
for example:
```console
git tag -a v2023.07.19 -m "Some prettifications."
```
- Push the tag to the remote repository:
```console
git push origin vVERSION
```

These steps trigger the creation of a new container image.
This will check the current version of the `main` branch and trigger
a GitHub continuous integration pipeline to create the new release. The procedure
performs a couple of checks, if theses checks fail please make sure to address
the issues.
7 changes: 5 additions & 2 deletions base/LdapUser.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import os
from configparser import ConfigParser as Config
from configparser import ExtendedInterpolation

from evaluation_system.misc import config
from evaluation_system.model.db import UserDB
from evaluation_system.model.user import User

from base.exceptions import UserNotFoundError
from django_evaluation.ldaptools import get_ldap_object
from configparser import ConfigParser as Config, ExtendedInterpolation
from evaluation_system.misc import config


class LdapUser(User):
Expand Down
4 changes: 1 addition & 3 deletions base/admin.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
from django.contrib import admin
from django.contrib.auth.admin import UserAdmin
from django.contrib.auth.models import User

from django.contrib.auth.models import Permission
from django.contrib.auth.models import Permission, User

from .models import UIMessages

Expand Down
6 changes: 3 additions & 3 deletions base/models.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from django.db import models
from django.contrib.auth.models import User

from datetime import datetime

from django.contrib.auth.models import User
from django.db import models


def isGuest(self):
groups = self.groups.filter(name="Guest")
Expand Down
2 changes: 1 addition & 1 deletion base/serializers.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from rest_framework import serializers
from django.contrib.auth.models import User
from rest_framework import serializers

from django_evaluation.settings.local import HOME_DIRS_AVAILABLE

Expand Down
1 change: 1 addition & 0 deletions base/urls.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from django.urls import re_path as url

import base.views

urlpatterns = [
Expand Down
17 changes: 9 additions & 8 deletions base/views.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import logging

from base.models import UIMessages

from django.http import HttpResponseRedirect
from django.shortcuts import render
import django.contrib.auth as auth
from django.contrib.auth.decorators import login_required, user_passes_test
from django.views.decorators.debug import sensitive_variables, sensitive_post_parameters
from django_evaluation.monitor import _restart
from django.conf import settings
from django.contrib.auth.decorators import login_required, user_passes_test
from django.http import HttpResponseRedirect
from django.shortcuts import render
from django.urls import reverse
from evaluation_system.misc import config
from django.utils.http import url_has_allowed_host_and_scheme
from django.views.decorators.debug import sensitive_post_parameters, sensitive_variables
from evaluation_system.misc import config

from base.models import UIMessages
from django_evaluation.monitor import _restart


@sensitive_variables("passwd")
Expand Down Expand Up @@ -113,6 +113,7 @@ def contact(request):
"""
if request.method == "POST":
from templated_email import send_templated_mail

from django_evaluation.ldaptools import get_ldap_object

user_info = get_ldap_object()
Expand Down
5 changes: 3 additions & 2 deletions base/views_api.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
from rest_framework.views import APIView
from rest_framework.response import Response
from rest_framework.views import APIView

from base.LdapUser import LdapUser
from base.exceptions import UserNotFoundError
from base.LdapUser import LdapUser

from .serializers import UserSerializer


Expand Down
1 change: 1 addition & 0 deletions conda-env.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ dependencies:
- pip
- pip:
- black
- isort
- requests_mock
- django-auth-ldap
- django-datatable-view
Expand Down
14 changes: 8 additions & 6 deletions django_evaluation/ldaptools.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
from __future__ import annotations
from abc import ABCMeta, abstractmethod

import grp
import importlib
import pwd
import time
from abc import ABCMeta, abstractmethod
from typing import Iterator

from django_evaluation import settings
from django_evaluation.utils import background
import ldap
from django.core.cache import cache, caches
from django.core.exceptions import ImproperlyConfigured
import ldap
import grp
import pwd

from django_evaluation import settings
from django_evaluation.utils import background

"""
FIXME: 28.03.2022
Expand Down
7 changes: 4 additions & 3 deletions django_evaluation/monitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@
This is an example code for restarting after code changes from
http://code.google.com/p/modwsgi/wiki/ReloadingSourceCode#Restarting_Daemon_Processes
"""

import atexit
import os
import sys
import queue
import signal
import sys
import threading
import atexit
import queue

_interval = 1.0
_times = {}
Expand Down
5 changes: 3 additions & 2 deletions django_evaluation/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,16 @@
repo. If you need to override a setting locally, use local.py
"""

import os
import logging
import os
from pathlib import Path

import django.utils

# Normally you should not import ANYTHING from Django directly
# into your settings, but ImproperlyConfigured is an exception.
from django.core.exceptions import ImproperlyConfigured
from django.urls import reverse_lazy
import django.utils


def get_env_setting(setting):
Expand Down
Loading

0 comments on commit 1ef65ba

Please sign in to comment.