From c165a0f71b4a06fd30c78242f61c16e5dbbe9eaf Mon Sep 17 00:00:00 2001 From: "theis.gaedigk" Date: Sun, 29 Jun 2025 19:10:43 +0200 Subject: [PATCH] feat: initialize backend environment with Docker setup and configuration files --- .gitignore | 3 --- Dockerfile | 0 README.md | 30 ++++++++++++++++++++++++++++++ backend/.env | 4 ++++ backend/Dockerfile | 12 ++++++++++++ docker-compose.yml | 33 +++++++++++++++++++++++++++++++++ 6 files changed, 79 insertions(+), 3 deletions(-) delete mode 100644 Dockerfile create mode 100755 backend/.env create mode 100644 backend/Dockerfile diff --git a/.gitignore b/.gitignore index bc926e3..11078bc 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,3 @@ -backend/.env -# Ignore environment files - index.html # Ignore frontend dev file diff --git a/Dockerfile b/Dockerfile deleted file mode 100644 index e69de29..0000000 diff --git a/README.md b/README.md index e69de29..0d856ed 100644 --- a/README.md +++ b/README.md @@ -0,0 +1,30 @@ +# Login page +This is an app which I am currently working on... + +## How to run? +1. Install docker on your machine +2. Then run the docker-compose file and make sure that port ```4000``` and ```3306``` are not in use. +3. Then enter the mysql container (exec) with the credentials that you can see in the ```docker-compose.yml``` file and in the ```.env``` file. +4. Then login with the root user with ```mysql -u root -p```, after that enter the password from the ```docker-compose.yml``` file or the ```.env``` file. +5. Then type ```use login_page;``` +6. Then create a table with the following scheme (extract from scheme.sql): +``` sql +-- Table structure for the database +CREATE TABLE users ( + id INT PRIMARY KEY AUTO_INCREMENT, + username VARCHAR(50) NOT NULL UNIQUE, + first_name VARCHAR(50) NOT NULL, + last_name VARCHAR(50) NOT NULL, + email VARCHAR(100) NOT NULL UNIQUE, + password VARCHAR(255) NOT NULL, + created TIMESTAMP NOT NULL DEFAULT NOW() +); + +-- Mock data for users +INSERT INTO users (username, first_name, last_name, email, password) +VALUES +('test1', 'John', 'Doe', 'jdoe@example.com', '1test'), +('test2', 'Alice', 'Smith', 'asmith@example.com', '2test'); +``` + +If you are confident with sql you can change the mock data, and create your own user. \ No newline at end of file diff --git a/backend/.env b/backend/.env new file mode 100755 index 0000000..c5fb2ae --- /dev/null +++ b/backend/.env @@ -0,0 +1,4 @@ +DB_HOST=mysql +DB_USER=root +DB_PASSWORD=D7Ze0lwV9hMrNQHdz1Q8yi0MIQuOO8 +DB_NAME=login_page \ No newline at end of file diff --git a/backend/Dockerfile b/backend/Dockerfile new file mode 100644 index 0000000..93c06de --- /dev/null +++ b/backend/Dockerfile @@ -0,0 +1,12 @@ +FROM node:18 + +WORKDIR /app + +COPY package*.json ./ +RUN npm install + +COPY . . + +EXPOSE 4000 + +CMD ["npm", "start"] \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index e69de29..0d3c5e5 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -0,0 +1,33 @@ +version: '3.9' + +services: + backend: + container_name: login-page + build: ./backend + ports: + - "4000:4000" + environment: + DB_HOST: mysql + DB_USER: root + DB_PASSWORD: D7Ze0lwV9hMrNQHdz1Q8yi0MIQuOO8 + DB_NAME: login_page + depends_on: + - mysql + volumes: + - ./backend:/app + restart: unless-stopped + + mysql: + container_name: mysql-db + image: mysql:8.0 + restart: unless-stopped + environment: + MYSQL_ROOT_PASSWORD: D7Ze0lwV9hMrNQHdz1Q8yi0MIQuOO8 + MYSQL_DATABASE: login_page + volumes: + - mysql-data:/var/lib/mysql + ports: + - "3306:3306" + +volumes: + mysql-data: