Browse Source

change to alpine image and reduce node_modules size

pull/431/head
Valentin Zickner 4 years ago
committed by Thomas
parent
commit
0f472873be
  1. 34
      Dockerfile
  2. 10
      README.md
  3. 1
      angular.json
  4. 2
      docker/docker-compose-build-local.yml
  5. 3
      package.json
  6. 4
      prisma/seed.js

34
Dockerfile

@ -1,13 +1,14 @@
FROM node:14 as builder
WORKDIR /app
FROM node:14-alpine as builder
# build application and add additional files
WORKDIR /ghostfolio
# only add basic files without application itself to avoid rebuilding layers when package.json, etc. did not change
COPY ./package.json package.json
COPY ./yarn.lock yarn.lock
COPY ./prisma/schema.prisma prisma/schema.prisma
RUN yarn
# see https://github.com/nrwl/nx/issues/6586 for further details
COPY ./decorate-angular-cli.js decorate-angular-cli.js
RUN node decorate-angular-cli.js
@ -22,14 +23,21 @@ COPY ./apps apps
RUN yarn build:all
COPY ./prisma/seed.ts prisma/seed.ts
# Prepare dist image with additional node_modules
WORKDIR /ghostfolio/dist/apps/api
# package.json was generated by build process, however the yarn.lock need to be used from the original to ensure same versions
COPY ./yarn.lock /ghostfolio/dist/apps/api/yarn.lock
RUN yarn
COPY prisma /ghostfolio/dist/apps/api/prisma
# Overwrite generated package.json with original to ensure we have all the scripts
COPY package.json /ghostfolio/dist/apps/api
RUN yarn database:generate-typings
FROM node:14
COPY --from=builder /app/dist/apps /app/apps
COPY --from=builder /app/package.json /app/package.json
# todo: change build to ensure that node_modules folder isn't required to reduce image size
COPY --from=builder /app/node_modules /app/node_modules
COPY --from=builder /app/prisma /app/prisma
WORKDIR /app
# Image to start, copy everything needed from builder
FROM node:14-alpine
COPY --from=builder /ghostfolio/dist/apps /ghostfolio/apps
WORKDIR /ghostfolio/apps/api
EXPOSE 3333
CMD [ "npm", "run", "start:prod" ]
CMD [ "node", "main" ]

10
README.md

@ -92,15 +92,18 @@ The frontend is built with [Angular](https://angular.io) and uses [Angular Mater
To run it with docker you can simply execute:
```bash
docker-compose -f docker/docker-compose-all.yml build
docker-compose -f docker/docker-compose-all.yml up
docker-compose -f docker/docker-compose-build-local.yml build
docker-compose -f docker/docker-compose-build-local.yml up
```
This will build a docker image of ghostfolio locally on your machine and start it up, including dependencies and the database.
### Initialize the Database
To initialize the database, you can run the following command once ghostfolio is started:
```bash
docker-compose -f docker/docker-compose-all.yml exec ghostfolio yarn setup:database
docker-compose -f docker/docker-compose-build-local.yml exec ghostfolio yarn setup:database
```
After this, go to http://localhost:3333/ and follow those steps:
@ -109,7 +112,6 @@ After this, go to http://localhost:3333/ and follow those steps:
1. Go to the _Admin Control Panel_ and click _Gather All Data_ to fetch historical data
1. Click _Sign out_ and check out the _Live Demo_
## Development
### Prerequisites

1
angular.json

@ -35,6 +35,7 @@
},
"configurations": {
"production": {
"generatePackageJson": true,
"optimization": true,
"extractLicenses": true,
"inspect": false,

2
docker/docker-compose-all.yml → docker/docker-compose-build-local.yml

@ -15,7 +15,7 @@ services:
env_file:
- ../.env
environment:
REDIS_HOST: "redis"
REDIS_HOST: 'redis'
DATABASE_URL: postgresql://user:password@postgres:5432/ghostfolio-db?sslmode=prefer
ports:
- 3333:3333

3
package.json

@ -175,5 +175,8 @@
"parser": "typescript",
"style": "module"
}
},
"prisma": {
"seed": "node prisma/seed.js"
}
}

4
prisma/seed.ts → prisma/seed.js

@ -1,10 +1,10 @@
import {
const {
AccountType,
DataSource,
PrismaClient,
Role,
Type
} from '@prisma/client';
} = require('@prisma/client');
const prisma = new PrismaClient();
async function main() {
Loading…
Cancel
Save