From bfa4a8fb357085f1f00c04469cbab54432a61036 Mon Sep 17 00:00:00 2001 From: NotLebedev Date: Sun, 14 Dec 2025 12:32:49 +0300 Subject: [PATCH 1/3] refactor(build): Remove nix flake dependency on flake-utils --- flake.lock | 39 +----------------- flake.nix | 116 +++++++++++++++++++++++++---------------------------- 2 files changed, 55 insertions(+), 100 deletions(-) diff --git a/flake.lock b/flake.lock index 14e6854..58344d8 100644 --- a/flake.lock +++ b/flake.lock @@ -1,25 +1,5 @@ { "nodes": { - "flake-utils": { - "inputs": { - "systems": [ - "systems" - ] - }, - "locked": { - "lastModified": 1731533236, - "narHash": "sha256-l0KFg5HjrsfsO/JpG+r7fRrqm12kzFHyUHqHCVpMMbI=", - "owner": "numtide", - "repo": "flake-utils", - "rev": "11707dc2f618dd54ca8739b309ec4fc024de578b", - "type": "github" - }, - "original": { - "owner": "numtide", - "repo": "flake-utils", - "type": "github" - } - }, "nixpkgs": { "locked": { "lastModified": 1765425892, @@ -38,24 +18,7 @@ }, "root": { "inputs": { - "flake-utils": "flake-utils", - "nixpkgs": "nixpkgs", - "systems": "systems" - } - }, - "systems": { - "locked": { - "lastModified": 1680978846, - "narHash": "sha256-Gtqg8b/v49BFDpDetjclCYXm8mAnTrUzR0JnE2nv5aw=", - "owner": "nix-systems", - "repo": "x86_64-linux", - "rev": "2ecfcac5e15790ba6ce360ceccddb15ad16d08a8", - "type": "github" - }, - "original": { - "owner": "nix-systems", - "repo": "x86_64-linux", - "type": "github" + "nixpkgs": "nixpkgs" } } }, diff --git a/flake.nix b/flake.nix index 4ba0f5f..681b56e 100644 --- a/flake.nix +++ b/flake.nix @@ -1,86 +1,78 @@ { inputs = { nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; - systems.url = "github:nix-systems/x86_64-linux"; - flake-utils = { - url = "github:numtide/flake-utils"; - inputs.systems.follows = "systems"; - }; }; outputs = { self, - flake-utils, nixpkgs, ... }: - flake-utils.lib.eachDefaultSystem ( - system: - let - pkgs = import nixpkgs { inherit system; }; - nativeBuildInputs = with pkgs; [ - nodejs_25 - nodePackages.typescript - nodePackages.typescript-language-server + let + system = "x86_64-linux"; + pkgs = import nixpkgs { inherit system; }; + nativeBuildInputs = with pkgs; [ + nodejs_25 + nodePackages.typescript + nodePackages.typescript-language-server - cocogitto - ]; - npmDepsHash = "sha256-XAzDSXub5xLzoUYXosH2Gqy9De0bzOgfoyOB4jFUKJU="; - in - { - devShells.default = pkgs.mkShell { - inherit nativeBuildInputs; - }; + cocogitto + ]; + npmDepsHash = "sha256-XAzDSXub5xLzoUYXosH2Gqy9De0bzOgfoyOB4jFUKJU="; + in + { + devShells.${system}.default = pkgs.mkShell { + inherit nativeBuildInputs; + }; - packages.default = pkgs.buildNpmPackage { - name = "blog"; + packages.${system}.default = pkgs.buildNpmPackage { + name = "blog"; - src = self; + src = self; - buildPhase = '' - npm run build - ''; + buildPhase = '' + npm run build + ''; - installPhase = '' - mkdir $out - cp -r dist/* $out - cp netlify.toml $out - ''; + installPhase = '' + mkdir $out + cp -r dist/* $out + cp netlify.toml $out + ''; - inherit nativeBuildInputs npmDepsHash; - }; + inherit nativeBuildInputs npmDepsHash; + }; - checks = - let - common = { - src = self; - buildPhase = ""; - doCheck = true; - dontBuild = true; - installPhase = "mkdir $out"; + checks.${system} = + let + common = { + src = self; + buildPhase = ""; + doCheck = true; + dontBuild = true; + installPhase = "mkdir $out"; - inherit nativeBuildInputs npmDepsHash; - }; - mkCheck = args: pkgs.buildNpmPackage (args // common); - in - { - eslint = mkCheck { - name = "eslint-check"; + inherit nativeBuildInputs npmDepsHash; + }; + mkCheck = args: pkgs.buildNpmPackage (args // common); + in + { + eslint = mkCheck { + name = "eslint-check"; - checkPhase = '' - npx eslint src - ''; - }; - tsc = mkCheck { - name = "eslint-check"; + checkPhase = '' + npx eslint src + ''; + }; + tsc = mkCheck { + name = "eslint-check"; - checkPhase = '' - tsc - ''; - }; + checkPhase = '' + tsc + ''; }; - } - ); + }; + }; } From 52841e7d736852aca0fb0a4daedfb26ea643895d Mon Sep 17 00:00:00 2001 From: NotLebedev Date: Mon, 15 Dec 2025 09:42:05 +0300 Subject: [PATCH 2/3] feat(tools): Deploy as docker image --- deploy/Dockerfile | 11 +++++++++++ deploy/nginx.conf | 25 +++++++++++++++++++++++++ 2 files changed, 36 insertions(+) create mode 100644 deploy/Dockerfile create mode 100644 deploy/nginx.conf diff --git a/deploy/Dockerfile b/deploy/Dockerfile new file mode 100644 index 0000000..5d3b3e4 --- /dev/null +++ b/deploy/Dockerfile @@ -0,0 +1,11 @@ +FROM nginx:stable-alpine-slim + +RUN sed -i '1idaemon off;' /etc/nginx/nginx.conf +COPY deploy/nginx.conf /etc/nginx/conf.d/default.conf + +# Copy your built application files into the NGINX serving directory +ADD dist/ /app + +# The base image handles the standard SPA routing config +EXPOSE 80 +CMD ["nginx"] diff --git a/deploy/nginx.conf b/deploy/nginx.conf new file mode 100644 index 0000000..c3c2bf5 --- /dev/null +++ b/deploy/nginx.conf @@ -0,0 +1,25 @@ +server { + listen 80 default_server; + + gzip on; + gzip_min_length 1000; + gzip_types text/plain text/xml application/javascript text/css; + + root /app; + + # normal routes + # serve given url and default to index.html if not found + # e.g. /, /user and /foo/bar will return index.html + location / { + add_header Cache-Control "no-store"; + try_files $uri $uri/index.html /index.html; + } + + # files + # for all routes matching a dot, check for files and return 404 if not found + # e.g. /file.js returns a 404 if not found + location ~ \.(?!html) { + add_header Cache-Control "public, max-age=2678400"; + try_files $uri =404; + } +} From e7626f7b1785b7409a1e8724d96cdab2c541faf2 Mon Sep 17 00:00:00 2001 From: NotLebedev Date: Mon, 15 Dec 2025 16:03:48 +0300 Subject: [PATCH 3/3] feat(ci): Add build+docker workflow --- .github/workflows/build.yml | 33 +++++++++++++++++++++++++++++++++ .github/workflows/deploy.yml | 33 --------------------------------- flake.nix | 1 - 3 files changed, 33 insertions(+), 34 deletions(-) delete mode 100644 .github/workflows/deploy.yml diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index d05bffa..5cb4c2e 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -36,6 +36,38 @@ jobs: git --no-pager log ${{ github.event.pull_request.base.sha }}..${{ github.event.pull_request.head.sha }} nix develop . --command cog check ${{ github.event.pull_request.base.sha }}..${{ github.event.pull_request.head.sha }} + build-docker: + runs-on: ubuntu-latest + permissions: + contents: read + deployments: write + statuses: write + steps: + - uses: actions/checkout@v5 + - uses: DeterminateSystems/determinate-nix-action@v3 + - name: Build site + run: | + nix build --print-build-logs + mkdir dist + cp -r --no-preserve=mode,ownership,timestamps result/* dist/ + + - uses: docker/metadata-action@v5 + id: meta + with: + images: ghcr.io/${{ github.repository }} + - uses: docker/login-action@v3 + if: github.event_name != 'pull_request' + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + - uses: docker/build-push-action@v6 + with: + context: . + file: deploy/Dockerfile + push: ${{ github.event_name != 'pull_request' }} + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + success: if: always() runs-on: ubuntu-latest @@ -44,6 +76,7 @@ jobs: - eslint - cog - tsc + - build-docker steps: - name: Check other jovs diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml deleted file mode 100644 index 5c85578..0000000 --- a/.github/workflows/deploy.yml +++ /dev/null @@ -1,33 +0,0 @@ -name: Deploy to netlify -on: - workflow_dispatch: -jobs: - deploy: - runs-on: ubuntu-latest - permissions: - contents: read - deployments: write - statuses: write - steps: - - uses: actions/checkout@v4 - - name: Install Nix - uses: cachix/install-nix-action@v27 - - name: Build - run: | - nix build --print-build-logs - mkdir site - cp -r result/* site - - name: Deploy to Netlify - uses: nwtgck/actions-netlify@v3.0 - with: - publish-dir: './site' - production-branch: master - github-token: ${{ secrets.GITHUB_TOKEN }} - deploy-message: "GitHub Actions deployed ${{ github.sha }}" - enable-pull-request-comment: false - enable-commit-comment: false - overwrites-pull-request-comment: false - env: - NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }} - NETLIFY_SITE_ID: ${{ secrets.NETLIFY_SITE_ID }} - timeout-minutes: 5 diff --git a/flake.nix b/flake.nix index 681b56e..e7b5997 100644 --- a/flake.nix +++ b/flake.nix @@ -38,7 +38,6 @@ installPhase = '' mkdir $out cp -r dist/* $out - cp netlify.toml $out ''; inherit nativeBuildInputs npmDepsHash;