Signed-off-by: Max Schmidt <max.schmidt@outlook.de>
This commit is contained in:
Max Schmidt 2023-05-17 09:18:08 +02:00
parent a4ed5449e9
commit 7f01d39909
20 changed files with 133 additions and 37 deletions

9
.env.dev Normal file
View File

@ -0,0 +1,9 @@
PAYLOAD_SECRET=supersecretkey
PAYLOAD_URL=http://localhost:3001
PAYLOAD_PORT=3001
MONGODB_URI=mongodb://payload:test@mongo:27017
MONGODB_USER=payload
MONGODB_PW=test
MONGODB_DB=payload
NAME=astroad

View File

@ -1,6 +1,7 @@
MONGODB_URI=mongodb://payload:test@mongo:27017
PAYLOAD_SECRET=supersecretkey
PAYLOAD_URL=http://localhost:3001
PAYLOAD_PORT=3001
MONGODB_URI=mongodb://payload:test@mongo:27017
MONGODB_USER=payload
MONGODB_PW=test
MONGODB_DB=payload

0
.github/workflows/push vendored Normal file
View File

View File

@ -13,9 +13,8 @@ FROM base AS build
ENV NODE_ENV=production
WORKDIR /build
COPY --from=base /base ./
ADD "https://www.random.org/cgi-bin/randbyte?nbytes=10&format=h" skipcache
RUN yarn build
FROM nginx:stable AS prod
COPY --from=build /build/dist /usr/share/nginx/html
EXPOSE 80
EXPOSE 3000

View File

@ -2,18 +2,23 @@ import { defineConfig } from "astro/config";
import tailwind from "@astrojs/tailwind";
import image from "@astrojs/image";
import compress from "astro-compress";
import critters from "astro-critters";
import sitemap from "@astrojs/sitemap";
import prefetch from "@astrojs/prefetch";
export default defineConfig({
integrations: [
tailwind({
config: { applyBaseStyles: false },
config: {
applyBaseStyles: false,
},
}),
image({
serviceEntryPoint: "@astrojs/image/sharp",
}),
compress(),
critters(),
sitemap(),
prefetch(),
],
});

View File

@ -9,6 +9,8 @@
},
"dependencies": {
"@astrojs/image": "^0.16.8",
"@astrojs/prefetch": "^0.2.1",
"@astrojs/sitemap": "^1.3.1",
"@astrojs/tailwind": "3.1.2",
"astro": "^2.4.5",
"astro-compress": "^1.1.43",

View File

@ -1,6 +1,6 @@
---
import Layout from "../../layouts/Layout.astro";
import RichText from "../../components/RichText.astro";
import Content from "../../components/Content.astro";
import type { Post } from "../../types";
import { getPost, getPosts } from "../../utils/payload";
@ -22,7 +22,7 @@ const post = id && (await getPost(id));
<div class="max-w-3xl mx-auto space-y-3 my-3">
<a href="/">BACK</a>
<h1>{post.title}</h1>
{post.content && <RichText content={post.content} />}
{post.content && <Content content={post.content} />}
</div>
</Layout>
) : (

View File

@ -75,6 +75,13 @@
unist-util-visit "^4.1.0"
vfile "^5.3.2"
"@astrojs/prefetch@^0.2.1":
version "0.2.1"
resolved "https://registry.yarnpkg.com/@astrojs/prefetch/-/prefetch-0.2.1.tgz#365bb38ce9da06febf78fad1dfc40291281f8885"
integrity sha512-kVDhUl0BzN/3D1NJL5ndgKK5Dk/mdSf5LinKrPIVVVND+hrdErkihV53sA3pyffdw488pFvAiFu2+LW/DWhiHA==
dependencies:
throttles "^1.0.1"
"@astrojs/prism@^2.1.0":
version "2.1.1"
resolved "https://registry.yarnpkg.com/@astrojs/prism/-/prism-2.1.1.tgz#5f6ae1ab5b630889a8850ba2c991888ed92a3c7a"
@ -82,6 +89,14 @@
dependencies:
prismjs "^1.28.0"
"@astrojs/sitemap@^1.3.1":
version "1.3.1"
resolved "https://registry.yarnpkg.com/@astrojs/sitemap/-/sitemap-1.3.1.tgz#2833f329e43d7210d651a1e5155625d138c6f65b"
integrity sha512-4ZBug4ml+2Nl5/Uh4VSja8Kij/DU7/RaNMciXCNm1EzQkP/jm+nqMG1liDDcQK5zXPAoLeaat06IbhNlruvQjg==
dependencies:
sitemap "^7.1.1"
zod "^3.17.3"
"@astrojs/tailwind@3.1.2":
version "3.1.2"
resolved "https://registry.yarnpkg.com/@astrojs/tailwind/-/tailwind-3.1.2.tgz#0de7912535554f3c2fcfc8eca94767f618603100"
@ -764,6 +779,16 @@
dependencies:
"@types/unist" "*"
"@types/node@*":
version "20.1.5"
resolved "https://registry.yarnpkg.com/@types/node/-/node-20.1.5.tgz#e94b604c67fc408f215fcbf3bd84d4743bf7f710"
integrity sha512-IvGD1CD/nego63ySR7vrAKEX3AJTcmrAN2kn+/sDNLi1Ff5kBzDeEdqWDplK+0HAEoLYej137Sk0cUU8OLOlMg==
"@types/node@^17.0.5":
version "17.0.45"
resolved "https://registry.yarnpkg.com/@types/node/-/node-17.0.45.tgz#2c0fafd78705e7a18b7906b5201a522719dc5190"
integrity sha512-w+tIMs3rq2afQdsPJlODhoUEKzFP1ayaoyl1CcnwtIlsVe7K7bA1NGm4s3PraqTLlXnbIN84zuBlxBWo1u9BLw==
"@types/parse5@^6.0.0":
version "6.0.3"
resolved "https://registry.yarnpkg.com/@types/parse5/-/parse5-6.0.3.tgz#705bb349e789efa06f43f128cef51240753424cb"
@ -774,6 +799,13 @@
resolved "https://registry.yarnpkg.com/@types/resolve/-/resolve-1.20.2.tgz#97d26e00cd4a0423b4af620abecf3e6f442b7975"
integrity sha512-60BCwRFOZCQhDncwQdxxeOEEkbc5dIMccYLwbxsS4TUNeVECQ/pBJ0j09mrHOl/JJvpRPGwO9SvE4nR2Nb/a4Q==
"@types/sax@^1.2.1":
version "1.2.4"
resolved "https://registry.yarnpkg.com/@types/sax/-/sax-1.2.4.tgz#8221affa7f4f3cb21abd22f244cfabfa63e6a69e"
integrity sha512-pSAff4IAxJjfAXUG6tFkO7dsSbTmf8CtUpfhhZ5VhkRpC4628tJhh3+V6H1E+/Gs9piSzYKT5yzHO5M4GG9jkw==
dependencies:
"@types/node" "*"
"@types/sharp@0.32.0":
version "0.32.0"
resolved "https://registry.yarnpkg.com/@types/sharp/-/sharp-0.32.0.tgz#fc3ac6df6b456319bae807c3d24efdc6631cdd6f"
@ -866,7 +898,7 @@ anymatch@~3.1.2:
normalize-path "^3.0.0"
picomatch "^2.0.4"
arg@^5.0.2:
arg@^5.0.0, arg@^5.0.2:
version "5.0.2"
resolved "https://registry.yarnpkg.com/arg/-/arg-5.0.2.tgz#c81433cc427c92c4dcf4865142dbca6f15acd59c"
integrity sha512-PYjyFOLKQ9y57JvQ6QLo8dAgNqswh8M1RMJYdQduT6xbWSgK36P/Z/v+p888pM69jMMfS8Xd8F6I1kQ/I9HUGg==
@ -3480,6 +3512,11 @@ sass-formatter@^0.7.5:
dependencies:
suf-log "^2.5.3"
sax@^1.2.4:
version "1.2.4"
resolved "https://registry.yarnpkg.com/sax/-/sax-1.2.4.tgz#2816234e2378bddc4e5354fab5caa895df7100d9"
integrity sha512-NqVDv9TpANUjFm0N8uM5GxL36UgKi9/atZw+x7YFnQ8ckwFGKrl4xX4yWtrey3UJm5nP1kUbnYgLopqWNSRhWw==
section-matter@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/section-matter/-/section-matter-1.0.0.tgz#e9041953506780ec01d59f292a19c7b850b84167"
@ -3572,6 +3609,16 @@ sisteransi@^1.0.5:
resolved "https://registry.yarnpkg.com/sisteransi/-/sisteransi-1.0.5.tgz#134d681297756437cc05ca01370d3a7a571075ed"
integrity sha512-bLGGlR1QxBcynn2d5YmDX4MGjlZvy2MRBDRNHLJ8VI6l6+9FUiyTFNJ0IveOSP0bcXgVDPRcfGqA0pjaqUpfVg==
sitemap@^7.1.1:
version "7.1.1"
resolved "https://registry.yarnpkg.com/sitemap/-/sitemap-7.1.1.tgz#eeed9ad6d95499161a3eadc60f8c6dce4bea2bef"
integrity sha512-mK3aFtjz4VdJN0igpIJrinf3EO8U8mxOPsTBzSsy06UtjZQJ3YY3o3Xa7zSc5nMqcMrRwlChHZ18Kxg0caiPBg==
dependencies:
"@types/node" "^17.0.5"
"@types/sax" "^1.2.1"
arg "^5.0.0"
sax "^1.2.4"
slash@^4.0.0:
version "4.0.0"
resolved "https://registry.yarnpkg.com/slash/-/slash-4.0.0.tgz#2422372176c4c6c5addb5e2ada885af984b396a7"
@ -3863,6 +3910,11 @@ thenify-all@^1.0.0:
dependencies:
any-promise "^1.0.0"
throttles@^1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/throttles/-/throttles-1.0.1.tgz#3abdcde28df88d5eddf7e57cad8da35bd403ddd0"
integrity sha512-fab7Xg+zELr9KOv4fkaBoe/b3L0GMGLd0IBSCn16GoE/Qx6/OfCr1eGNyEcDU2pUA79qQfZ8kPQWlRuok4YwTw==
tiny-warning@^1.0.3:
version "1.0.3"
resolved "https://registry.yarnpkg.com/tiny-warning/-/tiny-warning-1.0.3.tgz#94a30db453df4c643d0fd566060d60a875d84754"
@ -4240,7 +4292,7 @@ yocto-queue@^0.1.0:
resolved "https://registry.yarnpkg.com/yocto-queue/-/yocto-queue-0.1.0.tgz#0294eb3dee05028d31ee1a5fa2c556a6aaf10a1b"
integrity sha512-rVksvsnNCdJ/ohGc6xgPwyN8eheCxsiLM8mxuE/t/mOVqJewPuO1miLpTHQiRgTKCLexL4MeAFVagts7HmNZ2Q==
zod@^3.20.6:
zod@^3.17.3, zod@^3.20.6:
version "3.21.4"
resolved "https://registry.yarnpkg.com/zod/-/zod-3.21.4.tgz#10882231d992519f0a10b5dd58a38c9dabbb64db"
integrity sha512-m46AKbrzKVzOzs/DZgVnG5H55N1sv1M8qZU3A8RIKbs3mrACDNeIOeilDymVb2HdmP8uwshOCF4uJ8uM9rCqJw==

View File

@ -1,7 +1,7 @@
{
"tasks": {
"dev": "docker compose -f docker-compose.yml -f docker-compose-dev.yml --env-file .env.development up -d",
"prod": "docker compose -f docker-compose.yml -f docker-compose-prod.yml --env-file .env.production up -d --build",
"dev": "docker compose -f docker-compose.yml -f docker-compose-dev.yml --env-file .env.dev up -d",
"prod": "docker compose -f docker-compose.yml -f docker-compose-prod.yml --env-file .env.prod up -d --build",
"dump": "docker exec -i astrotus_database /bin/sh -c 'PGPASSWORD=password pg_dump --username directus directus' > ./dump.sql"
}
}

18
docker-compose-prod.yml Normal file
View File

@ -0,0 +1,18 @@
services:
astro:
build:
context: astro
target: prod
ports:
- 3000:3000
payload:
build:
context: payload
target: prod
ports:
- 3001:3001
mongo:
ports:
- 27017:27017

View File

@ -2,9 +2,13 @@ services:
astro:
container_name: ${NAME}-astro
restart: unless-stopped
networks:
- hallo
depends_on:
- payload
payload:
container_name: ${NAME}_cms
container_name: ${NAME}_payload
restart: unless-stopped
build:
context: ./payload
@ -12,10 +16,17 @@ services:
volumes:
- ./data/media:/app/dist/media
environment:
MONGODB_URI: ${MONGODB_URI}
PORT: ${PAYLOAD_PORT}
PAYLOAD_SECRET: ${PAYLOAD_SECRET}
MONGODB_URI: ${MONGODB_URI}
networks:
- hallo
- test
depends_on:
- mongo
mongo:
container_name: ${NAME}_mongo
image: mongo:6.0.5
volumes:
- ./data/mongo:/data/db
@ -24,3 +35,9 @@ services:
environment:
MONGO_INITDB_ROOT_USERNAME: ${MONGODB_USER}
MONGO_INITDB_ROOT_PASSWORD: ${MONGODB_PW}
networks:
- test
networks:
hallo:
test:

10
node_modules/.yarn-integrity generated vendored
View File

@ -1,10 +0,0 @@
{
"systemParams": "darwin-arm64-108",
"modulesFolders": [],
"flags": [],
"linkedModules": [],
"topLevelPatterns": [],
"lockfileEntries": {},
"files": [],
"artifacts": {}
}

1
payload/.dockerignore Normal file
View File

@ -0,0 +1 @@
node_modules

4
payload/.gitignore vendored
View File

@ -1,3 +1,5 @@
node_modules/
.env
yarn.lock
yarn.lock
build
dist

View File

@ -1,8 +1,8 @@
FROM node:lts-alpine as base
WORKDIR /base
COPY ./package.json ./package.json
COPY ./package.json .
RUN yarn install
COPY ./ ./
COPY . .
FROM base AS dev
ENV NODE_ENV=development
@ -13,15 +13,15 @@ CMD ["yarn","dev"]
FROM base AS build
ENV NODE_ENV=production
WORKDIR /build
COPY --from=base /base ./
COPY --from=base /base .
RUN yarn build
FROM build as prod
ENV NODE_ENV=production
WORKDIR /prod
COPY package.json ./
COPY package*.json .
RUN yarn install --production
COPY --from=buil /build/dist ./dist
COPY --from=buil /build/build ./build
EXPOSE 3000
CMD ["node", "dist/server.js"]
COPY --from=build /build/dist ./dist
COPY --from=build /build/build ./build
EXPOSE 3001
CMD ["yarn", "serve"]

View File

@ -9,17 +9,17 @@
"build:payload": "cross-env PAYLOAD_CONFIG_PATH=src/payload.config.ts payload build",
"build:server": "tsc",
"build": "yarn build:payload && yarn build:server",
"serve": "cross-env PAYLOAD_CONFIG_PATH=dist/payload.config.js NODE_ENV=production node dist/server.js",
"serve": "cross-env PAYLOAD_CONFIG_PATH=dist/payload.config.ts node dist/server.js",
"generate:types": "cross-env PAYLOAD_CONFIG_PATH=src/payload.config.ts payload generate:types"
},
"dependencies": {
"payload": "^1.8.2",
"dotenv": "^8.2.0",
"express": "^4.17.1"
"express": "^4.17.1",
"cross-env": "^7.0.3"
},
"devDependencies": {
"@types/express": "^4.17.9",
"cross-env": "^7.0.3",
"nodemon": "^2.0.6",
"ts-node": "^9.1.1",
"typescript": "^4.1.3"

View File

@ -5,7 +5,7 @@ import Users from "./collections/Users";
import Media from "./collections/Media";
export default buildConfig({
serverURL: "http://localhost:3001",
serverURL: process.env.PAYLOAD_URL,
admin: {
user: Users.slug,
},

View File

@ -21,4 +21,4 @@ payload.init({
// Add your own express routes here
app.listen(3001);
app.listen(process.env.PAYLOAD_PORT);