From 0dfad4431f5c8c69939519b76d1bb0c327d05802 Mon Sep 17 00:00:00 2001 From: Max Schmidt Date: Sat, 13 May 2023 19:10:37 +0200 Subject: [PATCH] UFF Signed-off-by: Max Schmidt --- .env | 5 --- .env.development | 7 ++++ astro/Dockerfile | 21 +++++++++++ astro/package.json | 9 ++--- astro/src/pages/index.astro | 10 ++++-- types.ts => astro/src/types.ts | 0 deno.json | 7 ++++ docker-compose-dev.yml | 24 +++++++++++++ docker-compose.yml | 11 +++--- payload/Dockerfile | 27 ++++++++++++++ payload/nodemon.json | 2 +- payload/src/collections/Posts.ts | 62 ++++++++++++++++---------------- payload/src/payload.config.ts | 2 +- src/env.d.ts | 1 + 14 files changed, 136 insertions(+), 52 deletions(-) delete mode 100644 .env create mode 100644 .env.development create mode 100644 astro/Dockerfile rename types.ts => astro/src/types.ts (100%) mode change 100644 => 100755 create mode 100644 deno.json create mode 100644 docker-compose-dev.yml create mode 100644 payload/Dockerfile create mode 100644 src/env.d.ts diff --git a/.env b/.env deleted file mode 100644 index d5c32d5..0000000 --- a/.env +++ /dev/null @@ -1,5 +0,0 @@ -MONGODB_URI=mongodb://payload:test@localhost:27017/payload -PAYLOAD_SECRET=supersecretkey -MONGODB_USER=payload -MONGODB_PW=test -MONGODB_DB=payload \ No newline at end of file diff --git a/.env.development b/.env.development new file mode 100644 index 0000000..4d7bd2e --- /dev/null +++ b/.env.development @@ -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 \ No newline at end of file diff --git a/astro/Dockerfile b/astro/Dockerfile new file mode 100644 index 0000000..592bbd8 --- /dev/null +++ b/astro/Dockerfile @@ -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 \ No newline at end of file diff --git a/astro/package.json b/astro/package.json index 85ecf1e..238fd82 100644 --- a/astro/package.json +++ b/astro/package.json @@ -3,13 +3,10 @@ "type": "module", "version": "0.0.1", "scripts": { - "dev": "astro dev", - "start": "astro dev", - "build": "astro build", - "preview": "astro preview", - "astro": "astro" + "dev": "astro dev --host", + "build": "astro build" }, "dependencies": { "astro": "^2.4.1" } -} \ No newline at end of file +} diff --git a/astro/src/pages/index.astro b/astro/src/pages/index.astro index fcd4a0c..4cb5121 100644 --- a/astro/src/pages/index.astro +++ b/astro/src/pages/index.astro @@ -1,14 +1,20 @@ --- import Layout from '../layouts/Layout.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.reverse().map(post => ( +
+

{post.title}

+

{post.updatedAt}

+
+ ))}

Welcome to Astro

To get started, open the directory src/pages in your project.
diff --git a/types.ts b/astro/src/types.ts old mode 100644 new mode 100755 similarity index 100% rename from types.ts rename to astro/src/types.ts diff --git a/deno.json b/deno.json new file mode 100644 index 0000000..13a0e5a --- /dev/null +++ b/deno.json @@ -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" + } +} diff --git a/docker-compose-dev.yml b/docker-compose-dev.yml new file mode 100644 index 0000000..da7c9ed --- /dev/null +++ b/docker-compose-dev.yml @@ -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 diff --git a/docker-compose.yml b/docker-compose.yml index fffd45a..b1dbf79 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,9 +1,11 @@ services: astro: - build: - context: ./astro - dockerfile: Dockerfile + container_name: ${NAME}-astro + restart: unless-stopped + payload: + container_name: ${NAME}_cms + restart: unless-stopped build: context: ./payload dockerfile: Dockerfile @@ -12,7 +14,6 @@ services: environment: MONGODB_URI: ${MONGODB_URI} PORT: ${PAYLOAD_PORT} - NODE_ENV: ${NODE_ENV} PAYLOAD_SECRET: ${PAYLOAD_SECRET} mongo: image: mongo:6.0.5 @@ -23,5 +24,3 @@ services: environment: MONGO_INITDB_ROOT_USERNAME: ${MONGODB_USER} MONGO_INITDB_ROOT_PASSWORD: ${MONGODB_PW} - ports: - - 27017:27017 diff --git a/payload/Dockerfile b/payload/Dockerfile new file mode 100644 index 0000000..b090a28 --- /dev/null +++ b/payload/Dockerfile @@ -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"] \ No newline at end of file diff --git a/payload/nodemon.json b/payload/nodemon.json index ed1a185..1e04413 100644 --- a/payload/nodemon.json +++ b/payload/nodemon.json @@ -1,4 +1,4 @@ { "ext": "ts", - "exec": "ts-node src/server.ts" + "exec": "yarn generate:types && ts-node src/server.ts" } diff --git a/payload/src/collections/Posts.ts b/payload/src/collections/Posts.ts index faf0ff5..373872c 100644 --- a/payload/src/collections/Posts.ts +++ b/payload/src/collections/Posts.ts @@ -1,62 +1,62 @@ -import { CollectionConfig } from 'payload/types'; +import { CollectionConfig } from "payload/types"; const Posts: CollectionConfig = { - slug: 'posts', + slug: "posts", admin: { - defaultColumns: ['title', 'author', 'category', 'tags', 'status'], - useAsTitle: 'title', + defaultColumns: ["title", "author", "category", "tags", "status"], + useAsTitle: "title", }, access: { read: () => true, }, fields: [ { - name: 'title', - type: 'text', + name: "title", + type: "text", }, { - name: 'author', - type: 'relationship', - relationTo: 'users', + name: "author", + type: "relationship", + relationTo: "users", }, { - name: 'publishedDate', - type: 'date', + name: "publishedDate", + type: "date", }, { - name: 'category', - type: 'relationship', - relationTo: 'categories' + name: "category", + type: "relationship", + relationTo: "categories", }, { - name: 'tags', - type: 'relationship', - relationTo: 'tags', + name: "tags", + type: "relationship", + relationTo: "tags", hasMany: true, }, { - name: 'content', - type: 'richText' + name: "content", + type: "richText", }, { - name: 'status', - type: 'select', + name: "status", + type: "select", options: [ { - value: 'draft', - label: 'Draft', + value: "draft", + label: "Draft", }, { - value: 'published', - label: 'Published', + value: "published", + label: "Published", }, ], - defaultValue: 'draft', + defaultValue: "draft", admin: { - position: 'sidebar', - } - } + position: "sidebar", + }, + }, ], -} +}; -export default Posts; \ No newline at end of file +export default Posts; diff --git a/payload/src/payload.config.ts b/payload/src/payload.config.ts index 8417be0..2b0afa6 100644 --- a/payload/src/payload.config.ts +++ b/payload/src/payload.config.ts @@ -12,6 +12,6 @@ export default buildConfig({ }, collections: [Categories, Posts, Tags, Users], typescript: { - outputFile: path.resolve("../", "types.ts"), + outputFile: path.resolve("/", "types.ts"), }, }); diff --git a/src/env.d.ts b/src/env.d.ts new file mode 100644 index 0000000..8c34fb4 --- /dev/null +++ b/src/env.d.ts @@ -0,0 +1 @@ +/// \ No newline at end of file