Skip to content

Commit 40470de

Browse files
authored
Merge pull request #2 from sredevopsorg/multi-steps
2 parents a7dcee6 + 7a5d674 commit 40470de

File tree

4 files changed

+101
-10
lines changed

4 files changed

+101
-10
lines changed

.github/copilot-instructions.md

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
# AI Coding Agent Instructions for ActivityPub Repository
2+
3+
## Overview
4+
This repository implements a multitenant ActivityPub server for [Ghost](https://ghost.org/), enabling independent websites to publish content directly to the Fediverse. It is built using [Fedify](https://fedify.dev/) and integrates with various Google Cloud services for production deployment.
5+
6+
## Key Components
7+
- **`/src`**: Core application code, organized by domain (e.g., `account`, `post`, `notification`).
8+
- **`/features`**: Cucumber feature files for end-to-end testing.
9+
- **`/jobs`**: Scripts for one-off production tasks.
10+
- **`/migrate`**: Database migration scripts and tools.
11+
- **`/dev`**: Development utilities, including Docker configurations and local emulators.
12+
13+
## Development Workflows
14+
### Setup
15+
- Install dependencies: `yarn install`
16+
- Start the development environment: `yarn dev`
17+
- Fix environment issues: `yarn fix`
18+
19+
### Testing
20+
- Run all tests: `yarn test`
21+
- Run unit tests: `yarn test:unit`
22+
- Run integration tests: `yarn test:integration`
23+
- Run end-to-end tests: `yarn test:cucumber`
24+
- Run a specific test: `yarn test:single path/to/test`
25+
26+
### Database
27+
- Create a migration: `yarn migration 'migration-name'`
28+
- Apply migrations: `yarn migrate`
29+
- Wipe the database: `yarn wipe-db`
30+
31+
## Architectural Patterns
32+
- **Dependency Injection**: Managed via [Awilix](https://github.com/jeffijoe/awilix) for testability.
33+
- **Result Pattern**: Prefer returning results over throwing exceptions.
34+
- **Layered Design**:
35+
- **Entities**: Contain business logic.
36+
- **Repositories**: Abstract database operations; accessed only via services.
37+
- **Services**: Orchestrate business logic and may depend on other services.
38+
- **Controllers**: Handle HTTP requests and delegate to services.
39+
- **Views**: Optimize data presentation for clients; may directly query the database but avoid business logic.
40+
41+
## Code Conventions
42+
- **Testing**:
43+
- Unit and integration test files use `.test.ts` suffix.
44+
- Co-locate tests with the code they validate.
45+
- End-to-end tests reside in `features/`.
46+
- **Linting and Formatting**:
47+
- Run linter: `yarn lint`
48+
- Run formatter: `yarn fmt`
49+
- **Performance**:
50+
- Minimize synchronous operations during application boot to optimize for Google Cloud Run.
51+
52+
## External Dependencies
53+
- **Google Cloud Services**:
54+
- Cloud Run: Production deployment.
55+
- Cloud SQL: Managed MySQL database.
56+
- Pub/Sub: Messaging.
57+
- Cloud Storage: File storage.
58+
- **Local Emulators**:
59+
- Pub/Sub: Port `8085`.
60+
- Cloud Storage: Port `4443`.
61+
- **Other Tools**:
62+
- [Tailscale](https://tailscale.com): Expose local development environment.
63+
- [Wiremock](https://wiremock.org): API mocking for end-to-end tests.
64+
65+
## Common Practices
66+
- Follow the outlined architecture and testing patterns.
67+
- Ensure new functionality is well-tested, lint-free, and adheres to conventions.
68+
- Optimize for fast test execution (<10 seconds per test).
69+
70+
## Known Quirks
71+
- Tests run in Docker containers, so additional flags passed to `yarn` may not propagate to the test runner.
72+
73+
---
74+
75+
For more details, refer to `AGENTS.md` or the `README.md` file.

.github/workflows/build-activitypub.yaml

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
# This workflow builds a multi-arch Docker image using GitHub Actions and separated Github Runners with native support for ARM64 and AMD64 architectures, without using QEMU emulation.
22
# It uses Docker Buildx to build and push the image to GitHub Container Registry (GHCR).
3-
name: Build multi arch Docker Image with separate Github Runners
3+
name: Build multi arch ActivityPub Docker Image with separate Github Runners
44

55
on:
66
workflow_dispatch:
77
push:
88
branches:
99
- main
10-
paths:
11-
- 'Dockerfile'
12-
- '.github/workflows/multi-build.yaml'
10+
tags:
11+
- 'v*'
12+
paths-ignore:
13+
- 'migrate/**'
1314
env:
1415
# The name of the Docker image to be built and pushed to GHCR
1516
# The image name is derived from the GitHub repository name and the GitHub Container Registry (GHCR) URL.
@@ -213,6 +214,7 @@ jobs:
213214
tags: |
214215
type=raw,value=main,enable=${{ github.ref_name == 'main' }}
215216
type=raw,value=latest,enable=${{ github.ref_name == 'main' }}
217+
type=ref,event=tag,enable=${{ startsWith(github.ref, 'refs/tags/v') }},format={{ ref_name }}
216218
217219
- name: Set up Docker Buildx
218220
uses: docker/setup-buildx-action@e468171a9de216ec08956ac3ada2f0791b6bd435 # v3.11.1

.github/workflows/build-migrations.yaml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
# This workflow builds a multi-arch Docker image using GitHub Actions and separated Github Runners with native support for ARM64 and AMD64 architectures, without using QEMU emulation.
22
# It uses Docker Buildx to build and push the image to GitHub Container Registry (GHCR).
3-
name: Build multi arch Docker Image with separate Github Runners
3+
name: Build multi arch ActivityPub Migrations Docker Image with separate Github Runners
44

55
on:
66
workflow_dispatch:
77
push:
88
branches:
99
- main
10+
tags:
11+
- 'v*'
1012
paths:
1113
- 'migrate/**'
1214
env:
@@ -213,6 +215,7 @@ jobs:
213215
tags: |
214216
type=raw,value=main,enable=${{ github.ref_name == 'main' }}
215217
type=raw,value=latest,enable=${{ github.ref_name == 'main' }}
218+
type=ref,event=tag,enable=${{ startsWith(github.ref, 'refs/tags/v') }},format={{ ref_name }}
216219
217220
- name: Set up Docker Buildx
218221
uses: docker/setup-buildx-action@e468171a9de216ec08956ac3ada2f0791b6bd435 # v3.11.1

Dockerfile

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
1-
FROM node:22.18.0-alpine@sha256:1b2479dd35a99687d6638f5976fd235e26c5b37e8122f786fcd5fe231d63de5b
1+
FROM node:jod-bookworm@sha256:6fe286835c595e53cdafc4889e9eff903dd3008a3050c1675809148d8e0df805 AS build-env
22

3-
RUN apk add python3 g++ make
4-
RUN apk add --no-cache ca-certificates
3+
# RUN apk add python3 g++ make
4+
# RUN apk add --no-cache ca-certificates
5+
6+
RUN apt update && apt install -y python3 g++ make
7+
RUN apt install -y ca-certificates
58

69
WORKDIR /opt/activitypub
710

@@ -19,8 +22,16 @@ COPY vitest.config.ts vitest.config.ts
1922
ENV NODE_ENV=production
2023
RUN yarn build
2124

22-
RUN apk del python3 g++ make
25+
# RUN apk del python3 g++ make
26+
27+
FROM gcr.io/distroless/nodejs22-debian12:latest@sha256:4c6848a24760c190338d20c3fd2e987431f8fe05c4067a114801cb66ca0018a1 AS runtime
28+
29+
WORKDIR /opt/activitypub
30+
31+
COPY --from=build-env /opt/activitypub .
32+
33+
ENV NODE_ENV=production
2334

2435
EXPOSE 8080
2536

26-
CMD ["node", "dist/app.js"]
37+
CMD ["dist/app.js"]

0 commit comments

Comments
 (0)