Nix all the things
All checks were successful
Build and Deploy / build-and-push (push) Successful in 2m36s
All checks were successful
Build and Deploy / build-and-push (push) Successful in 2m36s
This commit is contained in:
23
.env.example
23
.env.example
@@ -1,14 +1,13 @@
|
|||||||
# SMTP Configuration
|
# Container Image
|
||||||
SMTP_HOST=smtp.site.com
|
IMAGE=atashdotdev:latest
|
||||||
SMTP_PORT=587
|
|
||||||
SMTP_USER=email@site.com
|
|
||||||
SMTP_PASSWORD=your-app-password
|
|
||||||
|
|
||||||
# Email Configuration
|
# Application Port
|
||||||
FROM_EMAIL=email@site.com
|
|
||||||
TO_EMAIL=email@site.com
|
|
||||||
|
|
||||||
# Application Configuration
|
|
||||||
NODE_ENV=production
|
|
||||||
APP_PORT=4321
|
APP_PORT=4321
|
||||||
IMAGE=git.atri.dad/atridad/atashdotdev
|
|
||||||
|
# SMTP Configuration (required for contact form)
|
||||||
|
SMTP_HOST=smtp.example.com
|
||||||
|
SMTP_PORT=587
|
||||||
|
SMTP_USER=your-email@example.com
|
||||||
|
SMTP_PASSWORD=your-password
|
||||||
|
FROM_EMAIL=noreply@atash.dev
|
||||||
|
TO_EMAIL=contact@atash.dev
|
||||||
|
|||||||
35
.github/workflows/deploy.yml
vendored
35
.github/workflows/deploy.yml
vendored
@@ -1,9 +1,10 @@
|
|||||||
name: Docker Deploy
|
name: Build and Deploy
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
branches: [main]
|
branches: [main]
|
||||||
pull_request:
|
pull_request:
|
||||||
branches: [main]
|
branches: [main]
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
build-and-push:
|
build-and-push:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
@@ -12,24 +13,30 @@ jobs:
|
|||||||
packages: write
|
packages: write
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout code
|
- name: Checkout code
|
||||||
uses: actions/checkout@v3
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
- name: Set up Docker Buildx
|
- name: Install Nix
|
||||||
uses: docker/setup-buildx-action@v2
|
uses: cachix/install-nix-action@v26
|
||||||
|
with:
|
||||||
|
nix_path: nixpkgs=channel:nixos-unstable
|
||||||
|
extra_nix_config: |
|
||||||
|
experimental-features = nix-command flakes
|
||||||
|
|
||||||
|
- name: Build container image
|
||||||
|
run: |
|
||||||
|
nix build --impure --print-build-logs
|
||||||
|
docker load < result
|
||||||
|
|
||||||
- name: Login to Container Registry
|
- name: Login to Container Registry
|
||||||
uses: docker/login-action@v2
|
uses: docker/login-action@v3
|
||||||
with:
|
with:
|
||||||
registry: ${{ secrets.REPO_HOST }}
|
registry: ${{ secrets.REPO_HOST }}
|
||||||
username: ${{ github.repository_owner }}
|
username: ${{ github.repository_owner }}
|
||||||
password: ${{ secrets.DEPLOY_TOKEN }}
|
password: ${{ secrets.DEPLOY_TOKEN }}
|
||||||
|
|
||||||
- name: Build and push
|
- name: Tag and push images
|
||||||
uses: docker/build-push-action@v4
|
run: |
|
||||||
with:
|
docker tag atashdotdev:latest ${{ secrets.REPO_HOST }}/${{ github.repository_owner }}/${{ github.event.repository.name }}:${{ github.sha }}
|
||||||
context: .
|
docker tag atashdotdev:latest ${{ secrets.REPO_HOST }}/${{ github.repository_owner }}/${{ github.event.repository.name }}:latest
|
||||||
platforms: linux/amd64
|
docker push ${{ secrets.REPO_HOST }}/${{ github.repository_owner }}/${{ github.event.repository.name }}:${{ github.sha }}
|
||||||
push: true
|
docker push ${{ secrets.REPO_HOST }}/${{ github.repository_owner }}/${{ github.event.repository.name }}:latest
|
||||||
tags: |
|
|
||||||
${{ secrets.REPO_HOST }}/${{ github.repository_owner }}/${{ github.event.repository.name }}:${{ github.sha }}
|
|
||||||
${{ secrets.REPO_HOST }}/${{ github.repository_owner }}/${{ github.event.repository.name }}:latest
|
|
||||||
|
|||||||
1
.gitignore
vendored
1
.gitignore
vendored
@@ -1,5 +1,6 @@
|
|||||||
# build output
|
# build output
|
||||||
dist/
|
dist/
|
||||||
|
result
|
||||||
|
|
||||||
# generated types
|
# generated types
|
||||||
.astro/
|
.astro/
|
||||||
|
|||||||
@@ -1,14 +1,16 @@
|
|||||||
services:
|
services:
|
||||||
app:
|
app:
|
||||||
image: ${IMAGE}
|
image: ${IMAGE:-atashdotdev:latest}
|
||||||
ports:
|
ports:
|
||||||
- "${APP_PORT}:4321"
|
- "${APP_PORT:-4321}:4321"
|
||||||
environment:
|
environment:
|
||||||
NODE_ENV: production
|
NODE_ENV: production
|
||||||
SMTP_HOST: ${SMTP_HOST}
|
HOST: 0.0.0.0
|
||||||
SMTP_PORT: ${SMTP_PORT}
|
PORT: 4321
|
||||||
SMTP_USER: ${SMTP_USER}
|
SMTP_HOST: ${SMTP_HOST:-}
|
||||||
SMTP_PASSWORD: ${SMTP_PASSWORD}
|
SMTP_PORT: ${SMTP_PORT:-587}
|
||||||
FROM_EMAIL: ${FROM_EMAIL}
|
SMTP_USER: ${SMTP_USER:-}
|
||||||
TO_EMAIL: ${TO_EMAIL}
|
SMTP_PASSWORD: ${SMTP_PASSWORD:-}
|
||||||
|
FROM_EMAIL: ${FROM_EMAIL:-noreply@atash.dev}
|
||||||
|
TO_EMAIL: ${TO_EMAIL:-}
|
||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
|
|||||||
94
flake.nix
94
flake.nix
@@ -1,5 +1,5 @@
|
|||||||
{
|
{
|
||||||
description = "Development environment for atashdotdev with Node and pnpm";
|
description = "atashdotdev - Astro application with Nix build";
|
||||||
|
|
||||||
inputs = {
|
inputs = {
|
||||||
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
|
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
|
||||||
@@ -10,24 +10,104 @@
|
|||||||
flake-utils.lib.eachDefaultSystem (system:
|
flake-utils.lib.eachDefaultSystem (system:
|
||||||
let
|
let
|
||||||
pkgs = nixpkgs.legacyPackages.${system};
|
pkgs = nixpkgs.legacyPackages.${system};
|
||||||
|
|
||||||
|
# Build the Astro application
|
||||||
|
atashdotdev = pkgs.stdenv.mkDerivation rec {
|
||||||
|
pname = "atashdotdev";
|
||||||
|
version = "1.1.0";
|
||||||
|
|
||||||
|
src = ./.;
|
||||||
|
|
||||||
|
nativeBuildInputs = with pkgs; [
|
||||||
|
nodejs_24
|
||||||
|
nodePackages.pnpm
|
||||||
|
cacert
|
||||||
|
];
|
||||||
|
|
||||||
|
configurePhase = ''
|
||||||
|
export HOME=$TMPDIR
|
||||||
|
export SSL_CERT_FILE=${pkgs.cacert}/etc/ssl/certs/ca-bundle.crt
|
||||||
|
pnpm config set store-dir $TMPDIR/pnpm-store
|
||||||
|
'';
|
||||||
|
|
||||||
|
buildPhase = ''
|
||||||
|
pnpm install --frozen-lockfile
|
||||||
|
pnpm build
|
||||||
|
'';
|
||||||
|
|
||||||
|
installPhase = ''
|
||||||
|
mkdir -p $out/lib/atashdotdev
|
||||||
|
cp -r dist $out/lib/atashdotdev/
|
||||||
|
cp package.json $out/lib/atashdotdev/
|
||||||
|
cp pnpm-lock.yaml $out/lib/atashdotdev/
|
||||||
|
|
||||||
|
cd $out/lib/atashdotdev
|
||||||
|
pnpm install --prod --frozen-lockfile
|
||||||
|
|
||||||
|
mkdir -p $out/bin
|
||||||
|
cat > $out/bin/atashdotdev << 'EOF'
|
||||||
|
#!/bin/sh
|
||||||
|
cd $out/lib/atashdotdev
|
||||||
|
exec ${pkgs.nodejs_24}/bin/node ./dist/server/entry.mjs "$@"
|
||||||
|
EOF
|
||||||
|
chmod +x $out/bin/atashdotdev
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
|
||||||
|
# Container image
|
||||||
|
containerImage = pkgs.dockerTools.buildLayeredImage {
|
||||||
|
name = "atashdotdev";
|
||||||
|
tag = "latest";
|
||||||
|
|
||||||
|
contents = with pkgs; [
|
||||||
|
atashdotdev
|
||||||
|
nodejs_24
|
||||||
|
bash
|
||||||
|
coreutils
|
||||||
|
cacert
|
||||||
|
];
|
||||||
|
|
||||||
|
config = {
|
||||||
|
Cmd = [ "${atashdotdev}/bin/atashdotdev" ];
|
||||||
|
ExposedPorts = {
|
||||||
|
"4321/tcp" = {};
|
||||||
|
};
|
||||||
|
Env = [
|
||||||
|
"NODE_ENV=production"
|
||||||
|
"HOST=0.0.0.0"
|
||||||
|
"PORT=4321"
|
||||||
|
];
|
||||||
|
WorkingDir = "${atashdotdev}/lib/atashdotdev";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
|
# Dev shell
|
||||||
devShells.default = pkgs.mkShell {
|
devShells.default = pkgs.mkShell {
|
||||||
packages = with pkgs; [
|
packages = with pkgs; [
|
||||||
nodejs_24
|
nodejs_24
|
||||||
nodePackages.pnpm
|
nodePackages.pnpm
|
||||||
];
|
];
|
||||||
|
};
|
||||||
|
|
||||||
shellHook = ''
|
# Default package is the container
|
||||||
echo "🚀 atashdotdev development environment loaded!"
|
packages = {
|
||||||
echo "Node version: $(node --version)"
|
default = containerImage;
|
||||||
echo "pnpm version: $(pnpm --version)"
|
atashdotdev = atashdotdev;
|
||||||
|
containerImage = containerImage;
|
||||||
|
};
|
||||||
|
|
||||||
|
# Dev server app
|
||||||
|
apps.default = {
|
||||||
|
type = "app";
|
||||||
|
program = "${pkgs.writeShellScript "dev" ''
|
||||||
|
export PATH="${pkgs.nodejs_24}/bin:${pkgs.nodePackages.pnpm}/bin:$PATH"
|
||||||
if [ ! -d "node_modules" ]; then
|
if [ ! -d "node_modules" ]; then
|
||||||
echo "📦 Installing pnpm dependencies..."
|
|
||||||
pnpm install --frozen-lockfile
|
pnpm install --frozen-lockfile
|
||||||
fi
|
fi
|
||||||
'';
|
pnpm dev
|
||||||
|
''}";
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user