Skip to content

Commit

Permalink
update docker to run on both production and development (#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
necessarylion authored Dec 30, 2023
1 parent d0f32c2 commit 0760f24
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 22 deletions.
22 changes: 12 additions & 10 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,23 +1,25 @@
# Use latest stable channel SDK.
FROM dart:stable AS build
FROM dart:stable AS base

# Resolve app dependencies.
WORKDIR /app
COPY pubspec.* ./
RUN dart pub get

# Copy app source code (except anything in .dockerignore) and AOT compile app.
COPY . .

# build for production
RUN dart run build_runner build --delete-conflicting-outputs
RUN dart compile exe bin/server.dart -o bin/server

FROM base as development
RUN dart pub global activate dox
CMD ["dox", "s"]

# Build minimal serving image from AOT-compiled `/server`
# and the pre-built AOT-runtime in the `/runtime/` directory of the base image.
FROM scratch
COPY --from=build /runtime/ /
COPY --from=build /app/.env /
COPY --from=build /app/bin/server /bin/
COPY --from=build /app/db/migration /db/migration

# Start server.
FROM scratch as production
COPY --from=base /runtime/ /
COPY --from=base /app/.env /
COPY --from=base /app/bin/server /bin/
COPY --from=base /app/db/migration /db/migration
CMD ["/bin/server"]
25 changes: 16 additions & 9 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,15 @@ services:

# Http server
dox:
build: .
hostname: dox
build:
context: .
target: ${APP_ENV}
working_dir: /app
volumes:
- ./:/app
- /app/.dart_tool
ports:
# export:internal
- "3001:3000"
- "${APP_PORT}:${APP_PORT}"
depends_on:
postgres:
condition: service_healthy
Expand All @@ -17,13 +21,16 @@ services:
postgres:
image: postgres:14.1
environment:
- POSTGRES_USER=postgres
- POSTGRES_PASSWORD=postgres
- POSTGRES_DB=postgres
- POSTGRES_USER=${DB_USERNAME}
- POSTGRES_PASSWORD=${DB_PASSWORD}
- POSTGRES_DB=${DB_NAME}
expose:
- ${DB_PORT}
ports:
- "3002:5432"
- "${DB_PORT}:${DB_PORT}"
command: -p ${DB_PORT}
restart: always
healthcheck:
test: ['CMD', 'pg_isready', '-q', '-U', 'postgres']
test: ['CMD', 'pg_isready', '-q', '-U', 'postgres', '-p', '${DB_PORT}']
interval: 5s
retries: 5
14 changes: 13 additions & 1 deletion lib/app/models/user/user.model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,20 @@ import 'package:dox_query_builder/dox_query_builder.dart';

part 'user.model.g.dart';

@DoxModel()
@DoxModel(softDelete: true)
class User extends UserGenerator {
@override
List<String> get hidden => <String>[];

@Column()
String? name;

@Column()
String? email;

@Column()
String? password;

@Column()
String? deletedAt;
}
20 changes: 18 additions & 2 deletions lib/app/models/user/user.model.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 0760f24

Please sign in to comment.