From 3e7acb49e868f925ce6f90c04150f1d171c6642c Mon Sep 17 00:00:00 2001 From: DGNum Deploy Date: Tue, 17 Dec 2024 20:57:23 +0000 Subject: [PATCH] Deploy site --- .envrc | 1 - .forgejo/workflows/build-site.yaml | 38 ---------- .forgejo/workflows/build.yaml | 25 ------- .gitignore | 3 - {src/www/css => css}/bulma.css | 0 default.nix | 79 --------------------- {src/www/icons => icons}/contact.svg | 0 {src/www/icons => icons}/git.svg | 0 {src/www/icons => icons}/instagram.svg | 0 {src/www/icons => icons}/mastodon.svg | 0 {src/www/icons => icons}/status.svg | 0 {src/www/icons => icons}/website.svg | 0 {src/www/img => img}/dgnum.png | Bin {src/www/img => img}/dgnum.svg | 0 src/index.html => index.html | 47 +++++++++++-- lon.lock | 25 ------- lon.nix | 41 ----------- pkgs/moody-templates.nix | 37 ---------- shell.nix | 1 - src/build.py | 93 ------------------------- src/data.json | 41 ----------- 21 files changed, 41 insertions(+), 390 deletions(-) delete mode 100644 .envrc delete mode 100644 .forgejo/workflows/build-site.yaml delete mode 100644 .forgejo/workflows/build.yaml delete mode 100644 .gitignore rename {src/www/css => css}/bulma.css (100%) delete mode 100644 default.nix rename {src/www/icons => icons}/contact.svg (100%) rename {src/www/icons => icons}/git.svg (100%) rename {src/www/icons => icons}/instagram.svg (100%) rename {src/www/icons => icons}/mastodon.svg (100%) rename {src/www/icons => icons}/status.svg (100%) rename {src/www/icons => icons}/website.svg (100%) rename {src/www/img => img}/dgnum.png (100%) rename {src/www/img => img}/dgnum.svg (100%) rename src/index.html => index.html (63%) delete mode 100644 lon.lock delete mode 100644 lon.nix delete mode 100644 pkgs/moody-templates.nix delete mode 100644 shell.nix delete mode 100644 src/build.py delete mode 100644 src/data.json diff --git a/.envrc b/.envrc deleted file mode 100644 index 1d953f4..0000000 --- a/.envrc +++ /dev/null @@ -1 +0,0 @@ -use nix diff --git a/.forgejo/workflows/build-site.yaml b/.forgejo/workflows/build-site.yaml deleted file mode 100644 index 0387f9c..0000000 --- a/.forgejo/workflows/build-site.yaml +++ /dev/null @@ -1,38 +0,0 @@ -name: build site -on: - pull_request: - types: [opened, synchronize, edited, reopened] - branches: - - main - push: - branches: - - main - -jobs: - build_site: - runs-on: nix - steps: - - uses: actions/checkout@v3 - - name: Build the site - run: nix-build - - - name: Pushing site to pages branch - if: github.event_name == 'push' && github.ref == 'refs/heads/main' - run: | - git switch -C pages - find . -mindepth 1 -maxdepth 1 ! -name '.domains' ! -name '.git' ! -name 'result' -exec rm -rf {} + - ls -a - cp -r result/* . - rm result - git add . - - git config user.name "DGNum Deploy" - git config user.email "tech@dgnum.eu" - - git commit --message "Deploy site" - git push --set-upstream origin pages --force - - - uses: actions/upload-artifact@v3 - with: - name: site - path: ./ diff --git a/.forgejo/workflows/build.yaml b/.forgejo/workflows/build.yaml deleted file mode 100644 index 7d9c8ac..0000000 --- a/.forgejo/workflows/build.yaml +++ /dev/null @@ -1,25 +0,0 @@ -name: build configuration -on: - push: - branches: - - master - -jobs: - build: - runs-on: nix - steps: - - uses: actions/checkout@v3 - - - name: Build - run: nix-build - - - name: deploy - run: nix-shell -p awscli2 --run "aws s3 sync ./result/ s3://$BUCKET/ --delete --endpoint-url $URL" - env: - URL: "https://s3.dgnum.eu/" - BUCKET: pub.dgnum.eu - AWS_ACCESS_KEY_ID: ${{ secrets.KEY_ID }} - AWS_SECRET_ACCESS_KEY: ${{ secrets.SECRET_KEY }} - - - diff --git a/.gitignore b/.gitignore deleted file mode 100644 index 582de42..0000000 --- a/.gitignore +++ /dev/null @@ -1,3 +0,0 @@ -.direnv -build -result diff --git a/src/www/css/bulma.css b/css/bulma.css similarity index 100% rename from src/www/css/bulma.css rename to css/bulma.css diff --git a/default.nix b/default.nix deleted file mode 100644 index 72627fd..0000000 --- a/default.nix +++ /dev/null @@ -1,79 +0,0 @@ -{ - sources ? import ./lon.nix, - pkgs ? import sources.nixpkgs { }, -}: - -let - description = "La Délégation Générale Numérique est une association loi 1901 domiciliée à l'ENS dont les buts sont de promouvoir la chose numérique ainsi que son usage."; - - links = [ - { - text = "État des services"; - href = "https://status.dgnum.eu"; - cls = "link-status"; - icon = "status.svg"; - } - { - text = "Notre site"; - href = "https://dgnum.eu"; - cls = "link-classic"; - icon = "website.svg"; - } - { - text = "Forge Git"; - href = "https://git.dgnum.eu"; - cls = "link-git"; - icon = "git.svg"; - } - { - text = "Mastodon"; - href = "https://social.dgnum.eu/@dgnum"; - cls = "link-mastodon"; - icon = "mastodon.svg"; - } - { - text = "Instagram"; - href = "https://www.instagram.com/dgnum_eu/"; - cls = "link-instagram"; - icon = "instagram.svg"; - } - { - text = "Nous contacter"; - href = "mailto:contact@dgnum.eu"; - cls = "link-classic"; - icon = "contact.svg"; - } - ]; - - python3 = pkgs.python3.withPackages (ps: [ - ps.watchdog - (ps.callPackage ./pkgs/moody-templates.nix { }) - ]); -in - -pkgs.stdenv.mkDerivation { - name = "dgnum-landing"; - version = "1.0.1"; - src = ./src; - - passthru = { - devShell = pkgs.mkShell { - packages = [ - (pkgs.callPackage "${sources.lon}/nix/packages/lon.nix" { }) - python3 - ]; - }; - }; - - buildInputs = [ python3 ]; - - env.DATA_FILE = pkgs.writers.writeJSON "data.json" { inherit description links; }; - - configurePhase = '' - export BUILD_DIR=$out - ''; - - buildPhase = '' - python3 build.py - ''; -} diff --git a/src/www/icons/contact.svg b/icons/contact.svg similarity index 100% rename from src/www/icons/contact.svg rename to icons/contact.svg diff --git a/src/www/icons/git.svg b/icons/git.svg similarity index 100% rename from src/www/icons/git.svg rename to icons/git.svg diff --git a/src/www/icons/instagram.svg b/icons/instagram.svg similarity index 100% rename from src/www/icons/instagram.svg rename to icons/instagram.svg diff --git a/src/www/icons/mastodon.svg b/icons/mastodon.svg similarity index 100% rename from src/www/icons/mastodon.svg rename to icons/mastodon.svg diff --git a/src/www/icons/status.svg b/icons/status.svg similarity index 100% rename from src/www/icons/status.svg rename to icons/status.svg diff --git a/src/www/icons/website.svg b/icons/website.svg similarity index 100% rename from src/www/icons/website.svg rename to icons/website.svg diff --git a/src/www/img/dgnum.png b/img/dgnum.png similarity index 100% rename from src/www/img/dgnum.png rename to img/dgnum.png diff --git a/src/www/img/dgnum.svg b/img/dgnum.svg similarity index 100% rename from src/www/img/dgnum.svg rename to img/dgnum.svg diff --git a/src/index.html b/index.html similarity index 63% rename from src/index.html rename to index.html index ad77310..4d70510 100644 --- a/src/index.html +++ b/index.html @@ -138,17 +138,52 @@ Délégation Générale Numérique

Délégation Générale Numérique

-

{{ description }}

+

La Délégation Générale Numérique est une association loi 1901 domiciliée à l'ENS dont les buts sont de promouvoir la chose numérique ainsi que son usage.


- {% for link in links %} - + +
- +
- {{ link.text }} + État des services
- {% endfor %} + + +
+ +
+ Notre site +
+ + +
+ +
+ Forge Git +
+ + +
+ +
+ Mastodon +
+ + +
+ +
+ Instagram +
+ + +
+ +
+ Nous contacter +
+ diff --git a/lon.lock b/lon.lock deleted file mode 100644 index fe1ce05..0000000 --- a/lon.lock +++ /dev/null @@ -1,25 +0,0 @@ -{ - "version": "1", - "sources": { - "lon": { - "type": "GitHub", - "fetchType": "tarball", - "owner": "nikstur", - "repo": "lon", - "branch": "main", - "revision": "a8b4406e5151af87b989564d4aa98ecd6d4d3500", - "url": "https://github.com/nikstur/lon/archive/a8b4406e5151af87b989564d4aa98ecd6d4d3500.tar.gz", - "hash": "sha256-VGvK0ahBl440NMs03WqmP7T4a1DP13yfX47YI84rlGU=" - }, - "nixpkgs": { - "type": "GitHub", - "fetchType": "tarball", - "owner": "nixos", - "repo": "nixpkgs", - "branch": "master", - "revision": "b53cf65876d5b5dd6fc8d0df3f3f3f185fee164a", - "url": "https://github.com/nixos/nixpkgs/archive/b53cf65876d5b5dd6fc8d0df3f3f3f185fee164a.tar.gz", - "hash": "sha256-IoiRey6txrqjtmzMcw2Uwwj3t6fPo2pkaoKdkfRezuc=" - } - } -} diff --git a/lon.nix b/lon.nix deleted file mode 100644 index 5f320ea..0000000 --- a/lon.nix +++ /dev/null @@ -1,41 +0,0 @@ -# Generated by lon. Do not modify! -let - - lock = builtins.fromJSON (builtins.readFile ./lon.lock); - - # Override with a path defined in an environment variable. If no variable is - # set, the original path is used. - overrideFromEnv = - name: path: - let - replacement = builtins.getEnv "LON_OVERRIDE_${name}"; - in - if replacement == "" then - path - else - # this turns the string into an actual Nix path (for both absolute and - # relative paths) - if builtins.substring 0 1 replacement == "/" then - /. + replacement - else - /. + builtins.getEnv "PWD" + "/${replacement}"; - - fetchSource = - args@{ fetchType, ... }: - if fetchType == "git" then - builtins.fetchGit { - url = args.url; - ref = args.branch; - rev = args.revision; - narHash = args.hash; - } - else if fetchType == "tarball" then - builtins.fetchTarball { - url = args.url; - sha256 = args.hash; - } - else - builtins.throw "Unsupported source type ${fetchType}"; - -in -builtins.mapAttrs (name: args: overrideFromEnv name (fetchSource args)) lock.sources diff --git a/pkgs/moody-templates.nix b/pkgs/moody-templates.nix deleted file mode 100644 index 2b1f0e8..0000000 --- a/pkgs/moody-templates.nix +++ /dev/null @@ -1,37 +0,0 @@ -{ - lib, - buildPythonPackage, - fetchFromGitHub, - setuptools, - wheel, -}: - -buildPythonPackage rec { - pname = "moody-templates"; - version = "0.9.1-unstable"; - pyproject = true; - - src = fetchFromGitHub { - owner = "etianen"; - repo = "moody-templates"; - rev = "243dc91e4fa6f2225c0e327e96f3416bd165f80a"; - hash = "sha256-MY91vz2QB1WJzW+lFA9N4YHZaXPqv//OpgH6jwBT0m8="; - }; - - build-system = [ - setuptools - wheel - ]; - - pythonImportsCheck = [ - "moody" - ]; - - meta = { - description = "A fast, extensible templating engine for Python 3 with Django-like syntax"; - homepage = "https://github.com/etianen/moody-templates"; - changelog = "https://github.com/etianen/moody-templates/blob/${src.rev}/CHANGELOG.markdown"; - license = lib.licenses.bsd3; - maintainers = with lib.maintainers; [ ]; - }; -} diff --git a/shell.nix b/shell.nix deleted file mode 100644 index d6d21cf..0000000 --- a/shell.nix +++ /dev/null @@ -1 +0,0 @@ -(import ./. { }).devShell diff --git a/src/build.py b/src/build.py deleted file mode 100644 index 7de6a93..0000000 --- a/src/build.py +++ /dev/null @@ -1,93 +0,0 @@ -import json -import os -from dataclasses import asdict, dataclass, fields -from os import environ as env -from pathlib import Path -from shutil import copytree - -from moody import render -from watchdog.events import FileSystemEventHandler -from watchdog.observers import Observer - - -def dataclass_from_dict(klass, dikt): - try: - fieldtypes = {f.name: f.type for f in fields(klass)} - return klass(**{f: dataclass_from_dict(fieldtypes[f], dikt[f]) for f in dikt}) - except: - if isinstance(dikt, (tuple, list)): - return [dataclass_from_dict(klass.__args__[0], f) for f in dikt] - return dikt # Not a dataclass field - - -@dataclass -class Link: - href: str - text: str - icon: str - cls: str - - -@dataclass -class Data: - links: list[Link] - description: str | None = None - - -def write_files(rendered: str, src_dir: Path, out_dir: Path): - # Copy the static files - copytree(src_dir / "www", out_dir, dirs_exist_ok=True) - - # Write out the index file - with open(out_dir / "index.html", "w") as fp: - fp.write(rendered) - - -def build_project(src_dir: Path, build_dir: Path): - if not os.path.exists(build_dir): - os.mkdir(build_dir) - - data_path = env.get("DATA_FILE", src_dir / "data.json") - - # Load the data - with open(data_path) as fp: - data: Data = dataclass_from_dict(Data, json.load(fp)) # pyright: ignore - - # Render the template with the correct data - with open(src_dir / "index.html") as fp: - rendered = render(fp.read(), links=data.links, description=data.description) - - write_files(rendered, src_dir, build_dir) - - -class CatchAllHandler(FileSystemEventHandler): - def __init__(self, src_dir: Path, build_dir: Path): - self.src_dir = src_dir - self.build_dir = build_dir - self.count = 0 - - def on_modified(self, event): - print(f"Files changed, rebuilding project [{self.count}]") - build_project(self.src_dir, self.build_dir) - self.count += 1 - - -if __name__ == "__main__": - src_dir = Path(__file__).parent.resolve() - build_dir = Path(env.get("BUILD_DIR", src_dir.parent.resolve() / "build")) - watch_files = bool(env.get("WATCH_SRC")) - - build_project(src_dir, build_dir) - - if watch_files: - # Create the structure to watch for changes - observer = Observer() - observer.schedule(CatchAllHandler(src_dir, build_dir), src_dir, recursive=True) - observer.start() - - try: - while observer.is_alive(): - observer.join() - finally: - observer.stop() - observer.join() diff --git a/src/data.json b/src/data.json deleted file mode 100644 index 01d624b..0000000 --- a/src/data.json +++ /dev/null @@ -1,41 +0,0 @@ -{ - "links": [ - { - "text": "État des services", - "href": "https://status.dgnum.eu", - "cls": "link-status", - "icon": "status.svg" - }, - { - "text": "Notre site", - "href": "https://dgnum.eu", - "cls": "link-classic", - "icon": "website.svg" - }, - { - "text": "Forge Git", - "href": "https://git.dgnum.eu", - "cls": "link-git", - "icon": "git.svg" - }, - { - "text": "Mastodon", - "href": "https://social.dgnum.eu/@dgnum", - "cls": "link-mastodon", - "icon": "mastodon.svg" - }, - { - "text": "Instagram", - "href": "https://www.instagram.com/dgnum_eu/", - "cls": "link-instagram", - "icon": "instagram.svg" - }, - { - "text": "Nous contacter", - "href": "mailto:contact@dgnum.eu", - "cls": "link-classic", - "icon": "contact.svg" - } - ], - "description": "La Délégation Générale Numérique est une association loi 1901 domiciliée à l'ENS dont les buts sont de promouvoir la chose numérique ainsi que son usage." -}