Skip to content

Commit

Permalink
feat: add demo (#29)
Browse files Browse the repository at this point in the history
* chore: simplify build proccess

* chore: add demo

* chore(demo): install deps

* chore: correct dockerfile
  • Loading branch information
njfamirm authored Jan 10, 2025
1 parent 2f61e7e commit 0664dec
Show file tree
Hide file tree
Showing 11 changed files with 4,885 additions and 10 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
node_modules
dist
dist
12 changes: 3 additions & 9 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,7 @@ ENV NODE_ENV production

# Install dependencies
COPY package.json *.lock ./
RUN if [ -f *.lock ]; then \
yarn install --frozen-lockfile --non-interactive --production false; \
else \
yarn install --non-interactive --production false; \
fi;
RUN yarn install --frozen-lockfile --non-interactive --production false

COPY . .

Expand All @@ -35,16 +31,14 @@ CMD ["yarn", "serve"]

ENV NODE_ENV production
ENV NODE_OPTIONS --enable-source-maps
# ENV ALWATR_DEBUG 1
ENV HOST 0.0.0.0
ENV PORT 80

EXPOSE 80

# Copy all deps from last stage
COPY --from=builder /app/node_modules ./node_modules

# Copy builded files from last stage
ARG PACKAGE_SOURCE
COPY --from=builder /app/package.json ./

COPY --from=builder /app/dist ./dist
RUN pwd; ls -lAhF;
8 changes: 8 additions & 0 deletions demo/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
CMS_BACKEND_IMAGE="ghcr.io/njfamirm/decap-cms-github-backend:1.1.1"
OAUTH_GITHUB_CLIENT_ID="maybe-secret"
OAUTH_GITHUB_CLIENT_SECRET="secret"
DOMAIN='decap-demo.njfamirm.ir'
OAUTH_GITHUB_SCOPE=public_repo

# Enable debug logging
CMS_BACKEND_DEBUG=1
2 changes: 2 additions & 0 deletions demo/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules
*.min.js
3 changes: 3 additions & 0 deletions demo/admin/admin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import CMS from 'netlify-cms-app';

CMS.init();
13 changes: 13 additions & 0 deletions demo/admin/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="robots" content="noindex" />
<title>Website | Admin Panel</title>
<script type="module" src="/admin/admin.min.js"></script>
<link href="/config.yaml" type="text/yaml" rel="cms-config-url">
</head>
<body>
</body>
</html>
27 changes: 27 additions & 0 deletions demo/compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
networks:
internal:
alwatr-public-network:
name: alwatr-public-network
external: true

services:
cms-backend:
image: ${CMS_BACKEND_IMAGE}

restart: unless-stopped

environment:
- OAUTH_GITHUB_CLIENT_SECRET=${OAUTH_GITHUB_CLIENT_SECRET}
- OAUTH_GITHUB_CLIENT_ID=${OAUTH_GITHUB_CLIENT_ID}
- OAUTH_GITHUB_SCOPE=${OAUTH_GITHUB_SCOPE-}
- ALWATR_DEBUG=${CMS_BACKEND_DEBUG-}

networks:
alwatr-public-network:

labels:
traefik.enable: true
traefik.port: 80
traefik.frontend.rule: Host:${DOMAIN};
traefik.frontend.entryPoints: http, https
traefik.frontend.redirect.entryPoint: https
21 changes: 21 additions & 0 deletions demo/config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
backend:
name: github
branch: main
repo: njfamirm/decap-cms-github-backend
base_url: https://decap-demo.njfamirm.ir/

publish_mode: editorial_workflow

media_folder: "static/uploads"
public_folder: "/uploads"

collections:
- name: blog
label: Blog
folder: "content/blog"
create: true
slug: "{{year}}-{{month}}-{{day}}-{{slug}}"
fields:
- { label: "Title", name: "title", widget: "string" }
- { label: "Date", name: "date", widget: "datetime" }
- { label: "Body", name: "body", widget: "markdown" }
35 changes: 35 additions & 0 deletions demo/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"name": "@njfamirm/decap-cms-github-backend-demo",
"author": "S. Amir Mohammad Najafi <njfamirm@gamil.com> (https://www.njfamirm.ir)",
"description": "Demo of self-hosted decap cms github backend.",
"license": "MIT",
"private": true,
"type": "module",
"scripts": {
"b": "yarn build",
"s": "yarn start",
"start": "NODE_OPTIONS=--enable-source-maps run-s clean build serve",
"build": "yarn build:es --analyze=verbose",
"build:demo": "esbuild demo/admin.js --bundle --minify --outfile=demo/admin.min.js",
"build:ts": "tsc --build",
"build:es": "esbuild src/index.ts --platform=node --external:simple-oauth2 --target=node22 --bundle --format=esm --minify --sourcemap --outdir=dist --out-extension:.js=.mjs",
"clean": "rm -rf dist build .tsbuildinfo",
"serve": "node --enable-source-maps dist/index.mjs",
"serve:debug": "node --inspect --enable-source-maps dist/index.mjs",
"watch": "run-s clean build && run-p watch:es watch:node",
"watch:node": "nodemon -w dist/ --enable-source-maps dist/index.mjs",
"watch:debug-node": "nodemon -w dist/ --inspect --enable-source-maps dist/index.mjs",
"watch:ts": "yarn build:ts --watch --preserveWatchOutput",
"watch:es": "yarn build:es --watch",
"release": "standard-version --sign"
},
"dependencies": {
"netlify-cms-app": "^2.15.72"
},
"devDependencies": {
"@types/node": "^22.10.5",
"@web/dev-server": "^0.4.6",
"esbuild": "^0.24.2"
},
"packageManager": "yarn@1.22.22+sha256.c17d3797fb9a9115bf375e31bfd30058cac6bc9c3b8807a3d8cb2094794b51ca"
}
13 changes: 13 additions & 0 deletions demo/web-dev-server.config.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// https://modern-web.dev/docs/dev-server/cli-and-configuration/#configuration-file

/** @type {import('@web/dev-server').DevServerConfig} */
const config = {
hostname: '0.0.0.0',
port: 8080,
watch: true,
nodeResolve: {exportConditions: ['development']},
rootDir: '.',
clearTerminalOnReload: false,
};

module.exports = config;
Loading

0 comments on commit 0664dec

Please sign in to comment.