From e7fb31d1a63a4b096f880dc8a1ee4095601d49d4 Mon Sep 17 00:00:00 2001 From: Valentin Zickner <3200232+vzickner@users.noreply.github.com> Date: Sat, 30 Oct 2021 12:54:14 -0400 Subject: [PATCH] add Dockerfile with all in one docker image (#431) * Add Dockerfile with all in one docker image * Change to alpine image and reduce node_modules size * Improve documentation and fix changelog and license * Update changelog Co-authored-by: Valentin Zickner Co-authored-by: Thomas <4159106+dtslvr@users.noreply.github.com> --- CHANGELOG.md | 6 +++ Dockerfile | 51 +++++++++++++++++++ README.md | 45 ++++++++++++---- angular.json | 5 +- .../src/app/pages/about/about-page.html | 4 +- docker/docker-compose-build-local.yml | 24 +++++++++ package.json | 3 ++ prisma/{seed.ts => seed.js} | 4 +- 8 files changed, 127 insertions(+), 15 deletions(-) create mode 100644 Dockerfile create mode 100644 docker/docker-compose-build-local.yml rename prisma/{seed.ts => seed.js} (99%) diff --git a/CHANGELOG.md b/CHANGELOG.md index 66848d6b9..932bbc802 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## Unreleased + +### Added + +- Added a `Dockerfile` and documentation to build a _Docker_ image + ## 1.66.0 - 30.10.2021 ### Changed diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 000000000..995102f2e --- /dev/null +++ b/Dockerfile @@ -0,0 +1,51 @@ +FROM node:14-alpine as builder + +# Build application and add additional files + +WORKDIR /ghostfolio + +# Only add basic files without the application itself to avoid rebuilding +# layers when files (package.json etc.) have not changed +COPY ./CHANGELOG.md CHANGELOG.md +COPY ./LICENSE LICENSE +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 + +COPY ./angular.json angular.json +COPY ./nx.json nx.json +COPY ./replace.build.js replace.build.js +COPY ./jest.preset.js jest.preset.js +COPY ./jest.config.js jest.config.js +COPY ./tsconfig.base.json tsconfig.base.json +COPY ./libs libs +COPY ./apps apps + +RUN yarn build:all + +# Prepare the dist image with additional node_modules +WORKDIR /ghostfolio/dist/apps/api +# package.json was generated by the build process, however the original +# yarn.lock needs to be used to ensure the same versions +COPY ./yarn.lock /ghostfolio/dist/apps/api/yarn.lock + +RUN yarn +COPY prisma /ghostfolio/dist/apps/api/prisma + +# Overwrite the generated package.json with the original one to ensure having +# all the scripts +COPY package.json /ghostfolio/dist/apps/api +RUN yarn database:generate-typings + +# Image to run, copy everything needed from builder +FROM node:14-alpine +COPY --from=builder /ghostfolio/dist/apps /ghostfolio/apps +WORKDIR /ghostfolio/apps/api +EXPOSE 3333 +CMD [ "node", "main" ] diff --git a/README.md b/README.md index 78b0e2cf0..a4ed80f52 100644 --- a/README.md +++ b/README.md @@ -34,7 +34,7 @@ Our official **[Ghostfolio Premium](https://ghostfol.io/pricing)** cloud offering is the easiest way to get started. Due to the time it saves, this will be the best option for most people. The revenue is used for covering the hosting costs. -If you prefer to run Ghostfolio on your own infrastructure, please find the source code and further instructions here on _GitHub_ or use the [setup](https://github.com/psychowood/ghostfolio-docker) by [psychowood](https://github.com/psychowood). +If you prefer to run Ghostfolio on your own infrastructure, please find further instructions in the section [Run with Docker](#run-with-docker). ## Why Ghostfolio? @@ -81,13 +81,44 @@ The backend is based on [NestJS](https://nestjs.com) using [PostgreSQL](https:// The frontend is built with [Angular](https://angular.io) and uses [Angular Material](https://material.angular.io) with utility classes from [Bootstrap](https://getbootstrap.com). -## Getting Started +## Run with Docker ### Prerequisites +- [Docker](https://www.docker.com/products/docker-desktop) + +### Setup Docker Image + +Run the following commands to build and start the Docker image: + +```bash +docker-compose -f docker/docker-compose-build-local.yml build +docker-compose -f docker/docker-compose-build-local.yml up +``` + +### Setup Database + +Run the following command to setup the database once Ghostfolio is running: + +```bash +docker-compose -f docker/docker-compose-build-local.yml exec ghostfolio yarn setup:database +``` + +### Fetch Historical Data + +Open http://localhost:3333 in your browser and accomplish these steps: + +1. Login as _Admin_ with the following _Security Token_: `ae76872ae8f3419c6d6f64bf51888ecbcc703927a342d815fafe486acdb938da07d0cf44fca211a0be74a423238f535362d390a41e81e633a9ce668a6e31cdf9` +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 + +- [Docker](https://www.docker.com/products/docker-desktop) - [Node.js](https://nodejs.org/en/download) (version 14+) - [Yarn](https://yarnpkg.com/en/docs/install) -- [Docker](https://www.docker.com/products/docker-desktop) ### Setup @@ -101,18 +132,14 @@ The frontend is built with [Angular](https://angular.io) and uses [Angular Mater 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 - -Please make sure you have completed the instructions from [_Setup_](#Setup). - -### Start server +### Start Server
  1. Debug: Run yarn watch:server and click "Launch Program" in Visual Studio Code
  2. Serve: Run yarn start:server
-### Start client +### Start Client Run `yarn start:client` diff --git a/angular.json b/angular.json index c21159c7e..f22cb2008 100644 --- a/angular.json +++ b/angular.json @@ -35,6 +35,7 @@ }, "configurations": { "production": { + "generatePackageJson": true, "optimization": true, "extractLicenses": true, "inspect": false, @@ -99,12 +100,12 @@ { "glob": "CHANGELOG.md", "input": "", - "output": "./" + "output": "./assets" }, { "glob": "LICENSE", "input": "", - "output": "./" + "output": "./assets" }, { "glob": "robots.txt", diff --git a/apps/client/src/app/pages/about/about-page.html b/apps/client/src/app/pages/about/about-page.html index 503f7c738..beff9cf75 100644 --- a/apps/client/src/app/pages/about/about-page.html +++ b/apps/client/src/app/pages/about/about-page.html @@ -198,7 +198,7 @@

Changelog

- + @@ -209,7 +209,7 @@

License

- + diff --git a/docker/docker-compose-build-local.yml b/docker/docker-compose-build-local.yml new file mode 100644 index 000000000..39d6fcf95 --- /dev/null +++ b/docker/docker-compose-build-local.yml @@ -0,0 +1,24 @@ +version: '3.7' +services: + postgres: + image: postgres:12 + env_file: + - ../.env + volumes: + - postgres:/var/lib/postgresql/data + + redis: + image: 'redis:alpine' + + ghostfolio: + build: ../ + env_file: + - ../.env + environment: + REDIS_HOST: 'redis' + DATABASE_URL: postgresql://user:password@postgres:5432/ghostfolio-db?sslmode=prefer + ports: + - 3333:3333 + +volumes: + postgres: diff --git a/package.json b/package.json index 2e4e32357..ff873a3e2 100644 --- a/package.json +++ b/package.json @@ -175,5 +175,8 @@ "parser": "typescript", "style": "module" } + }, + "prisma": { + "seed": "node prisma/seed.js" } } diff --git a/prisma/seed.ts b/prisma/seed.js similarity index 99% rename from prisma/seed.ts rename to prisma/seed.js index 700808392..a5a789d59 100644 --- a/prisma/seed.ts +++ b/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() {