Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
[![Build Status](https://travis-ci.org/egnaf/spring-boot-docker-examples.svg)](https://travis-ci.org/egnaf/spring-boot-postgres-docker)
[![Build Status](https://travis-ci.org/egnaf/spring-boot-docker-samples.svg)](https://travis-ci.org/egnaf/spring-boot-postgres-docker)

# spring-boot-docker-examples
# spring-boot-docker-samples

## Installation
Change directory path to project directory with `cd`, build services and run in containers with run the `start.sh`.
```bash
$ cd path-to-project/ # change directory path to project path
$ ./start.sh # build services and run in containers
$ cd project-name
$ ./start.sh
```

## Contribute
Expand Down
4 changes: 2 additions & 2 deletions spring-boot-postgres-vue/backend/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
FROM openjdk:8-jdk-alpine
VOLUME /tmp
EXPOSE 6565
RUN mkdir -p /app/
RUN mkdir -p /app/logs/
ADD target/app-1.0.jar /app/app.jar
ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-Dspring.profiles.active=container", "-jar", "/app/app.jar"]
EXPOSE 2000
ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-Dspring.profiles.active=container", "-jar", "/app/app.jar"]
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.company.app;

import com.company.app.service.HumanService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
Expand All @@ -11,7 +10,6 @@ public class DemoApplication {

private final HumanService humanService;

@Autowired
public DemoApplication(HumanService humanService) {
this.humanService = humanService;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import com.company.app.entity.HumanEntity;
import com.company.app.service.HumanService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

Expand All @@ -13,7 +12,6 @@ public class HumanController {

private final HumanService humanService;

@Autowired
public HumanController(HumanService humanService) {
this.humanService = humanService;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import com.company.app.entity.HumanEntity;
import com.company.app.repository.HumanRepository;
import com.company.app.service.HumanService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
Expand All @@ -13,7 +12,6 @@ public class HumanServiceImpl implements HumanService {

private final HumanRepository humanRepository;

@Autowired
public HumanServiceImpl(HumanRepository humanRepository) {
this.humanRepository = humanRepository;
}
Expand Down
9 changes: 6 additions & 3 deletions spring-boot-postgres-vue/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,23 +1,26 @@
version: '3'

services:
database:
restart: always
image: postgres:latest
ports:
- "6564:5432"
- "1000:5432"
environment:
- POSTGRES_DB=demo
- POSTGRES_USER=root
- POSTGRES_PASSWORD=root

backend:
build: ./backend/
ports:
- 6565:8080
- "2000:8080"
depends_on:
- database

frontend:
build: ./frontend/
ports:
- 5555:3000
- "3000:3000"
depends_on:
- backend
15 changes: 1 addition & 14 deletions spring-boot-postgres-vue/frontend/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,22 +1,9 @@
FROM node:lts-alpine

# install simple http server for serving static content
RUN npm install -g http-server

# make the 'app' folder the current working directory
WORKDIR /app

# copy both 'package.json' and 'package-lock.json' (if available)
COPY package*.json ./

# install project dependencies leaving out dev dependencies
RUN npm install --production

# copy project files and folders to the current working directory (i.e. 'app' folder)
COPY . .

# build app for production with minification
RUN npm run build

EXPOSE 3000
CMD [ "http-server", "dist" ]
CMD ["http-server", "dist", "-p", "3000"]
3 changes: 3 additions & 0 deletions spring-boot-postgres-vue/start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
cd ./backend/ && mvn clean install && cd ..

## stop and remove containers created by 'docker-compose up'
docker-compose down

# build services
docker-compose build

# create and run containers for services
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
package com.company.app.controller;

import com.company.app.entity.HumanEntity;
import com.company.app.entity.Human;
import com.company.app.service.HumanService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

Expand All @@ -13,13 +12,12 @@ public class HumanController {

private final HumanService humanService;

@Autowired
public HumanController(HumanService humanService) {
this.humanService = humanService;
}

@GetMapping(value = "/humans")
public List<HumanEntity> getAll() {
public List<Human> getAll() {
return humanService.getAll();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

@Entity
@Table(name = "humans")
public class HumanEntity {
public class Human {

@Basic
@Column(name = "id")
Expand All @@ -20,10 +20,10 @@ public class HumanEntity {
@Column(name = "age")
private int age;

public HumanEntity() {
public Human() {
}

public HumanEntity(String nickname, int age) {
public Human(String nickname, int age) {
this.nickname = nickname;
this.age = age;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package com.company.app.repository;

import com.company.app.entity.HumanEntity;
import com.company.app.entity.Human;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;

@Repository
public interface HumanRepository extends JpaRepository<HumanEntity, Integer> {
public interface HumanRepository extends JpaRepository<Human, Integer> {
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package com.company.app.service;

import com.company.app.entity.HumanEntity;
import com.company.app.entity.Human;

import java.util.List;

public interface HumanService {

List<HumanEntity> getAll();
HumanEntity getOneById(Integer id);
List<Human> getAll();
Human getOneById(Integer id);
void create(String nickname, int age);
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
package com.company.app.service.impl;

import com.company.app.entity.HumanEntity;
import com.company.app.entity.Human;
import com.company.app.repository.HumanRepository;
import com.company.app.service.HumanService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
Expand All @@ -13,23 +12,22 @@ public class HumanServiceImpl implements HumanService {

private final HumanRepository humanRepository;

@Autowired
public HumanServiceImpl(HumanRepository humanRepository) {
this.humanRepository = humanRepository;
}

@Override
public List<HumanEntity> getAll() {
public List<Human> getAll() {
return humanRepository.findAll();
}

@Override
public HumanEntity getOneById(Integer id) {
public Human getOneById(Integer id) {
return humanRepository.getOne(id);
}

@Override
public void create(String nickname, int age) {
humanRepository.save(new HumanEntity(nickname, age));
humanRepository.save(new Human(nickname, age));
}
}