Added run docker github actions (#369)
Some checks failed
Ensure Prisma migrations are in sync with the schema / check_prisma_migrations (22.x) (push) Has been cancelled
Docker Build and Push / Docker Build and Push Server (push) Has been cancelled
Docker Test / docker (push) Has been cancelled
Runs E2E API Tests / build (20.x) (push) Has been cancelled
Lint & build / lint_and_build (20.x) (push) Has been cancelled
Lint & build / lint_and_build (22.x) (push) Has been cancelled
TOC Generator / TOC Generator (push) Has been cancelled

This commit is contained in:
Zai Shi 2024-12-15 01:21:18 +01:00 committed by GitHub
parent eae6bc34d8
commit c69307039d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 78 additions and 9 deletions

View File

@ -5,7 +5,6 @@ on:
branches:
- main
- dev
- docker-build
tags:
- "*.*.*"
pull_request:

43
.github/workflows/docker-test.yaml vendored Normal file
View File

@ -0,0 +1,43 @@
name: Docker Test
on:
push:
branches:
- dev
- main
pull_request:
branches:
- dev
- main
jobs:
docker:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Setup postgres
run: |
docker run -d --name db -e POSTGRES_USER=postgres -e POSTGRES_PASSWORD=password -e POSTGRES_DB=stackframe -p 5432:5432 postgres:latest
sleep 5
docker logs db
- name: Build Docker image
run: docker build -f docker/server/Dockerfile -t server .
- name: Run Docker container and check logs
run: |
docker run --add-host=host.docker.internal:host-gateway --env-file docker/server/.env.example -p 8101:8101 -p 8102:8102 -d --name stackframe-server server
sleep 10
docker logs stackframe-server
- name: Check server health
run: |
echo "Attempting to connect to server..."
curl -v http://localhost:8101
response_code=$(curl -s -o /dev/null -w "%{http_code}" http://localhost:8101)
echo "Response code: $response_code"
if [ $response_code -ne 200 ]; then
echo "Server health check failed with status code: $response_code"
exit 1
fi

View File

@ -152,6 +152,7 @@ async function seed() {
// Create optional default admin user if credentials are provided.
// This user will be able to login to the dashboard with both email/password and magic link.
if ((adminEmail && adminPassword) || adminGithubId) {
await prisma.$transaction(async (tx) => {
const oldAdminUser = await tx.projectUser.findFirst({
@ -162,7 +163,7 @@ async function seed() {
});
if (oldAdminUser) {
console.log(`User with email ${adminEmail} already exists, skipping creation`);
console.log(`Admin user already exists, skipping creation`);
} else {
const newUser = await tx.projectUser.create({
data: {
@ -239,6 +240,23 @@ async function seed() {
}
});
await tx.authMethod.create({
data: {
projectId: 'internal',
projectConfigId: (internalProject as any).configId,
projectUserId: newUser.projectUserId,
authMethodConfigId: githubConfig.authMethodConfigId || throwErr('GitHub OAuth provider config not found'),
oauthAuthMethod: {
create: {
projectUserId: newUser.projectUserId,
oauthProviderConfigId: 'github',
providerAccountId: adminGithubId,
projectConfigId: (internalProject as any).configId,
}
}
}
});
console.log(`Added admin user with GitHub ID ${adminGithubId}`);
}
}

View File

@ -30,15 +30,24 @@ On a high level, Stack Auth is composed of the following services:
Stack Auth provides a pre-configured Docker image that bundles the dashboard and API backend into a single container. To complete the setup, you'll need to provide your own PostgreSQL database, and optionally configure an email server and Svix instance for webhooks.
First, you need to get the [example environment file](https://github.com/stack-auth/stack/tree/main/docker/server/.env.example) and modify it to your needs. See the [full template here](https://github.com/stack-auth/stack/blob/dev/docker/server/.env).
1. Use a cloud hosted Postgres or start a example Postgres database. Don't use this setting in production:
```sh
docker run -d --name db -e POSTGRES_USER=postgres -e POSTGRES_PASSWORD=password -e POSTGRES_DB=stackframe -p 5432:5432 postgres:latest
```
```sh
# Start a example Postgres database, don't use this setting in production
docker run -d --name db -e POSTGRES_USER=postgres -e POSTGRES_PASSWORD=password -e POSTGRES_DB=stackframe -p 5432:5432 postgres:latest
2. Get the [example environment file](https://github.com/stack-auth/stack/tree/main/docker/server/.env.example) and modify it to your needs. See the [full template here](https://github.com/stack-auth/stack/blob/dev/docker/server/.env).
# Run the Docker container
docker run --env-file your-env-file.env -p 8101:8101 -p 8102:8102 stackauth/server:latest
```
3. Run the Docker container:
```sh
docker run --env-file <your-env-file.env> -p 8101:8101 -p 8102:8102 stackauth/server:latest
```
<Info>
For M1 Mac users, you might need to add `--platform linux/x86_64` to the `docker run` command.
</Info>
<Info>
For Linux users, you might need to add `--add-host=host.docker.internal:host-gateway` to the `docker run` command in order to connect to the local Postgres database.
</Info>
Now you can open the dashboard at [http://localhost:8101](http://localhost:8101) and the API backend on port 8102.