Skip to content

Commit 83c4566

Browse files
committed
Add deployment scripts
update deploy with flake.nix add github action
1 parent 1f1b0dd commit 83c4566

5 files changed

Lines changed: 1186 additions & 807 deletions

File tree

.github/workflows/deploy.yml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
name: Deploy Website
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
8+
jobs:
9+
deploy:
10+
runs-on: ubuntu-latest
11+
12+
steps:
13+
- name: Checkout repository
14+
uses: actions/checkout@v4
15+
16+
- name: Install Nix
17+
uses: cachix/install-nix-action@v24
18+
with:
19+
nix_path: nixpkgs=channel:nixos-unstable
20+
extra_nix_config: |
21+
experimental-features = nix-command flakes
22+
23+
- name: Deploy to Server
24+
run: |
25+
nix run .#deploy -- ${{ secrets.REMOTE_PASSWORD }}
26+
27+
- name: Deployment Success
28+
if: success()
29+
run: |
30+
echo "✅ Deployment completed successfully!"
31+
echo "🌐 Website deployed to: https://kellnr.io"
32+
33+
- name: Deployment Failed
34+
if: failure()
35+
run: |
36+
echo "❌ Deployment failed!"
37+
echo "Check the logs above for details."

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,3 +132,4 @@ dist
132132
.DS_Store
133133

134134
.idea/
135+
result/

flake.lock

Lines changed: 27 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

flake.nix

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
{
2+
description = "Development environment and deployment for kellnr website";
3+
4+
inputs = {
5+
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
6+
};
7+
8+
outputs =
9+
{ self, nixpkgs }:
10+
let
11+
allSystems = [
12+
"x86_64-linux"
13+
"aarch64-linux"
14+
"aarch64-darwin"
15+
];
16+
17+
forAllSystems =
18+
fn: nixpkgs.lib.genAttrs allSystems (system: fn { pkgs = import nixpkgs { inherit system; }; });
19+
20+
in
21+
{
22+
apps = forAllSystems (
23+
{ pkgs }:
24+
{
25+
deploy = {
26+
type = "app";
27+
program = toString (
28+
pkgs.writeShellScript "deploy-website" ''
29+
set -euo pipefail
30+
31+
REMOTE_HOST="kellnr.io"
32+
REMOTE_USER="root"
33+
REMOTE_TARGET_DIR="/var/www/html/kellnr/dist"
34+
REMOTE_PASSWORD="$1"
35+
36+
if [ -z "$REMOTE_PASSWORD" ]; then
37+
echo "Error: Password argument is required"
38+
echo "Usage: nix run .#deploy -- yourpassword"
39+
exit 1
40+
fi
41+
42+
echo "Building website..."
43+
${pkgs.nodejs_24}/bin/npm install
44+
${pkgs.nodejs_24}/bin/npm run build
45+
46+
echo "Deploying to $REMOTE_USER@$REMOTE_HOST:$REMOTE_TARGET_DIR..."
47+
${pkgs.sshpass}/bin/sshpass -p "$REMOTE_PASSWORD" \
48+
${pkgs.openssh}/bin/ssh -F /dev/null -o StrictHostKeyChecking=no \
49+
$REMOTE_USER@$REMOTE_HOST \
50+
"rm -rf $REMOTE_TARGET_DIR && mkdir -p $REMOTE_TARGET_DIR"
51+
52+
${pkgs.sshpass}/bin/sshpass -p "$REMOTE_PASSWORD" \
53+
${pkgs.rsync}/bin/rsync -avz --delete \
54+
-e "${pkgs.openssh}/bin/ssh -F /dev/null -o StrictHostKeyChecking=no" \
55+
dist/ $REMOTE_USER@$REMOTE_HOST:$REMOTE_TARGET_DIR/
56+
57+
echo "Restarting nginx..."
58+
${pkgs.sshpass}/bin/sshpass -p "$REMOTE_PASSWORD" \
59+
${pkgs.openssh}/bin/ssh -F /dev/null -o StrictHostKeyChecking=no \
60+
$REMOTE_USER@$REMOTE_HOST \
61+
"sudo systemctl restart nginx" || echo "Warning: Failed to restart nginx"
62+
63+
echo "Deployment completed!"
64+
''
65+
);
66+
};
67+
}
68+
);
69+
70+
devShells = forAllSystems (
71+
{ pkgs }:
72+
{
73+
default = pkgs.mkShell {
74+
buildInputs = with pkgs; [
75+
git
76+
nodejs_24
77+
openssh
78+
rsync
79+
sshpass
80+
];
81+
82+
shellHook = ''
83+
echo "Kellnr website development environment"
84+
echo ""
85+
echo "Available commands:"
86+
echo " npm install - Install dependencies"
87+
echo " npm run dev - Start development server"
88+
echo " npm run build - Build for production"
89+
echo " nix build - Build with Nix"
90+
echo " nix run .#deploy - Deploy to remote server"
91+
echo ""
92+
echo "Deployment usage:"
93+
echo " nix run .#deploy -- yourpassword"
94+
'';
95+
};
96+
}
97+
);
98+
};
99+
}

0 commit comments

Comments
 (0)