Skip to content
Snippets Groups Projects
Commit 1e9c3267 authored by leandet98's avatar leandet98
Browse files

Merge branch '8-docker' into 'main'

dockerize application

See merge request swp-ws21-fahrtenbuch/team-einhorn/fahrtenbuch!4
parents 77d11f52 12d31916
No related branches found
No related tags found
No related merge requests found
Showing
with 38872 additions and 16699 deletions
# Fahrtenbuch
- First create .env File from .env.example
The application is now dockerized.
That means: Every part of the app (client, server, postgres, pgAdmin) is now an own Docker container. Client and server both have a Dockerfile which defines the routine to be run when building the container from the source.
All parts work together by composing them with docker-compose. The file `docker-compose.yaml` defines, which services there are and how Docker should initialize them. By composing the multiple services, they all run inside their own container but can communicate inside their own network with each other.
By using **volumes**, we can directly map the source code on our machine to the source code inside the container, which enables us to sync our changes with the container -> Hot reload :)
- Install modules:
```
npm install
```
## How to develop
- Run
```
npm run dev
```
```
npm run start
```
- Install Docker: https://www.docker.com/get-started
- In the root of the project, run `docker compose build` to build all containers.
- Then run `docker compose up` to start the build.
- Done
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
# dependencies
/node_modules
/.pnp
.pnp.js
# testing
/coverage
# production
/build
# misc
.DS_Store
.env.local
.env.development.local
.env.test.local
.env.production.local
npm-debug.log*
yarn-debug.log*
yarn-error.log*
# pull latest node image
FROM node:lts-alpine
# set container's workdir
WORKDIR /client
# install dependencies
COPY package.json ./
RUN npm install
# copy source
COPY . .
EXPOSE 3000
CMD ["npm", "start"]
\ No newline at end of file
# Getting Started with Create React App
This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app).
## Available Scripts
In the project directory, you can run:
### `npm start`
Runs the app in the development mode.\
Open [http://localhost:3000](http://localhost:3000) to view it in the browser.
The page will reload if you make edits.\
You will also see any lint errors in the console.
### `npm test`
Launches the test runner in the interactive watch mode.\
See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information.
### `npm run build`
Builds the app for production to the `build` folder.\
It correctly bundles React in production mode and optimizes the build for the best performance.
The build is minified and the filenames include the hashes.\
Your app is ready to be deployed!
See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information.
### `npm run eject`
**Note: this is a one-way operation. Once you `eject`, you can’t go back!**
If you aren’t satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project.
Instead, it will copy all the configuration files and the transitive dependencies (webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you’re on your own.
You don’t have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn’t feel obligated to use this feature. However we understand that this tool wouldn’t be useful if you couldn’t customize it when you are ready for it.
## Learn More
You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started).
To learn React, check out the [React documentation](https://reactjs.org/).
This diff is collapsed.
{
"name": "client",
"version": "0.1.0",
"private": true,
"dependencies": {
"@fortawesome/fontawesome-svg-core": "^1.2.36",
"@fortawesome/free-solid-svg-icons": "^5.15.4",
"@fortawesome/react-fontawesome": "^0.1.16",
"@testing-library/jest-dom": "^5.15.0",
"@testing-library/react": "^11.2.7",
"@testing-library/user-event": "^12.8.3",
"@types/jest": "^26.0.24",
"@types/node": "^12.20.36",
"@types/react": "^17.0.34",
"@types/react-dom": "^17.0.11",
"bootstrap": "^5.1.3",
"formik": "^2.2.9",
"react": "^17.0.2",
"react-bootstrap": "^2.0.2",
"react-dom": "^17.0.2",
"react-router-dom": "^6.0.1",
"react-scripts": "4.0.3",
"sass": "^1.43.4",
"typescript": "^4.4.4",
"web-vitals": "^1.1.2",
"yup": "^0.32.11"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
"eslintConfig": {
"extends": [
"react-app",
"react-app/jest"
]
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
},
"proxy": "http://server:4000"
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<link rel="icon" href="%PUBLIC_URL%/favicon.ico" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="theme-color" content="#000000" />
<meta
name="description"
content="Web site created using create-react-app"
/>
<link rel="apple-touch-icon" href="%PUBLIC_URL%/logo192.png" />
<!--
manifest.json provides metadata used when your web app is installed on a
user's mobile device or desktop. See https://developers.google.com/web/fundamentals/web-app-manifest/
-->
<link rel="manifest" href="%PUBLIC_URL%/manifest.json" />
<!--
Notice the use of %PUBLIC_URL% in the tags above.
It will be replaced with the URL of the `public` folder during the build.
Only files inside the `public` folder can be referenced from the HTML.
Unlike "/favicon.ico" or "favicon.ico", "%PUBLIC_URL%/favicon.ico" will
work correctly both with client-side routing and a non-root public URL.
Learn how to configure a non-root public URL by running `npm run build`.
-->
<title>React App</title>
</head>
<body>
<noscript>You need to enable JavaScript to run this app.</noscript>
<div id="root"></div>
<!--
This HTML file is a template.
If you open it directly in the browser, you will see an empty page.
You can add webfonts, meta tags, or analytics to this file.
The build step will place the bundled scripts into the <body> tag.
To begin the development, run `npm start` or `yarn start`.
To create a production bundle, use `npm run build` or `yarn build`.
-->
</body>
</html>
\ No newline at end of file
import React from "react";
import { BrowserRouter, Routes, Route } from "react-router-dom";
import Header from "./components/Header";
import Home from "./pages/Home";
import VehicleTypes from "./pages/VehicleTypes";
import CreateLogEntry from "./pages/CreateLogEntry";
function Router() {
return (
<BrowserRouter>
<Header />
<div className="mainView">
<Routes>
<Route path="/">
<Route index element={<Home />} />
<Route path="qr">
<Route path=":vehicleId" element={<CreateLogEntry />} />
</Route>
<Route path="vehicleTypes" element={<VehicleTypes />} />
<Route path="login" element={null} />
</Route>
</Routes>
</div>
</BrowserRouter>
);
}
export default Router;
import React from "react";
import Navbar from "react-bootstrap/Navbar";
import Container from "react-bootstrap/Container";
import Nav from "react-bootstrap/Nav";
import { Navbar, Container, Nav } from "react-bootstrap";
import { Link } from "react-router-dom";
function Header() {
......
import React from "react";
import ReactDOM from "react-dom";
import Router from "./Router";
import "./styles/app.scss";
ReactDOM.render(
<React.StrictMode>
<Router />
</React.StrictMode>,
document.getElementById("root")
);
import React from "react";
import Form from "react-bootstrap/Form";
import Row from "react-bootstrap/Row";
import Col from "react-bootstrap/Col";
import Button from "react-bootstrap/Button";
import { useParams } from "react-router-dom";
import { useFormik } from "formik";
import * as Yup from "yup";
import { useParams } from "react-router-dom";
import { Col, Form, Row, Button } from "react-bootstrap";
function VehicleInfo() {
const { vehicleId } = useParams<{ vehicleId: string }>();
const { vehicleId } = useParams();
return (
<div>
<h3>ID: {vehicleId}</h3>
......
import React from "react";
function Home() {
return <div>Home</div>;
}
export default Home;
......@@ -10,7 +10,7 @@ function VehicleTypes() {
{ id: number; name: string; seats: number; image: string }[]
>([]);
const [add, setAdd] = useState(false);
const [removeId, setRemoveId] = useState<number>(null);
const [removeId, setRemoveId] = useState<number | null>(null);
useEffect(() => {
reloadData();
......@@ -65,7 +65,7 @@ function VehicleTypes() {
<Modal.Body>
<p>
Remove VehicleType "
{vehicleTypes.find((x) => x.id == removeId).name}"?
{/* {vehicleTypes.find((x) => x.id == removeId).name}"? */}
</p>
</Modal.Body>
<Modal.Footer>
......@@ -161,7 +161,7 @@ function VehicleTypes() {
<FontAwesomeIcon
className={"text-danger text-center iconHover"}
onClick={() => {
this.setState({ removeId: t.id });
setRemoveId(t.id);
}}
title="Remove"
icon={faTrash}
......
/// <reference types="react-scripts" />
......@@ -31,4 +31,4 @@ $theme-colors: (
}
}
@import '../../../node_modules/bootstrap/dist/css/bootstrap.css';
@import 'bootstrap/dist/css/bootstrap.css';
{
"compilerOptions": {
"target": "es5",
"lib": [
"dom",
"dom.iterable",
"esnext"
],
"allowJs": true,
"skipLibCheck": true,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"strict": true,
"forceConsistentCasingInFileNames": true,
"noFallthroughCasesInSwitch": true,
"module": "esnext",
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
"noEmit": true,
"jsx": "react-jsx"
},
"include": [
"src"
]
}
version: "3.8"
services:
postgres:
image: postgres
container_name: fahrtenbuch-postgres
environment:
POSTGRES_USER: ${POSTGRES_USER:-postgres}
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-postgres}
POSTGRES_DB: ${DB_NAME:-postgres}
PGDATA: /data/postgres
volumes:
- postgres:/data/postgres
ports:
- "5432:5432"
networks:
- app-network
restart: unless-stopped
pgadmin:
container_name: pgadmin_container
image: dpage/pgadmin4
environment:
PGADMIN_DEFAULT_EMAIL: ${PGADMIN_DEFAULT_EMAIL:-pgadmin4@pgadmin.org}
PGADMIN_DEFAULT_PASSWORD: ${PGADMIN_DEFAULT_PASSWORD:-admin}
PGADMIN_CONFIG_SERVER_MODE: "False"
volumes:
- pgadmin:/var/lib/pgadmin
ports:
- "${PGADMIN_PORT:-5050}:80"
networks:
- app-network
restart: unless-stopped
server:
build:
context: ./server
dockerfile: Dockerfile
image: fahrtenbuch-server-image
container_name: fahrtenbuch-server
command: npm run dev
volumes:
- ./server/:/server
- /server/node_modules
ports:
- "4000:4000"
depends_on:
- postgres
env_file:
- ./server/.env
environment:
- NODE_ENV=development
- DB_HOST=postgres
networks:
- app-network
client:
build:
context: ./client
dockerfile: Dockerfile
image: fahrtenbuch-client-image
container_name: fahrtenbuch-client
command: npm start
volumes:
- ./client/:/client
- /client/node_modules
depends_on:
- server
ports:
- "3000:3000"
networks:
- app-network
networks:
app-network:
driver: bridge
volumes:
postgres:
pgadmin:
node_modules:
web-root:
driver: local
This diff is collapsed.
{
"name": "swp-einhorn",
"version": "1.0.0",
"description": "",
"main": "dist/server.js",
"scripts": {
"build": "webpack",
"watch:build": "webpack -w",
"watch:server": "nodemon -r dotenv/config dist/server.js",
"dev": "npm-run-all --parallel watch:*",
"start": "node dist/server.js",
"test": "jest"
},
"author": "",
"license": "ISC",
"dependencies": {
"@fortawesome/fontawesome-svg-core": "^1.2.36",
"@fortawesome/free-solid-svg-icons": "^5.15.4",
"@fortawesome/react-fontawesome": "^0.1.16",
"bootstrap": "^5.1.3",
"dotenv": "^10.0.0",
"express": "^4.17.1",
"formik": "^2.2.9",
"pg": "^8.7.1",
"react": "^17.0.2",
"react-bootstrap": "^2.0.0",
"react-dom": "^17.0.2",
"react-router-dom": "^5.3.0",
"sass": "^1.43.4",
"sequelize": "^6.8.0",
"yup": "^0.32.11"
},
"devDependencies": {
"@types/express": "^4.17.13",
"@types/jquery": "^3.5.8",
"@types/node": "^16.11.6",
"@types/react": "^17.0.33",
"@types/react-dom": "^17.0.10",
"@types/react-router-dom": "^5.3.2",
"concurrently": "^6.3.0",
"css-loader": "^6.5.0",
"eslint": "^8.1.0",
"eslint-webpack-plugin": "^3.1.0",
"jest": "^27.3.1",
"mocha": "^9.1.3",
"nodemon": "^2.0.14",
"npm-run-all": "^4.1.5",
"sass-loader": "^12.3.0",
"style-loader": "^3.3.1",
"supertest": "^6.1.6",
"ts-loader": "^9.2.6",
"webpack": "^5.60.0",
"webpack-cli": "^4.9.1",
"webpack-node-externals": "^3.0.0"
}
}
<!DOCTYPE html>
<html lang="en">
<head>
<title>EFB - Einhorn</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
</head>
<body>
<div id="app"></div>
<script src="/js/app.js"></script>
</body>
</html>
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment