Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
nevivurn committed Nov 2, 2023
0 parents commit e4d4475
Show file tree
Hide file tree
Showing 5 changed files with 168 additions and 0 deletions.
33 changes: 33 additions & 0 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: Build and push image

on:
push:
branches:
- master

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

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- uses: cachix/install-nix-action@v22
- run: nix build .#docker

- uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Tag and Push
env:
GH_IMAGE: ghcr.io/${{ github.repository }}:${{ github.sha }}
run: |
IMAGE="$(docker load -i result | awk '{print $3}')"
docker tag "$IMAGE" "$GH_IMAGE"
docker push "$GH_IMAGE"
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/result
/result-*
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# secure front

```console
$ nix build .#docker
$ docker load -i result
Loaded image: localhost/secure-front:q4b69zbzv9x79kybqzhs53hfd7syxpsb
```
58 changes: 58 additions & 0 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

68 changes: 68 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
{
outputs = { self, flake-utils, nixpkgs }:
flake-utils.lib.eachDefaultSystem (system:
let
lib = nixpkgs.lib;
pkgs = nixpkgs.legacyPackages.${system};
placeholder = self.packages.${system}.placeholder;
in
{
packages = {
placeholder = pkgs.stdenvNoCC.mkDerivation {
name = "placeholder";
src = pkgs.fetchFromGitHub {
owner = "bacchus-snu";
repo = "snucse-gpu-service-manual";
rev = "3dd6d4df9b6c8ffbcc6073826527f119c7fd937f";
hash = "sha256-e9GANnoJpUggZROINZ0kxtrjA4uubrhzEIWjNCONE5U=";
};

postPatch = ''
cat <<EOF > src/robots.txt
User-Agent: *
Disallow: /
EOF
'';

nativeBuildInputs = with pkgs; [ mdbook mdbook-i18n-helpers ];

buildPhase = ''
mdbook build -d $out
'';
};
docker =
let
caddyfile = pkgs.writeText "Caddyfile" ''
:8080 {
root * ${placeholder}
file_server
handle_errors {
rewrite * /{err.status_code}.html
file_server
}
# such secure
header {
X-Frame-Options DENY
X-XSS-Protection 0
X-Content-Type-Options nosniff
}
}
'';
in
pkgs.dockerTools.buildLayeredImage {
name = "secure-front";
config = {
User = "1000";
Cmd = [
(lib.getExe pkgs.caddy)
"run"
"--adapter=caddyfile"
"--config=${caddyfile}"
];
};
};
};
}
);
}

0 comments on commit e4d4475

Please sign in to comment.