Commit 49514e17 authored by Shanelle Valencia's avatar Shanelle Valencia

Add docker exercise

parent d320cc33
File added
# copy and run jar
FROM openjdk:8-jre-slim
EXPOSE 8080
WORKDIR /app
COPY build/libs/employeeservice-0.0.1-SNAPSHOT.jar employeeservice-0.0.1-SNAPSHOT.jar
ENTRYPOINT ["java", "-jar", "/app/employeeservice-0.0.1-SNAPSHOT.jar"]
FROM postgres
COPY src/main/resources/employee.sql /docker-entrypoint-initdb.d/
\ No newline at end of file
...@@ -21,7 +21,10 @@ dependencies { ...@@ -21,7 +21,10 @@ dependencies {
implementation 'junit:junit:4.12' implementation 'junit:junit:4.12'
runtimeOnly 'com.h2database:h2' runtimeOnly 'com.h2database:h2'
testImplementation 'org.springframework.boot:spring-boot-starter-test' testImplementation 'org.springframework.boot:spring-boot-starter-test'
testImplementation 'com.h2database:h2' // testImplementation 'com.h2database:h2'
// https://mvnrepository.com/artifact/org.postgresql/postgresql
implementation group: 'org.postgresql', name: 'postgresql', version: '42.1.4'
} }
test { test {
......
version: "3.5"
services:
employee-service:
container_name: employeedocker
image: employee-service
build: Dockerfile
ports:
- "3000:8080"
depends_on:
- postgresdb
postgresdb:
container_name: pg_container
restart: always
image: postgres
volumes:
- "./pgdata:/var/lib/postgresql/data/pgdata"
# - ./src/main/resources/employee.sql:/docker-entrypoint-initdb.d/employee.sql
- ./init.sql:/docker-entrypoint-initdb.d/init.sql
environment:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: admin
POSTGRES_DB: postgres
ports:
- "5432:5432"
# pgadmin:
# container_name: pgadmin4_container
# image: dpage/pgadmin4
# restart: always
# environment:
# PGADMIN_DEFAULT_EMAIL: admin@admin.com
# PGADMIN_DEFAULT_PASSWORD: root
# ports:
# - "5050:80"
DROP TABLE IF EXISTS EMPLOYEE;
CREATE TABLE EMPLOYEE (
ID INT AUTO_INCREMENT PRIMARY KEY,
FIRST_NAME VARCHAR (255) NOT NULL,
LAST_NAME VARCHAR (255) NOT NULL
);
INSERT INTO EMPLOYEE VALUES
( 1, 'John', 'Smith' ),
(2, 'Jane', 'Doe'),
(3, 'Walter', 'Bell')
(4, 'Amanda', 'Seyfried')
(5, 'Barney', 'Stinson');
\ No newline at end of file
File added
...@@ -55,7 +55,7 @@ public class EmployeeController { ...@@ -55,7 +55,7 @@ public class EmployeeController {
@PutMapping("/employees/{id}") @PutMapping("/employees/update/{id}")
public ResponseEntity<Employee> updateEmployee(@PathVariable(value = "id") Long employeeId, public ResponseEntity<Employee> updateEmployee(@PathVariable(value = "id") Long employeeId,
@RequestBody Employee employeeDetails) throws ResourceNotFoundException { @RequestBody Employee employeeDetails) throws ResourceNotFoundException {
Employee employee = employeeService.getEmployeeById(employeeId) Employee employee = employeeService.getEmployeeById(employeeId)
...@@ -67,7 +67,7 @@ public class EmployeeController { ...@@ -67,7 +67,7 @@ public class EmployeeController {
@DeleteMapping("/employees/{id}") @DeleteMapping("/employees/delete/{id}")
public Map<String, Boolean> deleteEmployee(@PathVariable(value = "id") Long employeeId) throws ResourceNotFoundException { public Map<String, Boolean> deleteEmployee(@PathVariable(value = "id") Long employeeId) throws ResourceNotFoundException {
Employee employee = employeeService.getEmployeeById(employeeId) Employee employee = employeeService.getEmployeeById(employeeId)
.orElseThrow(() -> new ResourceNotFoundException("Employee not found for this id :: " + employeeId)); .orElseThrow(() -> new ResourceNotFoundException("Employee not found for this id :: " + employeeId));
......
spring.datasource.url=jdbc:h2:mem:dataSource #spring.datasource.url=jdbc:h2:mem:dataSource
spring.datasource.driverClassName=org.h2.Driver #spring.datasource.driverClassName=org.h2.Driver
spring.datasource.username=sa #spring.datasource.username=sa
spring.datasource.password= #spring.datasource.password=
spring.datasource.schema=classpath:employee.sql spring.datasource.schema=classpath:employee.sql
#spring.jpa.database-platform=org.hibernate.dialect.H2Dialect
#spring.jpa.hibernate.ddl-auto=none
#spring.h2.console.enabled=true
spring.jpa.database-platform=org.hibernate.dialect.H2Dialect
# Postgres
spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.PostgreSQLDialect
spring.jpa.hibernate.ddl-auto=none spring.jpa.hibernate.ddl-auto=none
spring.h2.console.enabled=true spring.jpa.hibernate.show-sql=true
spring.datasource.url=jdbc:postgresql://postgresdb:5432/postgres
spring.datasource.platform=postgres
spring.datasource.driver-class-name=org.postgresql.Driver
spring.datasource.username=postgres
spring.datasource.password=admin
# postgres
spring.jpa.show-sql=true
management.endpoint.beans.enabled=true management.endpoint.beans.enabled=true
management.endpoints.web.exposure.include=* management.endpoints.web.exposure.include=*
......
DROP TABLE IF EXISTS EMPLOYEE; --DROP TABLE IF EXISTS EMPLOYEE;
--
CREATE TABLE EMPLOYEE ( --CREATE TABLE EMPLOYEE (
ID INT AUTO_INCREMENT PRIMARY KEY, -- ID INT AUTO_INCREMENT PRIMARY KEY,
FIRST_NAME VARCHAR (255) NOT NULL, -- FIRST_NAME VARCHAR (255) NOT NULL,
LAST_NAME VARCHAR (255) NOT NULL -- LAST_NAME VARCHAR (255) NOT NULL
); --);
--
INSERT INTO EMPLOYEE VALUES --INSERT INTO EMPLOYEE VALUES
( 1, 'John', 'Smith' ), -- ( 1, 'John', 'Smith' ),
(2, 'Jane', 'Doe'), -- (2, 'Jane', 'Doe'),
(3, 'Walter', 'Bell'); -- (3, 'Walter', 'Bell')
\ No newline at end of file -- (4, 'Amanda', 'Seyfried')
-- (5, 'Barney', 'Stinson');
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment