Skip to content

Commit cc67b29

Browse files
tes
2 parents 140f944 + bd6444a commit cc67b29

4 files changed

Lines changed: 333 additions & 2 deletions

File tree

.gitignore

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,35 @@ out/
3535

3636
### VS Code ###
3737
.vscode/
38+
39+
### OS / Editor Junk ###
3840
.DS_Store
41+
<<<<<<< HEAD
3942
src/.DS_Store
4043
src/main/.DS_Store
4144
src/main/resources/.DS_Store
4245
.DS_Store
4346
.DS_Store
47+
=======
48+
Thumbs.db
49+
Desktop.ini
50+
51+
### Local App Data / Runtime Artifacts ###
52+
*.log
53+
*.tmp
54+
*.swp
55+
56+
### Local Environment / Secrets ###
57+
.env
58+
.env.*
59+
application-local.properties
60+
application-dev.properties
61+
src/main/resources/application-local.properties
62+
src/main/resources/application-dev.properties
63+
64+
### Local Databases ###
65+
*.db
66+
*.sqlite
67+
*.sqlite3
68+
>>>>>>> bd6444a68f11d9a3db5c157692385fabb6dfccc0
69+
.DS_Store

dockerfile renamed to Dockerfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ WORKDIR /app
77
# Copy only the specific JAR file
88
COPY build/libs/webstore-0.0.1-SNAPSHOT.jar app.jar
99

10+
COPY src/main/resources/static/images /app/src/main/resources/static/images
11+
1012
# Expose the application port
1113
EXPOSE 8080
1214

README.md

Lines changed: 304 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,304 @@
1+
2+
# Webstore Project
3+
4+
5+
6+
## Overview
7+
8+
9+
10+
This is a Java-based webstore application built with **Spring Boot**, **Thymeleaf**, and **MySQL**. The project is containerized using **Docker** and can be easily deployed using **Docker Compose**.
11+
12+
13+
14+
## Prerequisites
15+
16+
17+
18+
Make sure you have the following installed:
19+
20+
21+
22+
- [Docker](https://www.docker.com/)
23+
24+
- [Docker Compose](https://docs.docker.com/compose/)
25+
26+
- [Java 17](https://openjdk.org/projects/jdk/17/) (required for Gradle build)
27+
28+
- [Gradle](https://gradle.org/install/) (or use the included Gradle Wrapper)
29+
30+
31+
32+
## Installation & Setup
33+
34+
35+
36+
### 1. Clone the Repository
37+
38+
39+
40+
```sh
41+
42+
git clone https://github.com/ThomasRoyProjects/ExampleSpringbootWebstore.git
43+
44+
cd ExampleSpringbootWebstore
45+
46+
```
47+
48+
49+
50+
### 2. Launch a Temporary MySQL Container for Build
51+
52+
53+
54+
Start a temporary MySQL container to provide the database needed for the Gradle build (required for JPA tasks):
55+
56+
57+
58+
```sh
59+
60+
docker run -d --name mysql-db -e MYSQL_ROOT_PASSWORD=root -e MYSQL_DATABASE=amazingwebstore -p 3306:3306 mysql:8.0
61+
62+
```
63+
64+
65+
66+
This command:
67+
68+
69+
70+
- Starts a MySQL container named `mysql-db`
71+
72+
- Sets the root password to `root`
73+
74+
- Creates a database named `amazingwebstore`
75+
76+
- Maps port 3306 to the host
77+
78+
79+
80+
Wait for the MySQL container to be ready (this may take a few seconds):
81+
82+
83+
84+
```sh
85+
86+
docker logs mysql-db 2>&1 | grep "ready for connections"
87+
88+
```
89+
90+
91+
92+
Repeat the `docker logs` command until you see a message indicating the MySQL server is ready.
93+
94+
95+
96+
> **Note**: Ensure port 3306 is free on your host (check with `netstat -tuln | grep 3306` or equivalent).
97+
98+
99+
100+
### 3. Build the Spring Boot Application
101+
102+
103+
104+
With the MySQL container running, build the JAR file:
105+
106+
107+
108+
```sh
109+
110+
./gradlew build # For Linux/macOS
111+
112+
# OR
113+
114+
gradlew.bat build # For Windows
115+
116+
```
117+
118+
119+
120+
After the build completes, stop and remove the temporary MySQL container:
121+
122+
123+
124+
```sh
125+
126+
docker stop mysql-db
127+
128+
docker rm mysql-db
129+
130+
```
131+
132+
133+
134+
### 4. Start the Application with Docker Compose
135+
136+
137+
138+
Ensure ports 8080 and 3306 are free (check with `netstat -tuln | grep 8080` or equivalent). Then, run the following command to build and start the application and MySQL services:
139+
140+
141+
142+
```sh
143+
144+
docker-compose -f docker-compose.yml up --build -d
145+
146+
```
147+
148+
149+
150+
This will:
151+
152+
153+
154+
- Start a MySQL container (named `mysql-db`)
155+
156+
- Build and start the Spring Boot application (named `webstore`)
157+
158+
159+
160+
### 5. Verify Running Containers
161+
162+
163+
164+
Check that the containers are running:
165+
166+
167+
168+
```sh
169+
170+
docker ps
171+
172+
```
173+
174+
175+
176+
You should see the MySQL and application containers (`mysql-db` and `webstore`).
177+
178+
179+
180+
### 6. Access the Webstore
181+
182+
183+
184+
- Open your browser and go to: [http://localhost:8080](http://localhost:8080)
185+
186+
- MySQL is accessible on port 3306
187+
188+
189+
190+
## Admin Panel
191+
192+
193+
194+
An administrative interface is available to manage your webstore's products.
195+
196+
197+
198+
- 📍 Visit: [http://localhost:8080/admin](http://localhost:8080/admin)
199+
200+
- 🔐 Credentials:
201+
202+
- **Username**: `admin`
203+
204+
- **Password**: `adminpass`
205+
206+
207+
208+
From the admin panel, you can:
209+
210+
211+
212+
- Add new products to your store
213+
214+
- Edit or update existing product details
215+
216+
- Manage inventory and pricing
217+
218+
219+
220+
> ⚠️ For security, change these default credentials before deploying to production.
221+
222+
223+
224+
## Environment Variables
225+
226+
227+
228+
The application uses the following database environment variables, defined in `docker-compose.yml`:
229+
230+
231+
232+
```yaml
233+
234+
SPRING_DATASOURCE_URL: jdbc:mysql://mysql-db:3306/amazingwebstore?useSSL=false&allowPublicKeyRetrieval=true&serverTimezone=UTC
235+
236+
SPRING_DATASOURCE_USERNAME: root
237+
238+
SPRING_DATASOURCE_PASSWORD: root
239+
240+
```
241+
242+
243+
244+
## Stopping the Application
245+
246+
247+
248+
To stop all running containers:
249+
250+
251+
252+
```sh
253+
254+
docker-compose -f docker-compose.yml down
255+
256+
```
257+
258+
259+
260+
## Troubleshooting
261+
262+
263+
264+
- Check logs for the application or MySQL containers:
265+
266+
267+
268+
```sh
269+
270+
docker logs webstore
271+
272+
docker logs mysql-db
273+
274+
```
275+
276+
277+
278+
- Ensure ports 8080 and 3306 are free before starting containers.
279+
280+
- If database connection issues occur, try restarting:
281+
282+
283+
284+
```sh
285+
286+
docker-compose -f docker-compose.yml down && docker-compose -f docker-compose.yml up --build -d
287+
288+
```
289+
290+
291+
292+
## License
293+
294+
295+
296+
This project is licensed under the **MIT License**.
297+
298+
299+
300+
## Author
301+
302+
303+
304+
Developed by **Thomas Roy**.

docker-compose.yaml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,9 @@ services:
3333
- "8080:8080"
3434
volumes:
3535
- ./uploads:/app/uploads
36-
- ./src/main/resources/static/images:/app/src/main/resources/static/images
3736
networks:
3837
- webstore-network
3938

4039
networks:
4140
webstore-network:
42-
driver: bridge
41+
driver: bridge

0 commit comments

Comments
 (0)