Compare commits

...

2 Commits

Author SHA1 Message Date
3wc
7f2710e9a2 Update README
All checks were successful
continuous-integration/drone/push Build is passing
Closes autonomic-cooperative/astro-payload-template#6
2024-05-18 18:29:52 -03:00
3wc
7d071a2672 Split DRONE_URL out into setting 2024-05-18 18:29:42 -03:00
3 changed files with 36 additions and 50 deletions

View File

@ -44,6 +44,7 @@ steps:
SECRET_MONGO_PASSWORD_VERSION: v1
NGINX_CONF_VERSION: v1
REPOSITORY: "autonomic-cooperative/astro-payload-test"
DRONE_URL: "https://drone.autonomic.zone"
PAYLOAD_URL: "https://admin.paystro.swarm-demo.autonomic.zone"
depends_on:
- publish payload container

View File

@ -1,66 +1,51 @@
# How to use this template
1. Create a new Gitea repository based on this template repo (choose at least
"git content"
2. Edit `.env.sample` to define the project name
3. Remove this notice (everything down to the `---`)
To set up deployment:
1. Make sure the server you want to deploy to is set up for Drone access,
including adding an SSH key as an organisational secret for the organisation
this project is in (see [Autonomic internal
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
`STACK_NAME` / `DOMAIN` of the deployed app.
3. 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.
`autono-bot`) as `TOKEN`). For all of them, use something like `echo "foobar"
| docker secret create paystro_swarm-demo_autonomic_zone_token_v1 -`, where
`paystro_swarm-demo_autonomic_zone` is the `STACK_NAME`.
4. 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.
Paystro is a fork of [Astroad](https://github.com/mooxl/astroad).
## Prerequisites
Before getting started with Paystro, make sure you have the necessary software installed:
- Docker
- Node.js
- Yarn
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).
## Configuration
While there's no configuration necessary for local development, deployment via Github Workflows requires specific secrets and variables to be set.
### Secrets:
- `USER`: User on the server
- `HOST`: IP or URL of the server
- `KEY`: SSH KEY for connecting to the server
- `MONGODB_PW`: Password for MongoDB
- `MONGODB_USER`: User for MongoDB
- `PATH`: Path where the repository resides on the server
- `PAYLOAD_PORT`: Port at which Payload listens
- `PAYLOAD_SECRET`: String to encrypt Payload data
- `TOKEN`: Github Access Token for the webhook to trigger the payload.yml workflow and execute a new Astro build
### Variables:
- `ASTRO_HOST`: Hostdomain of the Frontend
- `PAYLOAD_HOST`: Hostdomain of the CMS
- `PAYLOAD_URL`: URL of the CMS
- `NAME`: Name of the Container and Project
Please remember to set these secrets and variables in your repository settings to ensure a successful deployment through Github Workflows.
Once the secrets and variables are set on GitHub, they will replace the existing ones in the `.env` file on the server during deployment. This is done by the push.yml workflow, which replaces the placeholders in the `.env` with the actual secrets and variables defined in the repository settings. Please ensure that the names of your secrets and variables match with the placeholders in the `.env` file.
## Getting started
To get started with Paystro, you'll need to have Docker and NPM || Yarn || PNPM installed on your machine.
You have two options for getting the repository:
1. Use the 'Use this template' button on the Github repository. This will create a new repository in your Github account with the same directory structure and files as Paystro. After the new repository is created, you can clone it to your local machine.
1. Alternatively, you can directly clone the Paystro repository: git clone https://github.com/mooxl/paystro.git. If you choose this option, remember to change the origin of your remote repository to a new one to avoid pushing changes directly to the Paystro repository. This can be done with the command: git remote set-url origin https://github.com/USERNAME/REPOSITORY.git where USERNAME is your username and REPOSITORY is the name of your new repository.
Once you've cloned the repository or created your own from the template, follow these steps:
1. Change into the repository directory: `cd {newName}`
1. Start the containers: `yarn dev`
This will start up the Astro, Payloadcms and Mongo containers and make them available on your local machine. Astro will be served at http://localhost:3000 and the Payload will be available at http://localhost:3001.
Copy `.env.sample` to `.env` and edit as appropriate (e.g. to change the port for Payload).
## Development
The `docker-compose.yml` and `docker-compose-dev.yml` files includes everything you need to run the containers. The containers use the environment variables declared in the `.env` file and mounted volumes to store data persistently even after the containers are stopped and started.
Launch local containers using `yarn dev` or, if you don't have yarn installed, plain `docker-compose up` / `docker compose up`.
The `docker-compose.yml` file includes everything you need to run the containers. The containers use the environment variables declared in the `.env` file, and mounted volumes to store data persistently even after the containers are stopped and started.
## Deployment
Deployment is handled by a Github Actions Workflow on every push. It logs into the server via SSH, pulls or clones the latest version of the repository, and runs `yarn prod`.
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`.
Because Astro is completely static, a content change in the CMS must trigger a new build of Astro. Therefore, theres a `payload.yml` workflow that gets triggered by a webhook after every content change from Payload.
Unlike Astroad where the "Astro" image is the built static site served with Nginx Paystro's Astro image is a builder image.
Ensure you have Traefik set up as a reverse proxy before deployment. The prod script will launch your site in a production-ready environment.
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

@ -19,7 +19,7 @@ const Posts: CollectionConfig = {
process.env.NODE_ENV !== "development" &&
console.log(
await fetch(
`https://drone.autonomic.zone/api/repos/${process.env.REPOSITORY}/builds`,
`${process.env.DRONE_URL}api/repos/${process.env.REPOSITORY}/builds`,
{
method: "POST",
headers: {