Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

150 fix start script for production runs #161

Merged
merged 4 commits into from
Jan 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .devcontainer/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ services:
EMAIL__HOST: smtp.strato.de
EMAIL__PORT: 587
EMAIL__ADDRESS: [email protected]
EMAIL__PSW: 123456
EMAIL__PSW: ${EMAIL__PSW}
ASPNETCORE_ENVIRONMENT: Development

# Uncomment the next line to use a non-root user for all processes.
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
.devcontainer/.env

# Node
logs
npm-debug.log*
Expand Down
10 changes: 9 additions & 1 deletion src/.env → src/.env.template
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
# Copy this file into a .env.local

BACKEND_URL=http://localhost:3001
# Secret which is used for the jwt auth tokens in frontend
NEXTAUTH_SECRET=test1234
# Must be the public url of the frontend
NEXTAUTH_URL=http://localhost:3000

POSTGRES_DB=deskstar
POSTGRES_USER=postgres
POSTGRES_PASSWORD=root
Expand All @@ -10,6 +18,6 @@ DB__PASSWORD=root
EMAIL__HOST=smtp.strato.de
EMAIL__PORT=587
[email protected]
EMAIL__PSW=123456
EMAIL__PSW=

ASPNETCORE_ENVIRONMENT=Development
1 change: 1 addition & 0 deletions src/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.local
27 changes: 26 additions & 1 deletion src/ReadMe.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,29 @@
# Local Dev Setup
# Local Setup

## Local production run

1. Copy the `.env.template` file to `.env.local`:
```bash
cp .env.template .env.local
```

2. Add the necessary settings to the `.env.local` or change it. The `EMAIL__PSW` is needed to run the backend. Please change the mail settings accordingly.

3. Inside the `src` folder run:

```bash
./start.sh
```

4. The frontend should now be reachable on `http://localhost:3000`. After that you should be able to register, login and use the software.

5. OPTIONAL: If you want to fill the database with our dummy-data you can use the following command:
```bash
docker exec -i deskstar_postgres psql -U postgres deskstar < ./deskstar-db/dummy-data.sql
```
The dummy data already contain some companies you can use and also some test users. You can find the login data at the bottom of this README.

## Local Dev Setup

### 1. Build and open in Dev Container

Expand Down
59 changes: 0 additions & 59 deletions src/compose.yaml

This file was deleted.

20 changes: 20 additions & 0 deletions src/deskstar-backend/Deskstar/Dockerfile_dev
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
FROM mcr.microsoft.com/dotnet/sdk:6.0

RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
&& apt-get -y install --no-install-recommends \
postgresql

RUN dotnet tool install --global dotnet-ef


WORKDIR /Deskstar
# Copy everything
COPY . ./
# Restore as distinct layers
RUN dotnet restore
# Build and publish a release
RUN dotnet publish -c Dev -o out

ENV PATH="${PATH}:~/.dotnet/tools/"

CMD ["dotnet", "bin/Dev/net6.0/Deskstar.dll"]
56 changes: 51 additions & 5 deletions src/deskstar-frontend/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,11 +1,57 @@
FROM node:16.18
# Install dependencies only when needed
FROM node:16-alpine AS deps
# Check https://github.com/nodejs/docker-node/tree/b4117f9333da4138b03a546ec926ef50a31506c3#nodealpine to understand why libc6-compat might be needed.
RUN apk add --no-cache libc6-compat
WORKDIR /app

# Install dependencies based on the preferred package manager
COPY package.json yarn.lock* package-lock.json* pnpm-lock.yaml* ./
RUN \
if [ -f yarn.lock ]; then yarn --frozen-lockfile; \
elif [ -f package-lock.json ]; then npm ci; \
elif [ -f pnpm-lock.yaml ]; then yarn global add pnpm && pnpm i --frozen-lockfile; \
else echo "Lockfile not found." && exit 1; \
fi


# Rebuild the source code only when needed
FROM node:16-alpine AS builder
WORKDIR /app
COPY . .
COPY --from=deps /app/node_modules ./node_modules

# Next.js collects completely anonymous telemetry data about general usage.
# Learn more here: https://nextjs.org/telemetry
# Uncomment the following line in case you want to disable telemetry during the build.
ENV NEXT_TELEMETRY_DISABLED 1

RUN yarn build

# If using npm comment out above and use below instead
# RUN npm run build

# Production image, copy all the files and run next
FROM node:16-alpine AS runner
WORKDIR /app

COPY ./package.json .
ENV NODE_ENV production
# Uncomment the following line in case you want to disable telemetry during runtime.
ENV NEXT_TELEMETRY_DISABLED 1

RUN addgroup --system --gid 1001 nodejs
RUN adduser --system --uid 1001 nextjs

COPY --from=builder /app/public ./public

# Automatically leverage output traces to reduce image size
# https://nextjs.org/docs/advanced-features/output-file-tracing
COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./
COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static

USER nextjs

RUN ["yarn", "install"]
EXPOSE 3000

ENV PATH=/app/node_modules/.bin:$PATH
ENV PORT 3000

WORKDIR /app/code
CMD ["node", "server.js"]
11 changes: 0 additions & 11 deletions src/deskstar-frontend/Dockerfile_production

This file was deleted.

1 change: 1 addition & 0 deletions src/deskstar-frontend/next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
const nextConfig = {
reactStrictMode: true,
swcMinify: true,
output: "standalone"
}

module.exports = nextConfig
12 changes: 12 additions & 0 deletions src/deskstar-frontend/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -496,6 +496,11 @@ [email protected], client-only@^0.0.1:
resolved "https://registry.yarnpkg.com/client-only/-/client-only-0.0.1.tgz#38bba5d403c41ab150bff64a95c85013cf73bca1"
integrity sha512-IV3Ou0jSMzZrd3pZ48nLkT9DA7Ag1pnPzaiQhpW7c3RbcqqzvzzVu+L8gfqMp/8IM2MQtSiqaCxrrcfu8I8rMA==

clsx@^1.1.1:
version "1.2.1"
resolved "https://registry.yarnpkg.com/clsx/-/clsx-1.2.1.tgz#0ddc4a20a549b59c93a4116bb26f5294ca17dc12"
integrity sha512-EcR6r5a8bj6pu3ycsa/E/cKVGuTgZJZdsyUYHOksG/UHIiKfjxzRxYJpyVBwYaQeOvghal9fcc4PidlgzugAQg==

color-convert@^2.0.1:
version "2.0.1"
resolved "https://registry.yarnpkg.com/color-convert/-/color-convert-2.0.1.tgz#72d3a68d598c9bdb3af2ad1e84f21d896abd4de3"
Expand Down Expand Up @@ -1822,6 +1827,13 @@ react-is@^16.13.1:
resolved "https://registry.yarnpkg.com/react-is/-/react-is-16.13.1.tgz#789729a4dc36de2999dc156dd6c1d9c18cea56a4"
integrity sha512-24e6ynE2H+OKt4kqsOvNd8kBpV65zoxbA4BVsEOB3ARVWQki/DHzaUoC5KuON/BiccDaCCTZBuOcfZs70kR8bQ==

react-toastify@^9.1.1:
version "9.1.1"
resolved "https://registry.yarnpkg.com/react-toastify/-/react-toastify-9.1.1.tgz#9280caea4a13dc1739c350d90660a630807bf10b"
integrity sha512-pkFCla1z3ve045qvjEmn2xOJOy4ZciwRXm1oMPULVkELi5aJdHCN/FHnuqXq8IwGDLB7PPk2/J6uP9D8ejuiRw==
dependencies:
clsx "^1.1.1"

[email protected]:
version "18.2.0"
resolved "https://registry.yarnpkg.com/react/-/react-18.2.0.tgz#555bd98592883255fa00de14f1151a917b5d77d5"
Expand Down
73 changes: 73 additions & 0 deletions src/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
services:
frontend:
container_name: deskstar_frontend
build:
context: ./deskstar-frontend
ports:
- 3000:3000
environment:
- BACKEND_URL
- NEXTAUTH_SECRET
- NEXTAUTH_URL
networks:
- external
- internal
backend:
container_name: deskstar_backend
depends_on:
- "postgres"
build:
context: ./deskstar-backend/Deskstar
ports:
- 3001:80
environment:
- ASPNETCORE_ENVIRONMENT
- DB__HOST
- DB__DATABASE
- DB__USERNAME
- DB__PASSWORD
# defined in .env.local (will no be pushed to git)
- EMAIL__HOST
- EMAIL__PORT
- EMAIL__ADDRESS
- EMAIL__PSW
networks:
- internal
dbpreparation:
container_name: deskstar_db_prep
build:
context: ./deskstar-backend/Deskstar
dockerfile: Dockerfile_dev
depends_on:
- "postgres"
environment:
# - ASPNETCORE_ENVIRONMENT
- DB__HOST
- DB__DATABASE
- DB__USERNAME
- DB__PASSWORD
# defined in .env.local (will no be pushed to git)
- EMAIL__HOST
- EMAIL__PORT
- EMAIL__ADDRESS
- EMAIL__PSW
networks:
- internal
command: dotnet ef database update
postgres:
container_name: deskstar_postgres
image: postgres
user: "postgres"
environment:
- POSTGRES_USER
- POSTGRES_DB
- POSTGRES_PASSWORD
ports:
- 5433:5432
networks:
- internal
volumes:
exclude:
networks:
internal:
external:
7 changes: 4 additions & 3 deletions src/start.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export USER_ID="$(id -u)"
export GROUP_ID="$(id -g)"
docker compose --env-file .env up --build
export DOCKER_BUILDKIT=0
export COMPOSE_DOCKER_CLI_BUILD=0

docker compose --env-file .env.local up --build