├── .gitignore ├── .nginx ├── Dockerfile └── default.conf ├── .travis.yml ├── LICENSE ├── README.md ├── backend ├── Dockerfile ├── pom.xml └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── github │ │ │ └── egnaf │ │ │ └── spring_docker_example │ │ │ ├── Application.java │ │ │ ├── config │ │ │ └── DozerConfig.java │ │ │ ├── domain │ │ │ └── User.java │ │ │ ├── exception │ │ │ ├── UserExistsException.java │ │ │ └── UserNotFoundException.java │ │ │ ├── repository │ │ │ └── UserRepository.java │ │ │ ├── rest │ │ │ ├── UserController.java │ │ │ └── error │ │ │ │ ├── ErrorHandlerController.java │ │ │ │ └── ErrorResponse.java │ │ │ ├── service │ │ │ ├── UserService.java │ │ │ └── impl │ │ │ │ └── UserServiceImpl.java │ │ │ └── transfer │ │ │ └── UserDto.java │ └── resources │ │ └── application.yml │ └── test │ ├── java │ └── com │ │ └── github │ │ └── egnaf │ │ └── spring_docker_example │ │ ├── ApplicationTest.java │ │ ├── repository │ │ └── UserRepositoryTest.java │ │ └── service │ │ └── impl │ │ └── UserServiceImplTest.java │ └── resources │ └── application.yml ├── codecov.yml ├── docker-compose.yml ├── frontend ├── .gitignore ├── Dockerfile ├── package.json ├── public │ ├── favicon.ico │ └── index.html └── src │ ├── App.vue │ ├── assets │ └── logo.png │ ├── components │ └── HelloWorld.vue │ └── main.js └── start.sh /.gitignore: -------------------------------------------------------------------------------- 1 | .idea 2 | *.iml -------------------------------------------------------------------------------- /.nginx/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM nginx 2 | RUN rm /etc/nginx/conf.d/default.conf 3 | COPY default.conf /etc/nginx/conf.d 4 | -------------------------------------------------------------------------------- /.nginx/default.conf: -------------------------------------------------------------------------------- 1 | server { 2 | listen 80; 3 | server_name nginx; 4 | 5 | location /api/0.1 { 6 | proxy_pass http://backend:5001; 7 | } 8 | 9 | location / { 10 | proxy_pass http://frontend:5002; 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: java 2 | jdk: openjdk8 3 | install: true 4 | 5 | cache: 6 | directories: 7 | - $HOME/.m2 8 | 9 | script: 10 | - cd backend && mvn -B verify && cd .. 11 | 12 | after_success: 13 | - bash <(curl -s https://codecov.io/bash) 14 | 15 | notifications: 16 | email: 17 | recipients: 18 | - egnaf@yahoo.com 19 | on_success: never 20 | on_failure: always 21 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2019 github.com/egnaf 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in all 11 | copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | SOFTWARE. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | [![Build Status](https://travis-ci.org/egnaf/spring-boot-docker-example.svg)](https://travis-ci.org/egnaf/spring-boot-docker-example) 2 | [![codecov](https://codecov.io/gh/egnaf/spring-boot-docker-example/branch/dev/graph/badge.svg)](https://codecov.io/gh/egnaf/spring-boot-docker-example) 3 | # spring-boot-postgres-vue-docker 4 | 5 | ## Stack 6 | - Spring Boot 2.2.0 7 | - Spring Data 2.2.0 8 | - Postgres 9.4 9 | - Docker 3 10 | - Maven 4 11 | - Tomcat 9 12 | 13 | ## Install 14 | To build services and launch them in containers, you need to run `start.sh`. 15 | ```bash 16 | $ bash start.sh 17 | ``` 18 | 19 | ## Contribute 20 | For any problems, comments, or feedback please create an issue 21 | [here](https://github.com/egnaf/spring-boot-docker-example/issues). 22 |
23 | 24 | ## License 25 | Project is released under the [MIT](https://en.wikipedia.org/wiki/MIT_License). 26 | -------------------------------------------------------------------------------- /backend/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM openjdk:8-jre-alpine 2 | WORKDIR /app/backend 3 | COPY target/app.jar ./app.jar 4 | CMD ["/usr/bin/java", "-jar", "app.jar"] 5 | -------------------------------------------------------------------------------- /backend/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4.0.0 3 | 4 | com.github.egnaf.spring-docker-example 5 | backend 6 | 0.1 7 | jar 8 | 9 | Spring boot docker example 10 | 11 | An example of a simple Spring Boot application and other services running 12 | with docker-compose file configuration 13 | 14 | 15 | 16 | 17 | 1 18 | Sherzod Mamadaliev 19 | egnaf@yahoo.com 20 | 21 | 22 | 23 | 24 | UTF-8 25 | 1.8 26 | 1.8 27 | 28 | 29 | 30 | org.springframework.boot 31 | spring-boot-starter-parent 32 | 2.2.0.RELEASE 33 | 34 | 35 | 36 | 37 | org.springframework.boot 38 | spring-boot-starter-web 39 | 40 | 41 | org.springframework.boot 42 | spring-boot-starter-test 43 | test 44 | 45 | 46 | org.springframework.boot 47 | spring-boot-devtools 48 | 49 | 50 | org.springframework.boot 51 | spring-boot-starter-data-jpa 52 | 53 | 54 | org.postgresql 55 | postgresql 56 | 42.7.2 57 | 58 | 59 | com.h2database 60 | h2 61 | 2.2.220 62 | test 63 | 64 | 65 | org.projectlombok 66 | lombok 67 | 1.18.10 68 | 69 | 70 | net.sf.dozer 71 | dozer 72 | 5.5.1 73 | 74 | 75 | 76 | 77 | app 78 | 79 | 80 | org.springframework.boot 81 | spring-boot-maven-plugin 82 | 83 | false 84 | 85 | 86 | 87 | org.jacoco 88 | jacoco-maven-plugin 89 | 0.8.4 90 | 91 | 92 | 93 | prepare-agent 94 | 95 | 96 | 97 | report 98 | test 99 | 100 | report 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | -------------------------------------------------------------------------------- /backend/src/main/java/com/github/egnaf/spring_docker_example/Application.java: -------------------------------------------------------------------------------- 1 | package com.github.egnaf.spring_docker_example; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class Application { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(Application.class, args); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /backend/src/main/java/com/github/egnaf/spring_docker_example/config/DozerConfig.java: -------------------------------------------------------------------------------- 1 | package com.github.egnaf.spring_docker_example.config; 2 | 3 | import org.dozer.DozerBeanMapper; 4 | import org.springframework.context.annotation.Bean; 5 | import org.springframework.context.annotation.Configuration; 6 | 7 | @Configuration 8 | public class DozerConfig { 9 | 10 | @Bean 11 | public DozerBeanMapper dozer() { 12 | return new DozerBeanMapper(); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /backend/src/main/java/com/github/egnaf/spring_docker_example/domain/User.java: -------------------------------------------------------------------------------- 1 | package com.github.egnaf.spring_docker_example.domain; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Data; 5 | import lombok.NoArgsConstructor; 6 | 7 | import javax.persistence.*; 8 | 9 | @Entity 10 | @Table(name = "users") 11 | @Data 12 | @NoArgsConstructor 13 | @AllArgsConstructor 14 | public class User { 15 | 16 | @Id 17 | @GeneratedValue(strategy = GenerationType.IDENTITY) 18 | private long id; 19 | 20 | @Column(name = "nickname") 21 | private String nickname; 22 | 23 | @Column(name = "email") 24 | private String email; 25 | 26 | @Column(name = "password") 27 | private String password; 28 | } 29 | -------------------------------------------------------------------------------- /backend/src/main/java/com/github/egnaf/spring_docker_example/exception/UserExistsException.java: -------------------------------------------------------------------------------- 1 | package com.github.egnaf.spring_docker_example.exception; 2 | 3 | public class UserExistsException extends RuntimeException { 4 | 5 | public UserExistsException() { 6 | super("User exists"); 7 | } 8 | 9 | public UserExistsException(String message) { 10 | super(message); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /backend/src/main/java/com/github/egnaf/spring_docker_example/exception/UserNotFoundException.java: -------------------------------------------------------------------------------- 1 | package com.github.egnaf.spring_docker_example.exception; 2 | 3 | public class UserNotFoundException extends RuntimeException { 4 | 5 | public UserNotFoundException() { 6 | super("User not found"); 7 | } 8 | 9 | public UserNotFoundException(String message) { 10 | super(message); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /backend/src/main/java/com/github/egnaf/spring_docker_example/repository/UserRepository.java: -------------------------------------------------------------------------------- 1 | package com.github.egnaf.spring_docker_example.repository; 2 | 3 | import com.github.egnaf.spring_docker_example.domain.User; 4 | import org.springframework.data.jpa.repository.JpaRepository; 5 | import org.springframework.stereotype.Repository; 6 | 7 | @Repository 8 | public interface UserRepository extends JpaRepository { 9 | 10 | boolean existsByEmail(String email); 11 | 12 | boolean existsByNickname(String nickname); 13 | } 14 | -------------------------------------------------------------------------------- /backend/src/main/java/com/github/egnaf/spring_docker_example/rest/UserController.java: -------------------------------------------------------------------------------- 1 | package com.github.egnaf.spring_docker_example.rest; 2 | 3 | import com.github.egnaf.spring_docker_example.domain.User; 4 | import com.github.egnaf.spring_docker_example.service.UserService; 5 | import com.github.egnaf.spring_docker_example.transfer.UserDto; 6 | import lombok.extern.slf4j.Slf4j; 7 | import org.dozer.Mapper; 8 | import org.springframework.beans.factory.annotation.Autowired; 9 | import org.springframework.web.bind.annotation.*; 10 | 11 | import java.util.List; 12 | import java.util.stream.Collectors; 13 | 14 | @Slf4j 15 | @RestController 16 | public class UserController { 17 | 18 | private final UserService userService; 19 | private final Mapper mapper; 20 | 21 | @Autowired 22 | public UserController(UserService userService, Mapper mapper) { 23 | this.userService = userService; 24 | this.mapper = mapper; 25 | } 26 | 27 | @GetMapping("/users") 28 | public List getUsers() { 29 | List users = userService.getUsers().stream() 30 | .map(user -> mapper.map(user, UserDto.class)) 31 | .collect(Collectors.toList()); 32 | log.debug(users.toString()); 33 | return users; 34 | } 35 | 36 | @GetMapping("/users/{id}") 37 | public UserDto getUser(@PathVariable long id) { 38 | UserDto user = mapper.map(userService.getUser(id), UserDto.class); 39 | log.debug(user.toString()); 40 | return user; 41 | } 42 | 43 | @PostMapping("/users") 44 | public UserDto addUser(@RequestBody User user) { 45 | UserDto newUser = mapper.map( 46 | userService.addUser(user.getNickname(), user.getEmail(), user.getPassword()), UserDto.class); 47 | log.debug(newUser.toString()); 48 | return newUser; 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /backend/src/main/java/com/github/egnaf/spring_docker_example/rest/error/ErrorHandlerController.java: -------------------------------------------------------------------------------- 1 | package com.github.egnaf.spring_docker_example.rest.error; 2 | 3 | import com.github.egnaf.spring_docker_example.exception.UserExistsException; 4 | import com.github.egnaf.spring_docker_example.exception.UserNotFoundException; 5 | import org.springframework.http.HttpStatus; 6 | import org.springframework.http.ResponseEntity; 7 | import org.springframework.web.bind.annotation.ControllerAdvice; 8 | import org.springframework.web.bind.annotation.ExceptionHandler; 9 | import org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExceptionHandler; 10 | 11 | @ControllerAdvice 12 | public class ErrorHandlerController extends ResponseEntityExceptionHandler { 13 | 14 | @ExceptionHandler(Exception.class) 15 | public ResponseEntity handleOtherException(Exception e) { 16 | return new ResponseEntity<>( 17 | new ErrorResponse(HttpStatus.INTERNAL_SERVER_ERROR.value(), e.getMessage()), 18 | HttpStatus.INTERNAL_SERVER_ERROR); 19 | } 20 | 21 | @ExceptionHandler(UserNotFoundException.class) 22 | public ResponseEntity handleNotFoundException(Exception e) { 23 | return new ResponseEntity<>( 24 | new ErrorResponse(HttpStatus.NOT_FOUND.value(), e.getMessage()), 25 | HttpStatus.NOT_FOUND); 26 | } 27 | 28 | @ExceptionHandler(UserExistsException.class) 29 | public ResponseEntity handleExistsException(Exception e) { 30 | return new ResponseEntity<>( 31 | new ErrorResponse(HttpStatus.BAD_REQUEST.value(), e.getMessage()), 32 | HttpStatus.BAD_REQUEST); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /backend/src/main/java/com/github/egnaf/spring_docker_example/rest/error/ErrorResponse.java: -------------------------------------------------------------------------------- 1 | package com.github.egnaf.spring_docker_example.rest.error; 2 | 3 | import lombok.Data; 4 | 5 | @Data 6 | class ErrorResponse { 7 | private int status; 8 | private String message; 9 | 10 | ErrorResponse(int status, String message) { 11 | this.status = status; 12 | this.message = message; 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /backend/src/main/java/com/github/egnaf/spring_docker_example/service/UserService.java: -------------------------------------------------------------------------------- 1 | package com.github.egnaf.spring_docker_example.service; 2 | 3 | import com.github.egnaf.spring_docker_example.domain.User; 4 | import com.github.egnaf.spring_docker_example.exception.UserExistsException; 5 | import com.github.egnaf.spring_docker_example.exception.UserNotFoundException; 6 | 7 | import java.util.List; 8 | 9 | public interface UserService { 10 | 11 | List getUsers(); 12 | User getUser(long id) throws UserNotFoundException; 13 | User addUser(String nickname, String email, String password) throws UserExistsException; 14 | } 15 | -------------------------------------------------------------------------------- /backend/src/main/java/com/github/egnaf/spring_docker_example/service/impl/UserServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.github.egnaf.spring_docker_example.service.impl; 2 | 3 | import com.github.egnaf.spring_docker_example.domain.User; 4 | import com.github.egnaf.spring_docker_example.exception.UserExistsException; 5 | import com.github.egnaf.spring_docker_example.exception.UserNotFoundException; 6 | import com.github.egnaf.spring_docker_example.repository.UserRepository; 7 | import com.github.egnaf.spring_docker_example.service.UserService; 8 | import lombok.extern.slf4j.Slf4j; 9 | import org.springframework.beans.factory.annotation.Autowired; 10 | import org.springframework.stereotype.Service; 11 | 12 | import java.util.List; 13 | import java.util.Optional; 14 | 15 | @Service 16 | @Slf4j 17 | public class UserServiceImpl implements UserService { 18 | 19 | private final UserRepository userRepository; 20 | 21 | @Autowired 22 | public UserServiceImpl(UserRepository userRepository) { 23 | this.userRepository = userRepository; 24 | } 25 | 26 | @Override 27 | public List getUsers() { 28 | return userRepository.findAll(); 29 | } 30 | 31 | @Override 32 | public User getUser(long id) { 33 | Optional user = userRepository.findById(id); 34 | 35 | if (user.isPresent()) { 36 | return user.get(); 37 | } else { 38 | throw new UserNotFoundException("User with id=" + id + " not found"); 39 | } 40 | } 41 | 42 | @Override 43 | public User addUser(String nickname, String email, String password) { 44 | 45 | if (userRepository.existsByEmail(email)) { 46 | throw new UserExistsException("User email=" + email + " already exists"); 47 | } else if (userRepository.existsByNickname(nickname)) { 48 | throw new UserExistsException("User nickname=" + nickname + " already exists"); 49 | } else if (password == null || password.equals("")) { 50 | throw new IllegalArgumentException(); 51 | } else { 52 | User user = new User(); 53 | user.setNickname(nickname); 54 | user.setEmail(email); 55 | user.setPassword(password); 56 | userRepository.save(user); 57 | return user; 58 | } 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /backend/src/main/java/com/github/egnaf/spring_docker_example/transfer/UserDto.java: -------------------------------------------------------------------------------- 1 | package com.github.egnaf.spring_docker_example.transfer; 2 | 3 | import lombok.Data; 4 | 5 | @Data 6 | public class UserDto { 7 | 8 | private long id; 9 | private String nickname; 10 | private String email; 11 | } 12 | -------------------------------------------------------------------------------- /backend/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8080 3 | servlet: 4 | context-path: /api/0.1 5 | 6 | spring: 7 | profiles: 8 | active: dev 9 | main: 10 | banner-mode: off 11 | datasource: 12 | driver-class-name: org.postgresql.Driver 13 | url: jdbc:postgresql://postgres:5432/demo?createDatabaseIfNotExist=true 14 | username: root 15 | password: root 16 | jpa: 17 | hibernate: 18 | ddl-auto: update 19 | show-sql: false 20 | database: postgresql 21 | database-platform: org.hibernate.dialect.PostgreSQLDialect 22 | open-in-view: false 23 | generate-ddl: false 24 | devtools: 25 | restart: 26 | enabled: true 27 | 28 | logging: 29 | pattern: 30 | console: "%d %-5level %logger : %msg%n" 31 | level: 32 | org.springframework: INFO 33 | org.hibernate: INFO 34 | -------------------------------------------------------------------------------- /backend/src/test/java/com/github/egnaf/spring_docker_example/ApplicationTest.java: -------------------------------------------------------------------------------- 1 | package com.github.egnaf.spring_docker_example; 2 | 3 | import org.springframework.boot.test.context.SpringBootTest; 4 | 5 | @SpringBootTest 6 | public class ApplicationTest { 7 | } 8 | -------------------------------------------------------------------------------- /backend/src/test/java/com/github/egnaf/spring_docker_example/repository/UserRepositoryTest.java: -------------------------------------------------------------------------------- 1 | package com.github.egnaf.spring_docker_example.repository; 2 | 3 | import com.github.egnaf.spring_docker_example.ApplicationTest; 4 | import com.github.egnaf.spring_docker_example.domain.User; 5 | import lombok.extern.slf4j.Slf4j; 6 | import org.junit.Before; 7 | import org.junit.Test; 8 | import org.junit.runner.RunWith; 9 | import org.springframework.beans.factory.annotation.Autowired; 10 | import org.springframework.test.context.junit4.SpringRunner; 11 | 12 | import static org.junit.Assert.*; 13 | 14 | @Slf4j 15 | @RunWith(SpringRunner.class) 16 | public class UserRepositoryTest extends ApplicationTest { 17 | 18 | @Autowired 19 | private UserRepository userRepository; 20 | 21 | @Before 22 | public void setUp() { 23 | User user1 = new User(1L, "user1", "user1@mail.com", "pass"); 24 | userRepository.save(user1); 25 | log.debug(user1.toString()); 26 | 27 | User user2 = new User(2L, "user2", "user2@mail.com", "test"); 28 | userRepository.save(user2); 29 | log.debug(user2.toString()); 30 | } 31 | 32 | @Test 33 | public void existsByEmailIsTrue() { 34 | //actual 35 | boolean actual = userRepository.existsByEmail("user1@mail.com"); 36 | 37 | //assert 38 | assertTrue(actual); 39 | } 40 | 41 | @Test 42 | public void existsByEmailIsFalse() { 43 | //actual 44 | boolean actual = userRepository.existsByEmail("user77@mail.com"); 45 | 46 | //assert 47 | assertFalse(actual); 48 | } 49 | 50 | @Test 51 | public void existsByNicknameIsTrue() { 52 | //actual 53 | boolean actual = userRepository.existsByNickname("user1"); 54 | 55 | //assert 56 | assertTrue(actual); 57 | } 58 | 59 | @Test 60 | public void existsByNicknameIsFalse() { 61 | //actual 62 | boolean actual = userRepository.existsByNickname("user77"); 63 | 64 | //assert 65 | assertFalse(actual); 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /backend/src/test/java/com/github/egnaf/spring_docker_example/service/impl/UserServiceImplTest.java: -------------------------------------------------------------------------------- 1 | package com.github.egnaf.spring_docker_example.service.impl; 2 | 3 | import com.github.egnaf.spring_docker_example.ApplicationTest; 4 | import com.github.egnaf.spring_docker_example.domain.User; 5 | import com.github.egnaf.spring_docker_example.exception.UserExistsException; 6 | import com.github.egnaf.spring_docker_example.exception.UserNotFoundException; 7 | import com.github.egnaf.spring_docker_example.repository.UserRepository; 8 | import com.github.egnaf.spring_docker_example.service.UserService; 9 | import lombok.extern.slf4j.Slf4j; 10 | import org.junit.Before; 11 | import org.junit.Test; 12 | import org.junit.runner.RunWith; 13 | import org.springframework.beans.factory.annotation.Autowired; 14 | import org.springframework.test.context.junit4.SpringRunner; 15 | 16 | import java.util.ArrayList; 17 | import java.util.List; 18 | 19 | import static org.junit.Assert.assertEquals; 20 | 21 | @Slf4j 22 | @RunWith(SpringRunner.class) 23 | public class UserServiceImplTest extends ApplicationTest { 24 | 25 | @Autowired 26 | private UserRepository userRepository; 27 | 28 | @Autowired 29 | private UserService userService; 30 | 31 | @Before 32 | public void setUp() { 33 | User user1 = new User(1L, "user1", "user1@mail.com", "pass"); 34 | userRepository.save(user1); 35 | log.debug(user1.toString()); 36 | 37 | User user2 = new User(2L, "user2", "user2@mail.com", "test"); 38 | userRepository.save(user2); 39 | log.debug(user2.toString()); 40 | } 41 | 42 | @Test 43 | public void getUsers() { 44 | //expected 45 | List expected = new ArrayList<>(); 46 | expected.add(new User(1L, "user1", "user1@mail.com", "pass")); 47 | expected.add(new User(2L, "user2", "user2@mail.com", "test")); 48 | 49 | //actual 50 | List actual = userService.getUsers(); 51 | 52 | //assert 53 | assertEquals(expected, actual); 54 | } 55 | 56 | @Test 57 | public void getUser() throws UserNotFoundException { 58 | //expected 59 | User expected = new User(1L, "user1", "user1@mail.com", "pass"); 60 | 61 | //actual 62 | User actual = userService.getUser(1L); 63 | 64 | //assert 65 | assertEquals(expected, actual); 66 | } 67 | 68 | @Test 69 | public void addUser() throws UserExistsException { 70 | //expected 71 | User expected = new User(3L, "user3", "user3@mail.com", "demo"); 72 | 73 | //actual 74 | User actual = userService.addUser(expected.getNickname(), expected.getEmail(), expected.getPassword()); 75 | userRepository.deleteById(3L); 76 | 77 | //assert 78 | assertEquals(expected, actual); 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /backend/src/test/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8080 3 | servlet: 4 | context-path: /api/0.1 5 | 6 | spring: 7 | profiles: 8 | active: dev 9 | main: 10 | banner-mode: off 11 | datasource: 12 | driver-class-name: org.h2.Driver 13 | url: jdbc:h2:mem:testdb 14 | username: sa 15 | password: password 16 | jpa: 17 | hibernate: 18 | ddl-auto: create-drop 19 | show-sql: false 20 | database: postgresql 21 | database-platform: org.hibernate.dialect.H2Dialect 22 | open-in-view: false 23 | generate-ddl: false 24 | h2: 25 | console: 26 | enabled: true 27 | 28 | logging: 29 | pattern: 30 | console: "%d %-5level %logger : %msg%n" 31 | level: 32 | org.springframework: INFO 33 | org.hibernate: INFO 34 | -------------------------------------------------------------------------------- /codecov.yml: -------------------------------------------------------------------------------- 1 | codecov: 2 | require_ci_to_pass: true 3 | 4 | coverage: 5 | precision: 2 6 | round: down 7 | range: "70...100" 8 | 9 | status: 10 | project: true 11 | patch: yes 12 | changes: no 13 | 14 | parsers: 15 | gcov: 16 | branch_detection: 17 | conditional: yes 18 | loop: yes 19 | method: no 20 | macro: no 21 | 22 | comment: 23 | layout: diff 24 | behavior: default 25 | require_changes: false 26 | -------------------------------------------------------------------------------- /docker-compose.yml: -------------------------------------------------------------------------------- 1 | version: '3' 2 | services: 3 | postgres: 4 | container_name: postgres 5 | image: postgres:latest 6 | ports: 7 | - "5432:5000" 8 | environment: 9 | - POSTGRES_DB=demo 10 | - POSTGRES_USER=root 11 | - POSTGRES_PASSWORD=root 12 | backend: 13 | container_name: backend 14 | build: ./backend 15 | ports: 16 | - "8080:5001" 17 | depends_on: 18 | - postgres 19 | frontend: 20 | container_name: frontend 21 | build: ./frontend 22 | ports: 23 | - "3000:5002" 24 | depends_on: 25 | - backend 26 | nginx: 27 | container_name: nginx 28 | image: proxy 29 | build: ./.nginx 30 | depends_on: 31 | - backend 32 | - frontend 33 | ports: 34 | - 80:80 35 | - 443:443 36 | -------------------------------------------------------------------------------- /frontend/.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | node_modules 3 | /dist 4 | 5 | # local env files 6 | .env.local 7 | .env.*.local 8 | 9 | # Log files 10 | npm-debug.log* 11 | yarn-debug.log* 12 | yarn-error.log* 13 | 14 | # Editor directories and files 15 | .idea 16 | .vscode 17 | *.suo 18 | *.ntvs* 19 | *.njsproj 20 | *.sln 21 | *.sw? 22 | -------------------------------------------------------------------------------- /frontend/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM node:lts-alpine 2 | RUN npm install -g http-server 3 | WORKDIR /app/frontend 4 | COPY package*.json ./ 5 | RUN npm install --production 6 | COPY . . 7 | RUN npm run build 8 | CMD ["http-server", "dist", "-p", "3000"] 9 | -------------------------------------------------------------------------------- /frontend/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "frontend", 3 | "version": "0.1.0", 4 | "private": true, 5 | "scripts": { 6 | "serve": "vue-cli-service serve", 7 | "build": "vue-cli-service build", 8 | "lint": "vue-cli-service lint" 9 | }, 10 | "dependencies": { 11 | "core-js": "^3.3.2", 12 | "vue": "^2.6.10" 13 | }, 14 | "devDependencies": { 15 | "@vue/cli-plugin-babel": "^4.0.0", 16 | "@vue/cli-plugin-eslint": "^4.0.0", 17 | "@vue/cli-service": "^4.0.0", 18 | "babel-eslint": "^10.0.3", 19 | "eslint": "^5.16.0", 20 | "eslint-plugin-vue": "^5.0.0", 21 | "vue-template-compiler": "^2.6.10" 22 | }, 23 | "eslintConfig": { 24 | "root": true, 25 | "env": { 26 | "node": true 27 | }, 28 | "extends": [ 29 | "plugin:vue/essential", 30 | "eslint:recommended" 31 | ], 32 | "rules": {}, 33 | "parserOptions": { 34 | "parser": "babel-eslint" 35 | } 36 | }, 37 | "postcss": { 38 | "plugins": { 39 | "autoprefixer": {} 40 | } 41 | }, 42 | "browserslist": [ 43 | "> 1%", 44 | "last 2 versions" 45 | ] 46 | } 47 | -------------------------------------------------------------------------------- /frontend/public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mamadaliev/spring-boot-postgres-vue-docker/0b52c879dae35276e7e69ad442e46893aac48e97/frontend/public/favicon.ico -------------------------------------------------------------------------------- /frontend/public/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | frontend 9 | 10 | 11 | 14 |
15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /frontend/src/App.vue: -------------------------------------------------------------------------------- 1 | 7 | 8 | 18 | 19 | 29 | -------------------------------------------------------------------------------- /frontend/src/assets/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mamadaliev/spring-boot-postgres-vue-docker/0b52c879dae35276e7e69ad442e46893aac48e97/frontend/src/assets/logo.png -------------------------------------------------------------------------------- /frontend/src/components/HelloWorld.vue: -------------------------------------------------------------------------------- 1 | 32 | 33 | 41 | 42 | 43 | 59 | -------------------------------------------------------------------------------- /frontend/src/main.js: -------------------------------------------------------------------------------- 1 | import Vue from 'vue' 2 | import App from './App.vue' 3 | 4 | Vue.config.productionTip = false; 5 | 6 | new Vue({ 7 | render: h => h(App), 8 | }).$mount('#app'); 9 | -------------------------------------------------------------------------------- /start.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | cd backend && mvn clean install && cd .. 4 | 5 | docker-compose down 6 | docker-compose build 7 | docker-compose up 8 | --------------------------------------------------------------------------------