feat: support admin account creation for gotrue image (#1036)

This commit is contained in:
Khor Shu Heng 2024-12-03 17:15:27 +08:00 committed by GitHub
parent a827016117
commit 522791ee6d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 30 additions and 6 deletions

View File

@ -7,13 +7,14 @@ RUN git apply mfa_enabled.patch
RUN CGO_ENABLED=0 go build -o /auth .
RUN rm /go/src/supabase/auth/migrations/20240612123726_enable_rls_update_grants.up.sql
FROM scratch
COPY --from=base /usr/share/zoneinfo /usr/share/zoneinfo
COPY --from=base /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
COPY --from=base /etc/passwd /etc/passwd
COPY --from=base /etc/group /etc/group
FROM alpine:3.20
RUN adduser -D -u 1000 supabase
RUN apk add --no-cache ca-certificates
USER supabase
COPY --from=base /auth .
COPY --from=base /go/src/supabase/auth/migrations ./migrations
CMD ["./auth"]
COPY start.sh .
CMD ["./start.sh"]

23
docker/gotrue/start.sh Executable file
View File

@ -0,0 +1,23 @@
#!/usr/bin/env sh
set -e
./auth migrate
if [ -n "${GOTRUE_ADMIN_EMAIL}" ] && [ -n "${GOTRUE_ADMIN_PASSWORD}" ]; then
set +e
echo "Creating admin user for gotrue..."
command_output=$(./auth admin createuser --admin "${GOTRUE_ADMIN_EMAIL}" "${GOTRUE_ADMIN_PASSWORD}" 2>&1)
command_status=$?
# Check if the command failed
if [ $command_status -ne 0 ]; then
# Check if the output contains the specific keyword
if echo "$command_output" | grep -q "user already exists"; then
echo "Admin user already exists. Skipping..."
else
echo "Command failed. Exiting."
echo $command_output
exit $command_status
fi
fi
fi
set -e
./auth