diff --git a/Dockerfile b/Dockerfile index 9fed99e..d0b543f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -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"] diff --git a/docker-compose.yml b/docker-compose.yml index 5efe181..3669dd8 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -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 @@ -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 diff --git a/lib/app/models/user/user.model.dart b/lib/app/models/user/user.model.dart index 32ba4d8..998e88f 100644 --- a/lib/app/models/user/user.model.dart +++ b/lib/app/models/user/user.model.dart @@ -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 get hidden => []; + + @Column() + String? name; + + @Column() + String? email; + + @Column() + String? password; + + @Column() + String? deletedAt; } diff --git a/lib/app/models/user/user.model.g.dart b/lib/app/models/user/user.model.g.dart index a601a91..7426a52 100644 --- a/lib/app/models/user/user.model.g.dart +++ b/lib/app/models/user/user.model.g.dart @@ -8,7 +8,7 @@ part of 'user.model.dart'; // ignore_for_file: always_specify_types -class UserGenerator extends Model { +class UserGenerator extends Model with SoftDeletes { @override String get primaryKey => 'id'; @@ -25,7 +25,15 @@ class UserGenerator extends Model { User query() => User(); @override - List get tableColumns => ['id', 'created_at', 'updated_at']; + List get tableColumns => [ + 'id', + 'name', + 'email', + 'password', + 'deleted_at', + 'created_at', + 'updated_at' + ]; @override List get preloadList => []; @@ -39,6 +47,10 @@ class UserGenerator extends Model { @override User fromMap(Map m) => User() ..id = m['id'] as int? + ..name = m['name'] as String? + ..email = m['email'] as String? + ..password = m['password'] as String? + ..deletedAt = m['deleted_at'] as String? ..createdAt = m['created_at'] == null ? null : DateTime.parse(m['created_at'] as String) @@ -51,6 +63,10 @@ class UserGenerator extends Model { User instance = i as User; Map map = { 'id': instance.id, + 'name': instance.name, + 'email': instance.email, + 'password': instance.password, + 'deleted_at': instance.deletedAt, 'created_at': instance.createdAt?.toIso8601String(), 'updated_at': instance.updatedAt?.toIso8601String(), };