Skip to content

Commit

Permalink
Merge branch 'main' into configuration-checking
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesread authored Sep 10, 2024
2 parents db472df + 39ecf5c commit 5e9dfa0
Show file tree
Hide file tree
Showing 47 changed files with 1,189 additions and 513 deletions.
14 changes: 14 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"name": "Postiz Dev Container",
"image": "localhost/postiz-devcontainer",
"features": {},
"customizations": {
"vscode": {
"settings": {},
"extensions": []
}
},
"forwardPorts": ["4200:4200", "3000:3000"],
"mounts": ["source=/apps,destination=/apps/dist/,type=bind,consistency=cached"]
}

13 changes: 13 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# We want the docker builds to be clean, and as fast as possible. Don't send
# any half-built stuff in the build context as a pre-caution (also saves copying
# 180k files in node_modules that isn't used!).
**/node_modules
dist
.nx
.devcontainer
**/.git
**/dist
**/*.md
**/LICENSE
**/npm-debug.log
**/*.vscode
43 changes: 43 additions & 0 deletions .github/workflows/build-containers.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
---
name: "Build Containers"

on:
workflow_dispatch:
push:
tags:
- '*'

jobs:
build-containers:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Login to ghcr
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ github.token }}

- name: docker build
run: ./var/docker/docker-build.sh

- name: Get date
run: |
echo "DATE=$(date +'%s')" >> "$GITHUB_ENV"
- name: Print post-build debug info
run: |
docker images
- name: docker tag
run: |
docker tag localhost/postiz ghcr.io/gitroomhq/postiz-app:${{ env.DATE }}
docker push ghcr.io/gitroomhq/postiz-app:${{ env.DATE }}
docker tag localhost/postiz-devcontainer ghcr.io/gitroomhq/postiz-devcontainer:${{ env.DATE }}
docker push ghcr.io/gitroomhq/postiz-devcontainer:${{ env.DATE }}
52 changes: 52 additions & 0 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
---
name: Build

on:
push:
branches:
- main
paths:
- package.json
- apps/**
- '!apps/docs/**'
- libraries/**

pull_request:
paths:
- package.json
- apps/**
- '!apps/docs/**'
- libraries/**

jobs:
build:
runs-on: ubuntu-latest

strategy:
matrix:
node-version: ['20.17.0']
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/

steps:
- uses: actions/checkout@v4
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
cache: 'npm'
cache-dependency-path: |
**/package-lock.json
# https://nextjs.org/docs/pages/building-your-application/deploying/ci-build-caching#github-actions
- uses: actions/cache@v4
with:
path: |
~/.npm
${{ github.workspace }}/.next/cache
key: ${{ runner.os }}-nextjs-${{ hashFiles('**/package-lock.json') }}-${{ hashFiles('**/*.js', '**/*.jsx', '**/*.ts', '**/*.tsx') }}
restore-keys: |
${{ runner.os }}-nextjs-${{ hashFiles('**/package-lock.json') }}-
- run: npm ci
- run: npm run build
47 changes: 47 additions & 0 deletions .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
---
name: "Code Quality Analysis"

on:
push:
branches:
- main
paths:
- apps/**
- '!apps/docs/**'
- libraries/**

pull_request:
paths:
- apps/**
- '!apps/docs/**'
- libraries/**

jobs:
analyze:
name: Analyze (${{ matrix.language }})

runs-on: 'ubuntu-latest'
permissions:
security-events: write

strategy:
fail-fast: false
matrix:
include:
- language: javascript-typescript
build-mode: none

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Initialize CodeQL
uses: github/codeql-action/init@v3
with:
languages: ${{ matrix.language }}
build-mode: ${{ matrix.build-mode }}

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v3
with:
category: "/language:${{matrix.language}}"
60 changes: 60 additions & 0 deletions .github/workflows/eslint.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
---
name: ESLint

on:
push:
branches:
- main
paths:
- package.json
- apps/**
- '!apps/docs/**'
- libraries/**

pull_request:
paths:
- package.json
- apps/**
- '!apps/docs/**'
- libraries/**

jobs:
eslint:
name: Run eslint scanning
runs-on: ubuntu-latest
permissions:
contents: read
security-events: write
actions: read # only required for a private repository by github/codeql-action/upload-sarif to get the Action run status
strategy:
matrix:
service: ["backend", "frontend"]
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Setup node
uses: actions/setup-node@v4
with:
node-version: '20'
cache: 'npm'
cache-dependency-path: |
**/package-lock.json
- name: Install ESLint
run: |
npm install eslint
npm install @microsoft/[email protected]
- name: Run ESLint
run: npx eslint apps/${{ matrix.service }}/
--config apps/${{ matrix.service }}/.eslintrc.json
--format @microsoft/eslint-formatter-sarif
--output-file apps/${{ matrix.service }}/eslint-results.sarif
continue-on-error: true

- name: Upload analysis results to GitHub
uses: github/codeql-action/upload-sarif@v3
with:
sarif_file: apps/${{ matrix.service }}/eslint-results.sarif
wait-for-processing: true
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,7 @@ Thumbs.db

# Next.js
.next

# Vim files
**/*.swp
**/*.swo
58 changes: 58 additions & 0 deletions Dockerfile.dev
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# This Dockerfile is used for producing 3 container images.
#
# base - which is thrown away, that contains node and the basic infrastructure.
# devcontainer - which is used for development, and contains the source code and the node_modules.
# dist - which is used for production, and contains the built source code and the node_modules.

ARG NODE_VERSION="20.17"

# Base image
FROM docker.io/node:${NODE_VERSION}-alpine3.19 AS base

## Just reduce unccessary noise in the logs.
ENV NPM_CONFIG_UPDATE_NOTIFIER=false
ENV NEXT_TELEMETRY_DISABLED=1

RUN apk add --no-cache \
bash=5.2.21-r0 \
supervisor=4.2.5-r4 \
make \
build-base

WORKDIR /app

EXPOSE 4200
EXPOSE 3000

COPY var/docker/entrypoint.sh /app/entrypoint.sh
COPY var/docker/supervisord.conf /etc/supervisord.conf
COPY var/docker/supervisord /app/supervisord_available_configs/
COPY .env.example /config/.env

VOLUME /config

LABEL org.opencontainers.image.source=https://github.com/gitroomhq/postiz-app

ENTRYPOINT ["/app/entrypoint.sh"]

# Builder image
FROM base AS devcontainer

COPY nx.json tsconfig.base.json package.json package-lock.json /app/
COPY apps /app/apps/
COPY libraries /app/libraries/

RUN npm ci --no-fund && npx nx run-many --target=build --projects=frontend,backend,workers,cron

LABEL org.opencontainers.image.title="Postiz App (DevContainer)"

# Output image
FROM base AS dist

COPY --from=devcontainer /app/node_modules/ /app/node_modules/
COPY --from=devcontainer /app/dist/ /app/dist/

COPY package.json nx.json /app/

## Labels at the bottom, because CI will eventually add dates, commit hashes, etc.
LABEL org.opencontainers.image.title="Postiz App (Production)"
15 changes: 7 additions & 8 deletions apps/backend/src/api/routes/posts.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,19 +48,18 @@ export class PostsController {
@GetOrgFromRequest() org: Organization,
@Query() query: GetPostsDto
) {
const [posts, comments] = await Promise.all([
const [posts] = await Promise.all([
this._postsService.getPosts(org.id, query),
this._commentsService.getAllCommentsByWeekYear(
org.id,
query.year,
query.week,
query.isIsoWeek === 'true'
),
// this._commentsService.getAllCommentsByWeekYear(
// org.id,
// query.year,
// query.week
// ),
]);

return {
posts,
comments,
// comments,
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,4 +169,4 @@ You can look at the other integration to understand what data to put inside.
And add the new provider to the list.
```typescript show.all.providers.tsx
{identifier: 'providerName', component: DefaultImportFromHighOrderProvider},
```
```
14 changes: 8 additions & 6 deletions apps/docs/emails.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,16 @@ title: Email Notifications
description: How to send notifications to users
---

At the moment we are using Resend to send email notifications to users, and might be changed the Novu later.
Postiz uses Resend to send email notifications to users. Emails are currently
required as part of the new-user creation process, which sends an activation
email.

Register to [Resend](https://resend.com) connect your domain.
Copy your API Key.
Head over to .env file and add the following line.
* Register to [Resend](https://resend.com), and connect your domain.
* Copy your API Key from the Resend control panel.
* Open the .env file and edit the following line.

```env
RESEND_API_KEY=""
RESEND_API_KEY="<your-api-key-here>"
```

Feel free to contribute other providers to send email notifications.
Feel free to contribute other providers to send email notifications.
12 changes: 6 additions & 6 deletions apps/docs/howitworks.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ Unlike other NX project, this project has one `.env` file that is shared between
It makes it easier to develop and deploy the project.<br /><br />
When deploying to websites like [Railway](https://railway.app) or [Heroku](https://heroku.com), you can use a shared environment variables for all the apps.<br /><br />

**At the moment it has 6 project:**
**At the moment it has 6 projects:**

- **Backend** - NestJS based system
- **Workers** - NestJS based workers connected to a Redis Queue.
- **Cron** - NestJS scheduler to run cron jobs.
- **Frontend** - NextJS based control panel.
- **Docs** - Mintlify based documentation website.
- [Frontend](#frontend) - Provides the Web user interface, talks to the Backend.
- [Backend](#backend) - Does all the real work, provides an API for the frontend, and posts work to the redis queue.
- [Workers](#worker) - Consumes work from the Redis Queue.
- [Cron](#cron) - Run jobs at scheduled times.
- [Docs](#docs) - This documentation site!

<img
src="/images/arch.png"
Expand Down
Loading

0 comments on commit 5e9dfa0

Please sign in to comment.