This commit is contained in:
Arnie 2024-10-21 11:19:42 +02:00
parent b183c239b3
commit 1d67745c69
6 changed files with 188 additions and 180 deletions

View File

@ -28,7 +28,7 @@ steps:
- name: deps - name: deps
path: /nix/store path: /nix/store
commands: commands:
- nix-build --argstr version ${DRONE_TAG} --argstr rev ${DRONE_COMMIT} --argstr repoUrl ${DRONE_REPO_LINK} - nix-build --argstr version ${DRONE_TAG} --argstr rev ${DRONE_COMMIT} .#image
- name: publish - name: publish
image: docker:dind image: docker:dind
@ -87,6 +87,6 @@ services:
--- ---
kind: signature kind: signature
hmac: 8db89c3a13466a543ec8edb72923c4985aae191b0b6de8c324bb24116a7684e9 hmac: df9a2fb07428f545bc41b36d4c8b53e0e7223333f614e2d5d890a1adbd7f324b
... ...

1
.gitignore vendored
View File

@ -12,6 +12,7 @@
# Frontend # Frontend
/app/frontend/node_modules /app/frontend/node_modules
/app/frontend/dist
/app/frontend/.pnp /app/frontend/.pnp
/app/frontend/.pnp.js /app/frontend/.pnp.js
/app/frontend/.dependency-graph /app/frontend/.dependency-graph

View File

@ -1,24 +0,0 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
lerna-debug.log*
node_modules
dist
dist-ssr
*.local
# Editor directories and files
.vscode/*
!.vscode/extensions.json
.idea
.DS_Store
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?

View File

@ -1,154 +0,0 @@
{ system ? builtins.currentSystem
, version ? "latest"
, rev ? ""
, commitTime ? "1970-01-01T00:00:00+00:00"
, repoUrl ? ""
}:
let
nixpkgs = builtins.fetchTarball {
url = "https://github.com/NixOS/nixpkgs/archive/4ecab3273592f27479a583fb6d975d4aba3486fe.tar.gz";
sha256 = "10wn0l08j9lgqcw8177nh2ljrnxdrpri7bp0g7nvrsn9rkawvlbf";
};
pkgs = import nixpkgs { inherit system; };
devshell = import
(pkgs.fetchFromGitHub {
owner = "numtide";
repo = "devshell";
rev = "5143ea68647c4cf5227e4ad2100db6671fc4c369";
sha256 = "sha256-9goJTd05yOyD/McaMqZ4BUB8JW+mZMnZQJZ7VQ6C/Lw=";
})
{ nixpkgs = pkgs; };
nodejs = pkgs.nodejs_20;
go = pkgs.go_1_20;
dream2nix = pkgs.dream2nix;
buildGoModule = pkgs.buildGoModule.override { inherit go; };
golangci-lint = pkgs.golangci-lint.override { inherit buildGoModule; };
src = pkgs.lib.cleanSource ./.;
uiSrc = pkgs.lib.cleanSource ./app/frontend;
package = pkgs.buildNpmPackage {
name = "ui";
buildInputs = [
nodejs
];
pname = "ui";
src = uiSrc;
buildPhase = ''
npm run check
npm run build
mkdir $out
cp -a dist $out
'';
npmInstallFlags = "--no-audit --no-progress --no-fund";
npmDepsHash = "sha256-p4rTpy0t8aajbubvtF1TA83/FFqvfKEOPBb5T0ZRfQY=";
npmPackFlags = [ "--ignore-scripts" ];
};
server = buildGoModule {
inherit src version;
pname = "cv";
postPatch = ''
rm -rf app/server/internal/files/data/public
mkdir -p app/server/internal/files/data/public
touch app/server/internal/files/data/public/.gitkeep
cp -Tr ${package}/dist/ app/server/internal/files/data/public/
chmod +w -R app/server/internal/files/data/public
sed -i 's#<script#<script nonce="{{ .CspNonce }}"#g' app/server/internal/files/data/public/index.html
'';
CGO_ENABLED = 0;
ldflags = "-s -w -X gopkg.c3c.cz/cv/app/server/internal/version.Tag=${version} -X gopkg.c3c.cz/cv/app/server/internal/version.Commit=${rev} -X gopkg.c3c.cz/cv/app/server/internal/version.commitTime=${commitTime} -X gopkg.c3c.cz/cv/app/server/internal/version.repoUrl=${repoUrl}";
subPackages = [ "app/server" ];
vendorSha256 = "sha256-44xcyVk5KcurQLkVJv1MeAj+Pfcu53664pvVgHdyv3E=";
overrideModAttrs = (_: {
impureEnvVars = pkgs.lib.fetchers.proxyImpureEnvVars ++ [ "GIT_PROXY_COMMAND" "SOCKS_SERVER" "GOPROXY" ];
});
};
in
{
image = pkgs.dockerTools.streamLayeredImage {
name = "cv";
tag = version;
config = {
Env = [ "SSL_CERT_FILE=${pkgs.cacert}/etc/ssl/certs/ca-bundle.crt" ];
Entrypoint = [ "${server}/bin/server" ];
};
};
shell = devshell.mkShell {
devshell = {
name = "c3c-cv";
packages = [
go
golangci-lint
pkgs.prefetch-npm-deps
nodejs
# keep pinned nixpkgs so they are not garbage collected
pkgs.path
];
};
commands = [
{
name = "lint";
help = "run golangci-lint and npm run check";
command = ''
cd ''$PRJ_ROOT
golangci-lint run --sort-results --out-format tab
npm --prefix app/frontend run check
'';
}
{
name = "fmt";
help = "Format and fix found issues";
command = ''
cd ''$PRJ_ROOT
golangci-lint run --sort-results --out-format tab --fix
npm --prefix app/frontend run fix
'';
}
{
name = "update-npm-deps-hash";
help = "Calculates and updates the npmDepsHash in default.nix";
command = ''
echo "Calculating npm deps"
# STDERR is poluted by the installed nodules, silencing
HASH=''$(prefetch-npm-deps ''$PRJ_ROOT/app/frontend/package-lock.json 2> /dev/null)
[[ ''$HASH = sha256* ]] && echo "Hash is ''$HASH"
[[ ''$HASH != sha256* ]] && echo "Failed" && exit 137
# Replace the first occurence of npmDepsHash with the new calculated hash in this file
sed -i "0,/npmDepsHash =/{s@npmDepsHash = .*@npmDepsHash = \"''$HASH\";@}" ''$PRJ_ROOT/default.nix
'';
}
{
name = "pre-commit";
help = "Format and fix found issues";
command = ''
cd ''$PRJ_ROOT
golangci-lint run --sort-results --out-format tab --fix
npm --prefix ''$PRJ_ROOT/app/frontend run fix
update-npm-deps-hash
'';
}
{
name = "dev";
help = "Starts the javascript project in dev";
command = ''
npm --prefix ''$PRJ_ROOT/app/frontend run dev
'';
}
];
};
}

67
flake.lock Normal file
View File

@ -0,0 +1,67 @@
{
"nodes": {
"devshell": {
"inputs": {
"nixpkgs": [
"nix",
"nixpkgs"
]
},
"locked": {
"lastModified": 1728330715,
"narHash": "sha256-xRJ2nPOXb//u1jaBnDP56M7v5ldavjbtR6lfGqSvcKg=",
"owner": "numtide",
"repo": "devshell",
"rev": "dd6b80932022cea34a019e2bb32f6fa9e494dfef",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "devshell",
"type": "github"
}
},
"nix": {
"inputs": {
"devshell": "devshell",
"nixpkgs": "nixpkgs"
},
"locked": {
"lastModified": 1729027123,
"narHash": "sha256-LjD40ya8efdhxQ26Zy/LkLDOriZIHJZqutAorvPIka8=",
"ref": "refs/heads/main",
"rev": "d3596fc7e933c171a284771f7f72342d33ad6508",
"revCount": 5,
"type": "git",
"url": "ssh://git@git.c3c.cz/C3C/nix"
},
"original": {
"type": "git",
"url": "ssh://git@git.c3c.cz/C3C/nix"
}
},
"nixpkgs": {
"locked": {
"lastModified": 1728538411,
"narHash": "sha256-f0SBJz1eZ2yOuKUr5CA9BHULGXVSn6miBuUWdTyhUhU=",
"owner": "nixos",
"repo": "nixpkgs",
"rev": "b69de56fac8c2b6f8fd27f2eca01dcda8e0a4221",
"type": "github"
},
"original": {
"owner": "nixos",
"ref": "nixpkgs-unstable",
"repo": "nixpkgs",
"type": "github"
}
},
"root": {
"inputs": {
"nix": "nix"
}
}
},
"root": "root",
"version": 7
}

118
flake.nix Normal file
View File

@ -0,0 +1,118 @@
{
inputs = {
nix.url = "git+ssh://git@git.c3c.cz/C3C/nix";
};
outputs =
{ self, nix }:
{
formatter = nix.formatter;
packages = nix.lib.forAllSystems (pkgs:
let
version = "rev-${self.shortRev or self.dirtyShortRev}";
package = builtins.fromJSON (builtins.readFile ./app/frontend/package.json);
in
rec {
ui = pkgs.buildNpmPackage {
inherit version;
pname = "cv";
src = ./app/frontend;
npmInstallFlags = "--no-audit --no-progress --no-fund";
npmDepsHash = "sha256-p4rTpy0t8aajbubvtF1TA83/FFqvfKEOPBb5T0ZRfQY=";
npmPackFlags = [ "--ignore-scripts" ];
};
server = pkgs.buildGoModule {
inherit version;
pname = "cv";
CGO_ENABLED = 0;
src = ./.;
subPackages = [ "app/server" ];
postPatch = ''
rm -rf app/server/internal/files/data/public
mkdir -p app/server/internal/files/data/public
touch app/server/internal/files/data/public/.gitkeep
cp -Tr ${ui}/lib/node_modules/${package.name}/dist app/server/internal/files/data/public/
chmod +w -R app/server/internal/files/data/public
sed -i 's#<script#<script nonce="{{ .CspNonce }}"#g' app/server/internal/files/data/public/index.html
'';
ldflags = [
"-s"
"-w"
"-X gopkg.c3c.cz/cv/app/server/internal/version.Tag=${version}"
"-X gopkg.c3c.cz/cv/app/server/internal/version.Commit=${self.rev or self.dirtyRev}"
"-X gopkg.c3c.cz/cv/app/server/internal/version.commitTime=${builtins.toString (self.lastModified or 0)}"
];
vendorHash = "sha256-44xcyVk5KcurQLkVJv1MeAj+Pfcu53664pvVgHdyv3E=";
};
image = pkgs.dockerTools.streamLayeredImage {
name = "cv";
tag = version;
config = {
Env = [ "SSL_CERT_FILE=${pkgs.cacert}/etc/ssl/certs/ca-bundle.crt" ];
Entrypoint = [ "${server}/bin/server" ];
};
};
}
);
devShells = nix.lib.forAllSystems (pkgs: {
default = pkgs.devshell.mkShell {
name = "c3c-cv";
packages = [
pkgs.go
pkgs.nodejs_22
];
commands = [
{
name = "lint";
help = "run linters";
command = ''
${nix.lib.cd_root}
${pkgs.golangci-lint}/bin/golangci-lint run --sort-results --out-format tab --config ${nix.lib.golangci-config-file} ./...
npm --prefix app/frontend run check
'';
}
{
name = "fix";
help = "format & fix found issues";
command = ''
${nix.lib.cd_root}
nix fmt .
${pkgs.golangci-lint}/bin/golangci-lint run --sort-results --out-format tab --config ${nix.lib.golangci-config-file} --fix --issues-exit-code 0 ./...
npm --prefix app/frontend run fix
'';
}
{
name = "update-npm-deps-hash";
help = "Calculates and updates the npmDepsHash in default.nix";
command = ''
${nix.lib.cd_root}
echo "Calculating npm deps"
# STDERR is poluted by the installed nodules, silencing
HASH=''$(${pkgs.prefetch-npm-deps}/bin/prefetch-npm-deps ''$PRJ_ROOT/app/frontend/package-lock.json 2> /dev/null)
[[ ''$HASH = sha256* ]] && echo "Hash is ''$HASH"
[[ ''$HASH != sha256* ]] && echo "Failed" && exit 137
# Replace the first occurence of npmDepsHash with the new calculated hash in this file
sed -i "0,/npmDepsHash =/{s@npmDepsHash = .*@npmDepsHash = \"''$HASH\";@}" ./flake.nix
'';
}
{
name = "dev";
help = "Starts the javascript project in dev";
command = ''
npm --prefix ''$PRJ_ROOT/app/frontend run dev
'';
}
];
};
});
};
}