Compare commits

..

30 Commits

Author SHA1 Message Date
tobias
2e372d1aae Makefile: sync_media
All checks were successful
continuous-integration/drone/push Build is passing
2024-07-16 15:34:24 +02:00
tobias
1496eefc14 Makefile: restore mongodb 2024-07-16 13:53:19 +02:00
tobias
e93b5e653a Copy mongodump directly from container 2024-07-16 13:01:41 +02:00
tobias
8fa28a31ce Make command for dumping mongodb 2024-07-16 11:55:55 +02:00
tobias
64da6f4553 Restart nextjs container in prod
All checks were successful
continuous-integration/drone/push Build is passing
2024-07-13 17:26:48 +02:00
tobias
5e74f45855 Always restart
Some checks failed
continuous-integration/drone/push Build is failing
2024-07-13 15:39:31 +02:00
tobias
ab8b409725 Bump combo x2
Some checks failed
continuous-integration/drone/push Build is failing
2024-07-11 21:40:18 +02:00
tobias
35ac1ece0e Fix uploads volume path in the correct file this time
All checks were successful
continuous-integration/drone/push Build is passing
2024-07-11 21:35:24 +02:00
tobias
b8a92095d8 Bump
All checks were successful
continuous-integration/drone/push Build is passing
2024-07-11 21:26:16 +02:00
tobias
9ce6eb5bcc Correct upload path for docker volume
All checks were successful
continuous-integration/drone/push Build is passing
2024-07-11 21:21:18 +02:00
tobias
ee243f7d20 Don't fetch user on preview pages
All checks were successful
continuous-integration/drone/push Build is passing
2024-07-11 21:06:38 +02:00
tobias
9edb207991 Clean up preview pages
Some checks failed
continuous-integration/drone/push Build is failing
2024-07-11 21:04:47 +02:00
tobias
e060d942f0 Fix payload_uploads volume?
All checks were successful
continuous-integration/drone/push Build is passing
2024-07-11 21:00:30 +02:00
tobias
c09862c702 Don't check null user on preview pages
All checks were successful
continuous-integration/drone/push Build is passing
2024-07-11 20:29:31 +02:00
tobias
fdfbce506e Revert "Remove baseURL from preview url"
All checks were successful
continuous-integration/drone/push Build is passing
This reverts commit f16e874f31.
2024-07-06 22:19:52 +02:00
tobias
f16e874f31 Remove baseURL from preview url
All checks were successful
continuous-integration/drone/push Build is passing
2024-07-06 22:11:46 +02:00
tobias
8d05864c15 Only check roles if a user when accessing pages
All checks were successful
continuous-integration/drone/push Build is passing
2024-07-06 19:57:55 +02:00
tobias
90f1750945 Deny access if no roles
All checks were successful
continuous-integration/drone/push Build is passing
2024-07-06 19:49:50 +02:00
tobias
abe4a3c883 Revert "Temporarily turn off access controls"
This reverts commit 519df326ce.
2024-07-06 19:34:47 +02:00
tobias
519df326ce Temporarily turn off access controls
All checks were successful
continuous-integration/drone/push Build is passing
2024-07-06 19:11:38 +02:00
tobias
3d4499fb80 Create new admin user
All checks were successful
continuous-integration/drone/push Build is passing
2024-07-05 23:26:50 +02:00
tobias
a27c335113 Catch non-arrays
All checks were successful
continuous-integration/drone/push Build is passing
2024-07-05 22:42:32 +02:00
tobias
199234a7e2 Remove misbehaving test route
All checks were successful
continuous-integration/drone/push Build is passing
2024-07-05 22:34:09 +02:00
tobias
95a00c63ea Disable code obfuscation
All checks were successful
continuous-integration/drone/push Build is passing
2024-07-05 22:24:10 +02:00
3wc
8a85724baf Revert bogus change to CMD syntax
All checks were successful
continuous-integration/drone/push Build is passing
2024-07-05 16:13:32 -04:00
tobias
b25a83b164 Revert "Copy entrypoint"
All checks were successful
continuous-integration/drone/push Build is passing
This reverts commit 83ea63dde4.
2024-07-05 22:04:30 +02:00
3wc
23357f0934 Align image names
Some checks failed
continuous-integration/drone/push Build is failing
2024-07-05 16:02:31 -04:00
tobias
83ea63dde4 Copy entrypoint
Some checks failed
continuous-integration/drone/push Build is failing
2024-07-05 21:59:17 +02:00
3wc
efd4be35f7 Attempt to fix CMD syntax
All checks were successful
continuous-integration/drone/push Build is passing
2024-07-05 15:53:47 -04:00
tobias
b6e56b0f83 chmod +x docker-entrypoint
All checks were successful
continuous-integration/drone/push Build is passing
2024-07-05 21:47:22 +02:00
14 changed files with 104 additions and 49 deletions

View File

@ -12,7 +12,7 @@ steps:
auto_tag: true
registry: git.autonomic.zone
dockerfile: ./Dockerfile
repo: git.autonomic.zone/autonomic-cooperative/nextjs
repo: git.autonomic.zone/autonomic-cooperative/nextload
- name: deploy stack
image: git.coopcloud.tech/coop-cloud/stack-ssh-deploy:latest
@ -29,4 +29,4 @@ steps:
SECRET_MONGO_PASSWORD_VERSION: v1
REPOSITORY: "autonomic-cooperative/nextload"
depends_on:
- publish nextjs container
- publish nextjs container

View File

@ -44,5 +44,6 @@ ENV PNPM_HOME="/pnpm"
ENV PATH="$PNPM_HOME:$PATH"
RUN corepack enable
COPY docker-entrypoint.sh /docker-entrypoint.sh
RUN chmod +x /docker-entrypoint.sh
ENTRYPOINT ["/docker-entrypoint.sh"]
CMD ["pnpm", "start:standalone"]

49
Makefile Normal file
View File

@ -0,0 +1,49 @@
.PHONY: sync_db
# Define variables
REMOTE_USER=tma
REMOTE_SERVER=swarm-demo.autonomic.zone
REMOTE_PORT=222
REMOTE_CONTAINER_PATH=/data/db/mongodump
LOCAL_PATH=/tmp/mongodump
LOCAL_DB=test
LOCAL_CONTAINER_NAME=nextload-mongo-1
REMOTE_VOLUME_NAME = nextload-demo_autonomic_zone_payload_uploads
LOCAL_VOLUME_NAME = nextload_payload_uploads
ENV_FILE=.env
include $(ENV_FILE)
sync_db:
@echo "Step 1: Dump the database on production"
docker --context swarm-demo.autonomic.zone exec -it $$(docker --context swarm-demo.autonomic.zone ps -q -f name=nextload-demo_autonomic_zone_mongo) \
bash -c 'rm -rf $(REMOTE_CONTAINER_PATH) && mongodump -u mongo -p "$$(cat /run/secrets/mongo_password)" -o $(REMOTE_CONTAINER_PATH) && ls -l $(REMOTE_CONTAINER_PATH)'
@echo "Step 2: Copy the dump from the remote MongoDB container to the local machine"
rm -rf $(LOCAL_PATH)
mkdir -p $(LOCAL_PATH) # Create the target directory if it doesn't exist
ssh -p $(REMOTE_PORT) $(REMOTE_USER)@$(REMOTE_SERVER) \
"docker exec $$(docker --context swarm-demo.autonomic.zone ps -q -f name=nextload-demo_autonomic_zone_mongo) \
tar -cC $(REMOTE_CONTAINER_PATH) ." | tar -xC $(LOCAL_PATH)
@echo "Step 3: Copy the dump from local machine to MongoDB container"
docker cp $(LOCAL_PATH)/ $(LOCAL_CONTAINER_NAME):/tmp/mongodump
@echo "Step 4: Drop the existing local database and restore the dump"
docker exec -it $(LOCAL_CONTAINER_NAME) mongorestore --drop --username $(MONGO_USER) --password $(MONGO_PASSWORD) --authenticationDatabase admin --db $(LOCAL_DB) /tmp/mongodump/$(LOCAL_DB)
sync_media:
@echo "Step 1: Create a tar archive of the remote Docker volume"
rm -rf /tmp/$(REMOTE_VOLUME_NAME)
mkdir -p /tmp/$(REMOTE_VOLUME_NAME)
ssh -p $(REMOTE_PORT) $(REMOTE_USER)@$(REMOTE_SERVER) \
"docker run --rm -v $(REMOTE_VOLUME_NAME):/volume -v /tmp:/backup alpine tar -czf /backup/$(REMOTE_VOLUME_NAME).tar.gz -C /volume ."
@echo "Step 2: Copy the media from remote volume to local volume"
scp -P $(REMOTE_PORT) $(REMOTE_USER)@$(REMOTE_SERVER):/tmp/$(REMOTE_VOLUME_NAME).tar.gz /tmp/$(REMOTE_VOLUME_NAME).tar.gz
docker run --rm -v /tmp:/volume -v $(LOCAL_VOLUME_NAME):/backup alpine tar -xzf /volume/$(REMOTE_VOLUME_NAME).tar.gz -C /backup
@echo "Step 3: Cleanup temporary files"
rm /tmp/$(REMOTE_VOLUME_NAME).tar.gz
@echo "Media synchronization complete."

View File

@ -40,4 +40,4 @@ You'll see that Payload requires a few files to be present in your `/app` folder
You'll see in the Next.js config that we have a `withPayload` function installed. This function is required for Payload to operate, and it ensures compatibility with packages that Payload needs such as `drizzle-kit`, `sharp`, `pino`, and `mongodb`.
**Using a TypeScript alias to point to your Payload config**
In the `tsconfig.json` within this repo, you'll see that we have `paths` set up to point `@payload-config` to the Payload config, which is located in the root. You can put your config wherever you want. By default, the `page.tsx` files and `route.ts` files within the `/app` folder use this alias. In the future, we might make it optional to use `paths` - and by default, we might just hard-code relative path imports to the config. We would like to hear your feedback on this part. What do you prefer? Use `paths` or just use relative imports?
In the `tsconfig.json` within this repo, you'll see that we have `paths` set up to point `@payload-config` to the Payload config, which is located in the root. You can put your config wherever you want. By default, the `page.tsx` files and `route.ts` files within the `/app` folder use this alias. In the future, we might make it optional to use `paths` - and by default, we might just hard-code relative path imports to the config. We would like to hear your feedback on this part. What do you prefer? Use `paths` or just use relative imports?

View File

@ -4,6 +4,7 @@ version: "3.8"
services:
nextjs:
image: git.autonomic.zone/autonomic-cooperative/nextload:latest
restart: unless-stopped
environment:
- "NAME=${STACK_NAME}"
- "PAYLOAD_SECRET_FILE=/run/secrets/payload_secret"
@ -19,7 +20,7 @@ services:
- mongo_password
- payload_secret
volumes:
- payload_uploads:/runner/.next/standalone/.next/media
- payload_uploads:/prod/.next/standalone/media
networks:
- proxy
- internal

View File

@ -18,7 +18,7 @@ services:
- "HOSTNAME=0.0.0.0"
- "MONGODB_URI=mongodb://${MONGO_USER}:${MONGO_PASSWORD}@mongo:27017"
volumes:
- /base/media
- payload_uploads:/base/media
- ./:/base
networks:
- internal

View File

@ -11,7 +11,7 @@ const nextConfig = {
HOSTNAME: process.env.HOSTNAME,
},
// Disable minification & chunking for debugging
/* webpack(config, { dev }) {
webpack(config, { dev }) {
config.optimization.minimize = false
config.optimization.splitChunks = {
cacheGroups: {
@ -20,7 +20,7 @@ const nextConfig = {
}
config.optimization.runtimeChunk = false
return config
}, */
},
}
export default withPayload(nextConfig)

View File

@ -37,7 +37,7 @@ export default buildConfig({
collections: [Users, Posts, Authors, Media, Pages],
admin: {
autoLogin: {
email: 'dev@payloadcms.com',
email: 'admin@nextload.test',
password: 'test',
prefillOnly: true,
},
@ -60,14 +60,14 @@ export default buildConfig({
async onInit(payload) {
const existingUsers = await payload.find({
collection: 'users',
limit: 1,
limit: 2,
})
if (existingUsers.docs.length === 0) {
if (existingUsers.docs.length === 0 || existingUsers.docs.length === 1) {
await payload.create({
collection: 'users',
data: {
email: 'dev@payloadcms.com',
email: 'admin@nextload.test',
password: 'test',
roles: ['admin'],
},

View File

@ -7,8 +7,7 @@ import { notFound } from 'next/navigation'
const PreviewCatchAllPage = async ({ params }: { params: { path: string[] } }) => {
noStore()
const [user, page] = await Promise.all([
getCurrentUser(),
const [page] = await Promise.all([
getDocument({
collection: COLLECTION_SLUG_PAGE,
path: params.path,
@ -16,7 +15,8 @@ const PreviewCatchAllPage = async ({ params }: { params: { path: string[] } }) =
cache: false,
}),
])
if (!user || !page) notFound()
if (!page) notFound()
return <PreviewBlocks initialData={page} locale="" url={process.env.BASE_URL || ''} />
}

View File

@ -8,8 +8,7 @@ import PreviewPostPage from '@/components/PreviewPostPage'
const PreviewCatchAllPage = async ({ params }: { params: { path: string[] } }) => {
noStore()
const [user, page] = await Promise.all([
getCurrentUser(),
const [page] = await Promise.all([
getDocument({
collection: COLLECTION_SLUG_POST,
path: params.path,
@ -17,7 +16,7 @@ const PreviewCatchAllPage = async ({ params }: { params: { path: string[] } }) =
cache: false,
}),
])
if (!user || !page) notFound()
if (!page) notFound()
return <PreviewPostPage initialData={page} locale="" url={process.env.BASE_URL || ''} />
}

View File

@ -2,7 +2,11 @@ import { Access } from 'payload/types'
import type { User } from 'types/payload-types'
export const isAdmin = ({ req: { user } }: any) => {
if (user && user.roles?.includes('admin')) {
if (!user || !user.roles) {
return false
}
if (user.roles?.includes('admin')) {
return true
}
@ -10,7 +14,11 @@ export const isAdmin = ({ req: { user } }: any) => {
}
export const isAdminOrCreatedBy = ({ req: { user } }: any) => {
if (user && user.role === 'admin') {
if (!user || !user.roles) {
return false
}
if (user.roles?.includes('admin')) {
return true
}
@ -26,24 +34,27 @@ export const isAdminOrCreatedBy = ({ req: { user } }: any) => {
}
export const isAdminOrSelf = ({ req: { user } }: any) => {
if (user) {
if (user.roles?.includes('admin')) {
return true
}
// Non-admin: can only access themselves
return {
id: {
equals: user.id,
},
}
if (!user || !user.roles) {
return false
}
if (user.roles?.includes('admin')) {
return true
}
// Non-admin: can only access themselves
return {
id: {
equals: user.id,
},
}
return false
}
export const isAdminOrPublished = ({ req: { user } }: any) => {
if (user && user?.role === 'admin') {
return true
if (user && user.roles) {
if (user.roles?.includes('admin')) {
return true
}
}
return {

View File

@ -2,7 +2,11 @@ import { Access, FieldAccess } from 'payload/types'
import type { User } from 'types/payload-types'
export const isEditor = ({ req: { user } }: any) => {
if (user && user?.roles?.some((role: string) => ['editor', 'admin'].includes(role))) {
if (!user || !user.roles) {
return false
}
if (user?.roles?.some((role: string) => ['editor', 'admin'].includes(role))) {
return true
}

View File

@ -2,7 +2,11 @@ import { Access, FieldAccess } from 'payload/types'
import type { User } from 'types/payload-types'
export const isUser = ({ req: { user } }: any) => {
if (user && user?.roles?.some((role: string) => ['user', 'editor', 'admin'].includes(role))) {
if (!user || !user.roles) {
return false
}
if (user?.roles?.some((role: string) => ['user', 'editor', 'admin'].includes(role))) {
return true
}

View File

@ -1,14 +0,0 @@
import { getPayloadHMR } from '@payloadcms/next/utilities'
import configPromise from '@payload-config'
export const GET = async () => {
const payload = await getPayloadHMR({
config: configPromise,
})
const data = await payload.find({
collection: 'users',
})
return Response.json(data)
}