-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Smayorov back helloworld #7
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
.idea/ | ||
back/target/ |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
## Run dev env | ||
1. Install Docker and docker-compose | ||
2. run this command (from project root): | ||
```console | ||
docker-compose up -d | ||
``` | ||
3. To clear the env run: | ||
```console | ||
docker-compose down | ||
``` |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<groupId>ru.gowork</groupId> | ||
<artifactId>back</artifactId> | ||
<version>1.0-SNAPSHOT</version> | ||
|
||
<packaging>jar</packaging> | ||
|
||
<properties> | ||
<nab.version>4.22.20</nab.version> | ||
</properties> | ||
|
||
<repositories> | ||
<repository> | ||
<id>hh-public</id> | ||
<name>hh public releases repository</name> | ||
<url>http://m2.hh.ru/content/repositories/public-releases</url> | ||
<releases> | ||
<enabled>true</enabled> | ||
</releases> | ||
<snapshots> | ||
<enabled>false</enabled> | ||
</snapshots> | ||
</repository> | ||
</repositories> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>ru.hh.nab</groupId> | ||
<artifactId>nab-starter</artifactId> | ||
<version>${nab.version}</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>ru.hh.nab</groupId> | ||
<artifactId>nab-hibernate</artifactId> | ||
<version>${nab.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>ru.hh.nab</groupId> | ||
<artifactId>nab-testbase</artifactId> | ||
<version>${nab.version}</version> | ||
<scope>test</scope> | ||
</dependency> | ||
</dependencies> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-compiler-plugin</artifactId> | ||
<version>3.8.0</version> | ||
<configuration> | ||
<release>11</release> | ||
<showDeprecation>true</showDeprecation> | ||
</configuration> | ||
</plugin> | ||
|
||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-shade-plugin</artifactId> | ||
<version>3.2.2</version> | ||
<configuration> | ||
<finalName>${project.artifactId}</finalName> | ||
<transformers> | ||
<transformer | ||
implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer"/> | ||
<transformer | ||
implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer"> | ||
<manifestEntries> | ||
<Main-Class>ru.gowork.App</Main-Class> | ||
</manifestEntries> | ||
</transformer> | ||
</transformers> | ||
<filters> | ||
<filter> | ||
<artifact>*:*</artifact> | ||
<excludes> | ||
<exclude>META-INF/*.SF</exclude> | ||
<exclude>META-INF/*.DSA</exclude> | ||
<exclude>META-INF/*.RSA</exclude> | ||
</excludes> | ||
</filter> | ||
</filters> | ||
</configuration> | ||
<executions> | ||
<execution> | ||
<phase>package</phase> | ||
<goals> | ||
<goal>shade</goal> | ||
</goals> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
|
||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-surefire-plugin</artifactId> | ||
<configuration> | ||
<systemPropertyVariables> | ||
<settingsDir>${basedir}/src/etc</settingsDir> | ||
</systemPropertyVariables> | ||
</configuration> | ||
</plugin> | ||
<plugin> | ||
<groupId>org.codehaus.mojo</groupId> | ||
<artifactId>exec-maven-plugin</artifactId> | ||
<version>1.6.0</version> | ||
<executions> | ||
<execution> | ||
<goals> | ||
<goal>java</goal> | ||
</goals> | ||
</execution> | ||
</executions> | ||
<configuration> | ||
<systemProperties> | ||
<systemProperty> | ||
<key>settingsDir</key> | ||
<value>src/etc</value> | ||
</systemProperty> | ||
</systemProperties> | ||
<mainClass>ru.gowork.App</mainClass> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</project> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
serviceName=backend | ||
datacenter=testDC | ||
|
||
jetty.port=8080 | ||
|
||
log.immediate.flush=true | ||
log.toConsole=true | ||
log.timings=false | ||
|
||
consul.http.host=127.0.0.1 | ||
consul.http.port=13100 | ||
consul.check.host=127.0.0.1 | ||
consul.check.timeout=5s | ||
consul.check.interval=5s | ||
consul.tags=nab,nab-example | ||
consul.enabled=false |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package ru.gowork; | ||
|
||
import ru.gowork.resource.ExampleResource; | ||
import ru.hh.nab.common.properties.PropertiesUtils; | ||
import ru.hh.nab.starter.NabApplication; | ||
import ru.gowork.config.ProdConfig; | ||
|
||
public class App { | ||
|
||
public static void main(String[] args) { | ||
// System.setProperty(PropertiesUtils.SETINGS_DIR_PROPERTY, "back/src/etc"); | ||
NabApplication | ||
.builder() | ||
.configureJersey().addAllowedPackages("ru.gowork") | ||
.bindToRoot() | ||
.build() | ||
.run(ProdConfig.class); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package ru.gowork.config; | ||
|
||
import io.sentry.logback.SentryAppender; | ||
import org.slf4j.event.Level; | ||
import ru.hh.nab.logging.HhMultiAppender; | ||
import ru.hh.nab.starter.NabLogbackBaseConfigurator; | ||
|
||
public class LogbackConfigurator extends NabLogbackBaseConfigurator { | ||
@Override | ||
public void configure(LoggingContextWrapper context, HhMultiAppender service, HhMultiAppender libraries, SentryAppender sentry) { | ||
getRootLogger(context).setLevel(Level.INFO); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package ru.gowork.config; | ||
|
||
import ru.gowork.resource.ExampleResource; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.context.annotation.Import; | ||
import ru.hh.nab.starter.NabProdConfig; | ||
|
||
@Configuration | ||
@Import({ | ||
ExampleResource.class, | ||
NabProdConfig.class | ||
}) | ||
public class ProdConfig { | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package ru.gowork.entity; | ||
|
||
public class HelloWorldEntity { | ||
private final String HELLO_STRING = "Hello, "; | ||
private final String EXCLAMATION_MARK = "!"; | ||
private String name; | ||
|
||
public HelloWorldEntity(String name) { | ||
this.name = name; | ||
} | ||
|
||
public synchronized String getString() { | ||
return HELLO_STRING + name + EXCLAMATION_MARK; | ||
} | ||
|
||
public synchronized void setName(String name) { | ||
if (name != null) { | ||
this.name = name; | ||
} | ||
} | ||
|
||
public synchronized void deleteName() { | ||
this.name = ""; | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package ru.gowork.resource; | ||
|
||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import ru.gowork.entity.HelloWorldEntity; | ||
|
||
import javax.inject.Singleton; | ||
import javax.ws.rs.*; | ||
import javax.ws.rs.core.Response; | ||
|
||
@Singleton | ||
@Path("/") | ||
public class ExampleResource { | ||
|
||
private static final Logger logger = LoggerFactory.getLogger(ExampleResource.class); | ||
private HelloWorldEntity helloWorldEntity = new HelloWorldEntity("world"); | ||
|
||
@GET | ||
public Response get() { | ||
logger.info("Print " + helloWorldEntity.getString()); | ||
return Response.ok(helloWorldEntity.getString()).build(); | ||
} | ||
|
||
@POST | ||
public Response post(@QueryParam(value = "name") String name) { | ||
logger.info("Set input name: " + name); | ||
helloWorldEntity.setName(name); | ||
return Response.ok().build(); | ||
} | ||
|
||
@DELETE | ||
public Response delete() { | ||
logger.info("Delete name"); | ||
helloWorldEntity.deleteName(); | ||
return Response.ok().build(); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
ru.gowork.config.LogbackConfigurator |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
version: '3.4' | ||
|
||
services: | ||
postgres: | ||
image: postgres:13.2-alpine | ||
restart: always | ||
volumes: | ||
- ./back/migrations/:/docker-entrypoint-initdb.d/ | ||
ports: | ||
- "5432:5432" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Если линкуешь делаешь связь контейнеров через link, то выставлять порты не обязательно There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Да, но ports в такой форме еще пробрасывает порт на хост. Иногда может пригодится присоединится к постгресу в конейнере с хоста. Например хостовым клиентом psql посмотреть на таблички. |
||
environment: | ||
POSTGRES_PASSWORD: hh | ||
POSTGRES_DB: hh | ||
POSTGRES_USER: hh | ||
healthcheck: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Вопрос - depends_on бекенда будет дожидаться когда сработает healthcheck в бд? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Нет, не будет т.к. в V3 выпилили кондишены в depends_on. Но здесь это разруливается restart: always (docker/compose#4305 (comment)) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. годится |
||
test: ["CMD-SHELL", "pg_isready -U hh"] | ||
interval: 10s | ||
timeout: 5s | ||
retries: 5 | ||
|
||
back: | ||
image: maven:3.6.3-jdk-11 | ||
restart: always | ||
working_dir: /mnt/app | ||
command: mvn install exec:java | ||
volumes: | ||
- gowork-back-maven-repo:/root/.m2 | ||
- ./back:/mnt/app:Z | ||
ports: | ||
- "8080:8080" | ||
links: | ||
- postgres | ||
depends_on: | ||
- postgres | ||
healthcheck: | ||
test: ["CMD", "curl", "-f", "http://localhost:8080/status"] | ||
interval: 10s | ||
timeout: 5s | ||
retries: 5 | ||
start_period: 180s # first start may be long due to downloading dependencies | ||
front: | ||
build: ./front | ||
ports: | ||
- "3000:80" | ||
links: | ||
- back | ||
depends_on: | ||
- back | ||
volumes: | ||
gowork-back-maven-repo: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
можно сделать extends из back, и на pg и на back сервисы
или, если вам бэк отдельно от фронта будет ненужен, можно вобще тогда из back удалить compose
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Extends вроде тоже выпилили в V3(
https://docs.docker.com/compose/extends/#extending-services
Я бы хотел запускать бэк отдельно потому что это быстрее, но это вроде можно сделать и без отдельного компоуз файла (передать конкретные сервисы для запуска). Так что я за удаление.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Готово