Skip to content

Commit fb72ea4

Browse files
committed
updated docker-compose
1 parent 64ed9c3 commit fb72ea4

File tree

3 files changed

+212
-13
lines changed

3 files changed

+212
-13
lines changed

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM openjdk:11-jre-slim
1+
FROM adoptopenjdk/openjdk11:alpine-jre
22
VOLUME /tmp
33
ARG JAR_FILE=target/*.jar
44
COPY ${JAR_FILE} app.jar

data/blogapi.sql

Lines changed: 192 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,192 @@
1+
USE blogapi;
2+
3+
UNLOCK TABLES;
4+
5+
DROP TABLE IF EXISTS `post_tag`;
6+
DROP TABLE IF EXISTS `tags`;
7+
DROP TABLE IF EXISTS `user_role`;
8+
DROP TABLE IF EXISTS `roles`;
9+
DROP TABLE IF EXISTS `comments`;
10+
DROP TABLE IF EXISTS `posts`;
11+
DROP TABLE IF EXISTS `photos`;
12+
DROP TABLE IF EXISTS `albums`;
13+
DROP TABLE IF EXISTS `todos`;
14+
DROP TABLE IF EXISTS `users`;
15+
DROP TABLE IF EXISTS `address`;
16+
DROP TABLE IF EXISTS `company`;
17+
DROP TABLE IF EXISTS `geo`;
18+
19+
CREATE TABLE `tags` (
20+
`id` bigint(19) unsigned NOT NULL AUTO_INCREMENT,
21+
`name` varchar(255) NOT NULL,
22+
`created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
23+
`updated_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
24+
`created_by` bigint(19) unsigned NOT NULL,
25+
`updated_by` bigint(19) unsigned NOT NULL,
26+
PRIMARY KEY (`id`)
27+
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
28+
29+
CREATE TABLE `geo` (
30+
`id` bigint(19) unsigned NOT NULL AUTO_INCREMENT,
31+
`lat` varchar(255),
32+
`lng` varchar(255),
33+
`created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
34+
`updated_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
35+
`created_by` bigint(19) unsigned DEFAULT NULL,
36+
`updated_by` bigint(19) unsigned DEFAULT NULL,
37+
PRIMARY KEY (`id`)
38+
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;
39+
40+
CREATE TABLE `company` (
41+
`id` bigint(19) unsigned NOT NULL AUTO_INCREMENT,
42+
`name` varchar(255),
43+
`catch_phrase` varchar(255),
44+
`bs` varchar(255),
45+
`created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
46+
`updated_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
47+
`created_by` bigint(19) unsigned DEFAULT NULL,
48+
`updated_by` bigint(19) unsigned DEFAULT NULL,
49+
PRIMARY KEY (`id`)
50+
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;
51+
52+
CREATE TABLE `address` (
53+
`id` bigint(19) unsigned NOT NULL AUTO_INCREMENT,
54+
`street` varchar(255),
55+
`suite` varchar(255),
56+
`city` varchar(255),
57+
`zipcode` varchar(255),
58+
`geo_id` bigint(19) unsigned DEFAULT NULL,
59+
`created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
60+
`updated_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
61+
`created_by` bigint(19) unsigned DEFAULT NULL,
62+
`updated_by` bigint(19) unsigned DEFAULT NULL,
63+
PRIMARY KEY (`id`),
64+
KEY `fk_geo` (`geo_id`),
65+
CONSTRAINT `fk_geo` FOREIGN KEY (`geo_id`) REFERENCES `geo` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
66+
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;
67+
68+
CREATE TABLE `users` (
69+
`id` bigint(19) unsigned NOT NULL AUTO_INCREMENT,
70+
`first_name` varchar(255) NOT NULL,
71+
`last_name` varchar(255) NOT NULL,
72+
`username` varchar(255) NOT NULL,
73+
`password` varchar(255) NOT NULL,
74+
`email` varchar(255) NOT NULL,
75+
`address_id` bigint(19) unsigned DEFAULT NULL,
76+
`phone` varchar(255),
77+
`website` varchar(255),
78+
`company_id` bigint(19) unsigned DEFAULT NULL,
79+
`created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
80+
`updated_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
81+
PRIMARY KEY (`id`),
82+
KEY `fk_address` (`address_id`),
83+
KEY `fk_company` (`company_id`),
84+
CONSTRAINT `fk_address` FOREIGN KEY (`address_id`) REFERENCES `address` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
85+
CONSTRAINT `fk_company` FOREIGN KEY (`company_id`) REFERENCES `company` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
86+
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;
87+
88+
CREATE TABLE `todos` (
89+
`id` bigint(19) unsigned NOT NULL AUTO_INCREMENT,
90+
`title` varchar(255) NOT NULL,
91+
`completed` boolean default false,
92+
`user_id` bigint(19) unsigned DEFAULT NULL,
93+
`created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
94+
`updated_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
95+
`created_by` bigint(19) unsigned DEFAULT NULL,
96+
`updated_by` bigint(19) unsigned DEFAULT NULL,
97+
PRIMARY KEY (`id`),
98+
KEY `fk_user_todos` (`user_id`),
99+
CONSTRAINT `fk_user_todos` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`)
100+
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;
101+
102+
CREATE TABLE `albums` (
103+
`id` bigint(19) unsigned NOT NULL AUTO_INCREMENT,
104+
`title` varchar(255) NOT NULL,
105+
`user_id` bigint(19) unsigned DEFAULT NULL,
106+
`created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
107+
`updated_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
108+
`created_by` bigint(19) unsigned DEFAULT NULL,
109+
`updated_by` bigint(19) unsigned DEFAULT NULL,
110+
PRIMARY KEY (`id`),
111+
KEY `fk_user_album` (`user_id`),
112+
CONSTRAINT `fk_user_album` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`)
113+
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;
114+
115+
CREATE TABLE `photos` (
116+
`id` bigint(19) unsigned NOT NULL AUTO_INCREMENT,
117+
`title` varchar(255) NOT NULL,
118+
`url` varchar(255) NOT NULL,
119+
`thumbnail_url` varchar(255) NOT NULL,
120+
`album_id` bigint(19) unsigned DEFAULT NULL,
121+
`created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
122+
`updated_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
123+
`created_by` bigint(19) unsigned DEFAULT NULL,
124+
`updated_by` bigint(19) unsigned DEFAULT NULL,
125+
PRIMARY KEY (`id`),
126+
KEY `fk_album` (`album_id`),
127+
CONSTRAINT `fk_album` FOREIGN KEY (`album_id`) REFERENCES `albums` (`id`)
128+
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;
129+
130+
CREATE TABLE `posts` (
131+
`id` bigint(19) unsigned NOT NULL AUTO_INCREMENT,
132+
`title` varchar(255) NOT NULL,
133+
`body` text NOT NULL,
134+
`user_id` bigint(19) unsigned DEFAULT NULL,
135+
`created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
136+
`updated_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
137+
`created_by` bigint(19) unsigned DEFAULT NULL,
138+
`updated_by` bigint(19) unsigned DEFAULT NULL,
139+
PRIMARY KEY (`id`),
140+
KEY `fk_user_post` (`user_id`),
141+
CONSTRAINT `fk_user_post` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`)
142+
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;
143+
144+
CREATE TABLE `post_tag` (
145+
`id` bigint(19) unsigned NOT NULL AUTO_INCREMENT,
146+
`post_id` bigint(19) unsigned NOT NULL,
147+
`tag_id` bigint(19) unsigned NOT NULL,
148+
PRIMARY KEY (`id`),
149+
KEY `fk_posttag_post_id` (`post_id`),
150+
KEY `fk_posttag_tag_id` (`tag_id`),
151+
CONSTRAINT `fk_posttag_post_id` FOREIGN KEY (`post_id`) REFERENCES `posts` (`id`),
152+
CONSTRAINT `fk_posttag_tag_id` FOREIGN KEY (`tag_id`) REFERENCES `tags` (`id`)
153+
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
154+
155+
CREATE TABLE `comments` (
156+
`id` bigint(19) unsigned NOT NULL AUTO_INCREMENT,
157+
`name` varchar(255) NOT NULL,
158+
`email` varchar(255) NOT NULL,
159+
`body` text NOT NULL,
160+
`post_id` bigint(19) unsigned DEFAULT NULL,
161+
`user_id` bigint(19) unsigned DEFAULT NULL,
162+
`created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
163+
`updated_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
164+
`created_by` bigint(19) unsigned NOT NULL,
165+
`updated_by` bigint(19) unsigned NOT NULL,
166+
PRIMARY KEY (`id`),
167+
KEY `fk_comment_post` (`post_id`),
168+
KEY `fk_comment_user` (`user_id`),
169+
CONSTRAINT `fk_comment_post` FOREIGN KEY (`post_id`) REFERENCES `posts` (`id`),
170+
CONSTRAINT `fk_comment_user` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`)
171+
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;
172+
173+
CREATE TABLE `roles` (
174+
`id` bigint(19) unsigned NOT NULL AUTO_INCREMENT,
175+
`name` varchar(255) NOT NULL,
176+
PRIMARY KEY (`id`)
177+
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;
178+
179+
CREATE TABLE `user_role` (
180+
`id` bigint(19) unsigned NOT NULL AUTO_INCREMENT,
181+
`user_id` bigint(19) unsigned NOT NULL,
182+
`role_id` bigint(19) unsigned NOT NULL,
183+
PRIMARY KEY (`id`),
184+
KEY `fk_security_user_id` (`user_id`),
185+
KEY `fk_security_role_id` (`role_id`),
186+
CONSTRAINT `fk_security_user_id` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`),
187+
CONSTRAINT `fk_security_role_id` FOREIGN KEY (`role_id`) REFERENCES `roles` (`id`)
188+
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;
189+
190+
LOCK TABLES `roles` WRITE;
191+
INSERT INTO `roles` VALUES (1,'ROLE_ADMIN'),(2,'ROLE_USER');
192+
UNLOCK TABLES;

docker-compose.yml

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,36 @@
1-
version: '3'
1+
version: '3.8'
22
services:
3-
mysql:
3+
db:
44
image: mysql
5+
container_name: blogapi-db
56
restart: always
67
environment:
78
MYSQL_DATABASE: 'blogapi'
8-
MYSQL_USER: 'root'
99
MYSQL_PASSWORD: 'root'
1010
MYSQL_ROOT_PASSWORD: 'root'
1111
ports:
12-
- '3306'
12+
- '3306:3306'
1313
networks:
14-
- production-network
14+
- blogapi-network
15+
healthcheck:
16+
test: "/usr/bin/mysql --user=root --password=root --execute \"SHOW DATABASES;\""
17+
interval: 2s
18+
timeout: 20s
19+
retries: 10
20+
volumes:
21+
- ./data:/docker-entrypoint-initdb.d
1522
application:
23+
container_name: blogapi-application
1624
build:
17-
dockerfile: ./Dockerfile
18-
context: .
19-
image: michel-eckhardt/spring-boot-blog
20-
container_name: spring-boot-blog
25+
context: ./
26+
dockerfile: Dockerfile
2127
ports:
2228
- "8080:8080"
2329
networks:
24-
- production-network
30+
- blogapi-network
2531
depends_on:
26-
- "mysql"
32+
- "db"
2733
networks:
28-
production-network:
34+
blogapi-network:
35+
name: blogapi-network
2936
driver: bridge

0 commit comments

Comments
 (0)