Skip to content

Commit

Permalink
Merge pull request #161 from amosproj/150-fix-start-script-for-produc…
Browse files Browse the repository at this point in the history
…tion-runs

150 fix start script for production runs
  • Loading branch information
xilef45 authored Jan 17, 2023
2 parents 6f95e24 + 476105c commit 1474060
Show file tree
Hide file tree
Showing 12 changed files with 188 additions and 81 deletions.
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
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

0 comments on commit 1474060

Please sign in to comment.