Signed-off-by: Max Schmidt <max.schmidt@outlook.de>
This commit is contained in:
Max Schmidt 2023-05-13 19:10:37 +02:00
parent 43fc0a402c
commit 0dfad4431f
14 changed files with 136 additions and 52 deletions

5
.env
View File

@ -1,5 +0,0 @@
MONGODB_URI=mongodb://payload:test@localhost:27017/payload
PAYLOAD_SECRET=supersecretkey
MONGODB_USER=payload
MONGODB_PW=test
MONGODB_DB=payload

7
.env.development Normal file
View File

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

21
astro/Dockerfile Normal file
View File

@ -0,0 +1,21 @@
FROM node:lts-alpine as base
WORKDIR /base
COPY ./package.json ./package.json
RUN yarn install
COPY ./ ./
FROM base AS dev
ENV NODE_ENV=development
EXPOSE 3000
CMD ["yarn","dev"]
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

View File

@ -3,11 +3,8 @@
"type": "module", "type": "module",
"version": "0.0.1", "version": "0.0.1",
"scripts": { "scripts": {
"dev": "astro dev", "dev": "astro dev --host",
"start": "astro dev", "build": "astro build"
"build": "astro build",
"preview": "astro preview",
"astro": "astro"
}, },
"dependencies": { "dependencies": {
"astro": "^2.4.1" "astro": "^2.4.1"

View File

@ -1,14 +1,20 @@
--- ---
import Layout from '../layouts/Layout.astro'; import Layout from '../layouts/Layout.astro';
import Card from '../components/Card.astro'; import Card from '../components/Card.astro';
import type { Post } from '../../../types'; import type { Post } from '../types';
const posts: Post[] = (await(await fetch("http://localhost:3001/api/posts")).json()).docs; const posts: Post[] = (await(await fetch("http://payload:3001/api/posts")).json()).docs;
posts.forEach(post=> console.log(post.title)); posts.forEach(post=> console.log(post.title));
--- ---
<Layout title="Welcome to Astro."> <Layout title="Welcome to Astro.">
<main> <main>
{posts.reverse().map(post => (
<article>
<h2>{post.title}</h2>
<p>{post.updatedAt}</p>
</article>
))}
<h1>Welcome to <span class="text-gradient">Astro</span></h1> <h1>Welcome to <span class="text-gradient">Astro</span></h1>
<p class="instructions"> <p class="instructions">
To get started, open the directory <code>src/pages</code> in your project.<br /> To get started, open the directory <code>src/pages</code> in your project.<br />

0
types.ts → astro/src/types.ts Normal file → Executable file
View File

7
deno.json Normal file
View File

@ -0,0 +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",
"dump": "docker exec -i astrotus_database /bin/sh -c 'PGPASSWORD=password pg_dump --username directus directus' > ./dump.sql"
}
}

24
docker-compose-dev.yml Normal file
View File

@ -0,0 +1,24 @@
services:
astro:
build:
context: astro
target: dev
volumes:
- ./astro/src:/base/src
- .env.development:/base/.env.development
ports:
- 3000:3000
payload:
build:
context: payload
target: dev
volumes:
- ./payload/src:/base/src
- ./astro/src/types.ts:/types.ts
ports:
- 3001:3001
mongo:
ports:
- 27017:27017

View File

@ -1,9 +1,11 @@
services: services:
astro: astro:
build: container_name: ${NAME}-astro
context: ./astro restart: unless-stopped
dockerfile: Dockerfile
payload: payload:
container_name: ${NAME}_cms
restart: unless-stopped
build: build:
context: ./payload context: ./payload
dockerfile: Dockerfile dockerfile: Dockerfile
@ -12,7 +14,6 @@ services:
environment: environment:
MONGODB_URI: ${MONGODB_URI} MONGODB_URI: ${MONGODB_URI}
PORT: ${PAYLOAD_PORT} PORT: ${PAYLOAD_PORT}
NODE_ENV: ${NODE_ENV}
PAYLOAD_SECRET: ${PAYLOAD_SECRET} PAYLOAD_SECRET: ${PAYLOAD_SECRET}
mongo: mongo:
image: mongo:6.0.5 image: mongo:6.0.5
@ -23,5 +24,3 @@ services:
environment: environment:
MONGO_INITDB_ROOT_USERNAME: ${MONGODB_USER} MONGO_INITDB_ROOT_USERNAME: ${MONGODB_USER}
MONGO_INITDB_ROOT_PASSWORD: ${MONGODB_PW} MONGO_INITDB_ROOT_PASSWORD: ${MONGODB_PW}
ports:
- 27017:27017

27
payload/Dockerfile Normal file
View File

@ -0,0 +1,27 @@
FROM node:lts-alpine as base
WORKDIR /base
COPY ./package.json ./package.json
RUN yarn install
COPY ./ ./
FROM base AS dev
ENV NODE_ENV=development
EXPOSE 3001
CMD ["yarn","dev"]
FROM base AS build
ENV NODE_ENV=production
WORKDIR /build
COPY --from=base /base ./
RUN yarn build
FROM build as prod
ENV NODE_ENV=production
WORKDIR /prod
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"]

View File

@ -1,4 +1,4 @@
{ {
"ext": "ts", "ext": "ts",
"exec": "ts-node src/server.ts" "exec": "yarn generate:types && ts-node src/server.ts"
} }

View File

@ -1,62 +1,62 @@
import { CollectionConfig } from 'payload/types'; import { CollectionConfig } from "payload/types";
const Posts: CollectionConfig = { const Posts: CollectionConfig = {
slug: 'posts', slug: "posts",
admin: { admin: {
defaultColumns: ['title', 'author', 'category', 'tags', 'status'], defaultColumns: ["title", "author", "category", "tags", "status"],
useAsTitle: 'title', useAsTitle: "title",
}, },
access: { access: {
read: () => true, read: () => true,
}, },
fields: [ fields: [
{ {
name: 'title', name: "title",
type: 'text', type: "text",
}, },
{ {
name: 'author', name: "author",
type: 'relationship', type: "relationship",
relationTo: 'users', relationTo: "users",
}, },
{ {
name: 'publishedDate', name: "publishedDate",
type: 'date', type: "date",
}, },
{ {
name: 'category', name: "category",
type: 'relationship', type: "relationship",
relationTo: 'categories' relationTo: "categories",
}, },
{ {
name: 'tags', name: "tags",
type: 'relationship', type: "relationship",
relationTo: 'tags', relationTo: "tags",
hasMany: true, hasMany: true,
}, },
{ {
name: 'content', name: "content",
type: 'richText' type: "richText",
}, },
{ {
name: 'status', name: "status",
type: 'select', type: "select",
options: [ options: [
{ {
value: 'draft', value: "draft",
label: 'Draft', label: "Draft",
}, },
{ {
value: 'published', value: "published",
label: 'Published', label: "Published",
}, },
], ],
defaultValue: 'draft', defaultValue: "draft",
admin: { admin: {
position: 'sidebar', position: "sidebar",
} },
} },
], ],
} };
export default Posts; export default Posts;

View File

@ -12,6 +12,6 @@ export default buildConfig({
}, },
collections: [Categories, Posts, Tags, Users], collections: [Categories, Posts, Tags, Users],
typescript: { typescript: {
outputFile: path.resolve("../", "types.ts"), outputFile: path.resolve("/", "types.ts"),
}, },
}); });

1
src/env.d.ts vendored Normal file
View File

@ -0,0 +1 @@
/// <reference types="astro/client" />