From c69307039d254091f59eeb7a01abfe3d00eeea06 Mon Sep 17 00:00:00 2001 From: Zai Shi Date: Sun, 15 Dec 2024 01:21:18 +0100 Subject: [PATCH] Added run docker github actions (#369) --- .github/workflows/docker-build.yaml | 1 - .github/workflows/docker-test.yaml | 43 +++++++++++++++++++++++ apps/backend/prisma/seed.ts | 20 ++++++++++- docs/fern/docs/pages/others/self-host.mdx | 23 ++++++++---- 4 files changed, 78 insertions(+), 9 deletions(-) create mode 100644 .github/workflows/docker-test.yaml diff --git a/.github/workflows/docker-build.yaml b/.github/workflows/docker-build.yaml index 541d8d5c8..1dc95827f 100644 --- a/.github/workflows/docker-build.yaml +++ b/.github/workflows/docker-build.yaml @@ -5,7 +5,6 @@ on: branches: - main - dev - - docker-build tags: - "*.*.*" pull_request: diff --git a/.github/workflows/docker-test.yaml b/.github/workflows/docker-test.yaml new file mode 100644 index 000000000..fdc5cf867 --- /dev/null +++ b/.github/workflows/docker-test.yaml @@ -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 diff --git a/apps/backend/prisma/seed.ts b/apps/backend/prisma/seed.ts index 37f0c31da..55526ff0a 100644 --- a/apps/backend/prisma/seed.ts +++ b/apps/backend/prisma/seed.ts @@ -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}`); } } diff --git a/docs/fern/docs/pages/others/self-host.mdx b/docs/fern/docs/pages/others/self-host.mdx index 02e415646..b18528cc7 100644 --- a/docs/fern/docs/pages/others/self-host.mdx +++ b/docs/fern/docs/pages/others/self-host.mdx @@ -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 -p 8101:8101 -p 8102:8102 stackauth/server:latest + ``` + + + For M1 Mac users, you might need to add `--platform linux/x86_64` to the `docker run` command. + + + 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. + Now you can open the dashboard at [http://localhost:8101](http://localhost:8101) and the API backend on port 8102.