Compare commits

9 Commits

Author SHA1 Message Date
747ada89e9 Update ssg and editor access functions
All checks were successful
continuous-integration/drone/push Build is passing
2024-05-20 11:41:41 +02:00
ff564a62ec Add author collection 2024-05-20 11:40:57 +02:00
9629c93ceb Merge branch 'main' into t-work 2024-05-20 09:43:08 +02:00
3wc
3aa5ec6a69 Dependency experiment
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone Build is passing
2024-05-20 01:17:29 -03:00
3wc
db712ecffc Add missing drone dep
All checks were successful
continuous-integration/drone/push Build is passing
2024-05-20 01:14:39 -03:00
3wc
e1a782ad39 Fix YAML syntax
Some checks failed
continuous-integration/drone/push Build is failing
2024-05-20 01:11:19 -03:00
3wc
b8b10670f9 Astro build on code changes
Some checks reported errors
continuous-integration/drone/push Build encountered an error
2024-05-20 01:08:42 -03:00
3wc
b83ce8c97a Fix YAML syntax error
All checks were successful
continuous-integration/drone/push Build is passing
2024-05-19 19:19:41 -03:00
3wc
0a7b0e98b2 README and .drone.yml updates
Some checks reported errors
continuous-integration/drone/push Build encountered an error
Re autonomic-cooperative/astro-payload-template#3
2024-05-19 19:17:59 -03:00
9 changed files with 132 additions and 56 deletions

View File

@ -4,7 +4,7 @@ name: publish pipeline
steps: steps:
- name: publish astro container - name: publish astro container
image: plugins/docker image: plugins/docker
settings: settings: &docker-build-settings
username: 3wordchant username: 3wordchant
password: password:
from_secret: git_autonomic_zone_token_3wc from_secret: git_autonomic_zone_token_3wc
@ -14,32 +14,35 @@ steps:
registry: git.autonomic.zone registry: git.autonomic.zone
context: astro context: astro
dockerfile: astro/Dockerfile dockerfile: astro/Dockerfile
trigger: &exclude-event-custom
branch:
- main
event:
exclude:
- custom
- name: publish payload dev container - name: publish payload dev container
image: plugins/docker image: plugins/docker
settings: settings: &payload-build-settings
username: 3wordchant <<: *docker-build-settings
password:
from_secret: git_autonomic_zone_token_3wc
# NOTE: edit this if you want your image called something else # NOTE: edit this if you want your image called something else
repo: git.autonomic.zone/autonomic-cooperative/astro-payload-test-payload-dev repo: git.autonomic.zone/autonomic-cooperative/astro-payload-test-payload-dev
auto_tag: true
registry: git.autonomic.zone
context: payload context: payload
dockerfile: payload/Dockerfile dockerfile: payload/Dockerfile
target: dev target: dev
trigger:
<< *exclude-event-custom
- name: publish payload prod container - name: publish payload prod container
image: plugins/docker image: plugins/docker
settings: settings:
<<: *payload-build-settings
username: 3wordchant username: 3wordchant
password:
from_secret: git_autonomic_zone_token_3wc
# NOTE: edit this if you want your image called something else
repo: git.autonomic.zone/autonomic-cooperative/astro-payload-test-payload repo: git.autonomic.zone/autonomic-cooperative/astro-payload-test-payload
auto_tag: true
registry: git.autonomic.zone
context: payload
dockerfile: payload/Dockerfile
target: prod target: prod
trigger:
<< *exclude-event-custom
- name: deploy stack - name: deploy stack
image: git.coopcloud.tech/coop-cloud/stack-ssh-deploy:latest image: git.coopcloud.tech/coop-cloud/stack-ssh-deploy:latest
settings: settings:
@ -61,16 +64,8 @@ steps:
depends_on: depends_on:
- publish payload prod container - publish payload prod container
trigger: trigger:
branch: << *exclude-event-custom
- main
event:
exclude:
- custom
---
kind: pipeline
name: build astro
steps:
- name: build astro content - name: build astro content
image: git.autonomic.zone/autonomic-cooperative/astro-payload-test-astro:latest image: git.autonomic.zone/autonomic-cooperative/astro-payload-test-astro:latest
environment: environment:
@ -79,6 +74,9 @@ steps:
- cd astro - cd astro
- mv /base/node_modules . - mv /base/node_modules .
- yarn build - yarn build
depends_on:
- deploy stack
- name: copy built content to stack - name: copy built content to stack
image: git.coopcloud.tech/coop-cloud/docker-cp-deploy:latest image: git.coopcloud.tech/coop-cloud/docker-cp-deploy:latest
settings: settings:
@ -90,7 +88,5 @@ steps:
dest: /usr/share/nginx/html/ dest: /usr/share/nginx/html/
deploy_key: deploy_key:
from_secret: drone_ssh_swarm-demo.autonomic.zone from_secret: drone_ssh_swarm-demo.autonomic.zone
depends_on:
trigger: - build astro content
event:
- custom

View File

@ -1,4 +1,16 @@
# How to use this template # Paystro
Paystro is a pre-configured setup for Astro and Payloadcms, designed to make it easy for you to start building your website. With Paystro, you'll have a complete development environment that you can run locally using Docker. This setup simplifies the testing and development of your website before deploying it to a production environment.
## Architecture
Paystro is a fork of [Astroad](https://github.com/mooxl/astroad).
Unlike Astroad where the "Astro" image is the built static site served with Nginx Paystro's Astro image is a builder image.
In Paystro, the Docker stack just contains Payload and a generic Nginx container.
## How to use this template
1. Create a new Gitea repository based on this template repo (choose at least 1. Create a new Gitea repository based on this template repo (choose at least
"git content") "git content")
@ -11,24 +23,30 @@ To set up deployment:
including adding an SSH key as an organisational secret for the organisation including adding an SSH key as an organisational secret for the organisation
this project is in (see [Autonomic internal this project is in (see [Autonomic internal
docs](https://docz.autonomic.zone/doc/setting-up-auto-deployment-using-drone-I4j2onjaKT)) docs](https://docz.autonomic.zone/doc/setting-up-auto-deployment-using-drone-I4j2onjaKT))
2. Edit `.drone.yml` to define the server to host on, and the 2. Edit `.drone.yml` to set variables:
`STACK_NAME` / `DOMAIN` of the deployed app. - `HOST`: hostname or IP address of the server to deploy to (e.g.
3. Generate secrets (`openssl rand -hex 32` works well) for `PAYLOAD_SECRET` and `vps.example.tld`)
- `DOMAIN`: domain name of the live site (e.g. `site.example.tld`)
- `STACK_NAME`: the Docker stack name, usually `$DOMAIN` with dots replaced
with underscores (e.g. `site_example_tld`)
- `DRONE_URL`: root URL for the Drone instance (e.g.
`https://drone.example.tld`)
3. Make sure that DNS records for `$DOMAIN` and `admin.$DOMAIN`, pointing to
`$HOST`, are defined.
4. Generate secrets (`openssl rand -hex 32` works well) for `PAYLOAD_SECRET` and
`MONGO_PASSWORD`. Insert the personal user token for a Drone bot user (e.g. `MONGO_PASSWORD`. Insert the personal user token for a Drone bot user (e.g.
`autono-bot`) as `TOKEN`). For all of them, use something like `echo "foobar" `autono-bot`) as `TOKEN`). For all of them, use something like `echo "foobar"
| docker secret create paystro_swarm-demo_autonomic_zone_token_v1 -`, where | docker secret create paystro_swarm-demo_autonomic_zone_token_v1 -`, where
`paystro_swarm-demo_autonomic_zone` is the `STACK_NAME`. `paystro_swarm-demo_autonomic_zone` is the `STACK_NAME`.
4. Activate the repo in Drone 5. Activate the repo in Drone
# Paystro ---
Paystro is a pre-configured setup for Astro and Payloadcms, designed to make it easy for you to start building your website. With Paystro, you'll have a complete development environment that you can run locally using Docker. This setup simplifies the testing and development of your website before deploying it to a production environment. # ${REPO_NAME}
Paystro is a fork of [Astroad](https://github.com/mooxl/astroad).
## Prerequisites ## Prerequisites
Before getting started with Paystro, make sure you have Docker installed (and, if your Docker doesn't include `docker compose`, the separate `docker-compose` tool). Before getting started, make sure you have Docker installed (and, if your Docker doesn't include `docker compose`, the separate `docker-compose` tool).
## Configuration ## Configuration
@ -44,8 +62,4 @@ The `docker-compose.yml` file includes everything you need to run the containers
Whenever the repository is updated, Drone builds new Docker images for Payload and Astro, and deploys a new Docker Swarm stack to the `HOST` configured in `.drone.yml`. Whenever the repository is updated, Drone builds new Docker images for Payload and Astro, and deploys a new Docker Swarm stack to the `HOST` configured in `.drone.yml`.
Unlike Astroad where the "Astro" image is the built static site served with Nginx Paystro's Astro image is a builder image. Whenever changes are made to Payload content on the live site, Drone uses the Astro builder image to regenerate the static site, and publish it to the Nginx container by copying it into the Docker volume.
In Paystro, the Docker stack just contains Payload and a generic Nginx container.
Whenever changes are made to Payload content, Drone uses the Astro builder image to regenerate the static site, and publish it to the Nginx container by copying it into the Docker volume.

View File

@ -3,10 +3,10 @@ import { User } from "../payload-types";
export const isEditor: Access<any, User> = ({ req: { user } }) => { export const isEditor: Access<any, User> = ({ req: { user } }) => {
// Return true or false based on if the user has an editor role // Return true or false based on if the user has an editor role
return Boolean(user?.roles?.includes('editor', 'admin')); return Boolean(user?.roles?.some(role => ['user', 'editor', 'admin'].includes(role)));
} }
export const isEditorFieldLevel: FieldAccess<{ id: string }, unknown, User> = ({ req: { user } }) => { export const isEditorFieldLevel: FieldAccess<{ id: string }, unknown, User> = ({ req: { user } }) => {
// Return true or false based on if the user has an editor role // Return true or false based on if the user has an editor role
return Boolean(user?.roles?.includes('editor', 'admin')); return Boolean(user?.roles?.some(role => ['user', 'editor', 'admin'].includes(role)));
} }

View File

@ -0,0 +1,12 @@
import { Access, FieldAccess } from "payload/types";
import { User } from "../payload-types";
export const isSSG: Access<any, User> = ({ req: { user } }) => {
// Return true or false based on if the user has an ssg or admin role
return Boolean(user?.roles?.some(role => ['ssg', 'admin'].includes(role)));
}
export const isSSGFieldLevel: FieldAccess<{ id: string }, unknown, User> = ({ req: { user } }) => {
// Return true or false based on if the user has an ssg or admin role
return Boolean(user?.roles?.some(role => ['ssg', 'admin'].includes(role)));
}

View File

@ -0,0 +1,13 @@
import { Access, FieldAccess } from "payload/types";
import { User } from "../payload-types";
export const isUser: Access<any, User> = ({ req: { user } }) => {
// Return true or false based on if the user has an ssg or admin role
return Boolean(user?.roles?.some(role => ['user', 'editor', 'admin'].includes(role)));
}
export const isUserFieldLevel: FieldAccess<{ id: string }, unknown, User> = ({ req: { user } }) => {
// Return true or false based on if the user has an ssg or admin role
return Boolean(user?.roles?.some(role => ['user', 'editor', 'admin'].includes(role)));
}

View File

@ -0,0 +1,44 @@
import { CollectionConfig } from "payload/types";
import { isAdmin } from "@/access/isAdmin";
import { isEditor } from "@/access/isEditor";
import { isSSG } from "@/access/isSSG";
import { isUser } from "@/access/isUser";
import { isEditorOrSelf } from "@/access/isEditorOrSelf";
const Authors: CollectionConfig = {
slug: "authors",
admin: {
defaultColumns: ["avatar","name"],
useAsTitle: "name",
},
access: {
//TODO: Author can CRUD own post
create: isUser,
read: () => true,
update: isEditor,
delete: isEditor,
},
fields: [
{
name: "name",
type: "text",
required: true
},
{
name: "avatar",
type: "upload",
relationTo: "media",
required: false,
},
{
name: "user",
type: "relationship",
relationTo: "users",
admin: {
description: 'The selected user will be able to edit this author'
},
}
],
};
export default Authors;

View File

@ -2,6 +2,7 @@ import { CollectionConfig } from "payload/types";
import { isAdmin } from "@/access/isAdmin"; import { isAdmin } from "@/access/isAdmin";
import { isEditor } from "@/access/isEditor"; import { isEditor } from "@/access/isEditor";
import { isSSG } from "@/access/isSSG"; import { isSSG } from "@/access/isSSG";
import { isUser } from "@/access/isUser";
const Posts: CollectionConfig = { const Posts: CollectionConfig = {
slug: "posts", slug: "posts",
@ -12,7 +13,7 @@ const Posts: CollectionConfig = {
}, },
access: { access: {
//TODO: Author can CRUD own post //TODO: Author can CRUD own post
create: isEditor, create: isUser,
read: () => true, read: () => true,
update: isEditor, update: isEditor,
delete: isEditor, delete: isEditor,
@ -89,12 +90,11 @@ const Posts: CollectionConfig = {
}, },
}, },
{ {
name: "author", name: "authors",
//TODO: Add active user as default //TODO: Add active user as default
type: 'relationship', type: 'relationship',
relationTo: 'users', relationTo: 'authors',
hasMany: false, hasMany: true,
required: false,
admin: { admin: {
position: "sidebar", position: "sidebar",
}, },

View File

@ -35,10 +35,6 @@ const Users: CollectionConfig = {
update: isAdminFieldLevel, update: isAdminFieldLevel,
}, },
}, },
{
name: 'name',
type: 'text',
}
], ],
}; };

View File

@ -2,6 +2,7 @@ import { buildConfig } from "payload/config";
import path from "path"; import path from "path";
import Posts from "@/collections/Posts"; import Posts from "@/collections/Posts";
import Users from "@/collections/Users"; import Users from "@/collections/Users";
import Authors from "./collections/Authors";
import Media from "@/collections/Media"; import Media from "@/collections/Media";
export default buildConfig({ export default buildConfig({
@ -19,7 +20,7 @@ export default buildConfig({
}, },
}), }),
}, },
collections: [Posts, Users, Media], collections: [Posts, Users, Authors, Media],
typescript: { typescript: {
outputFile: path.resolve("/", "types.ts"), outputFile: path.resolve("/", "types.ts"),
}, },