Skip to content

Commit c43c90d

Browse files
committed
Dockerfile + docker-compose
1 parent c3b18e3 commit c43c90d

File tree

7 files changed

+29
-7
lines changed

7 files changed

+29
-7
lines changed

Dockerfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
FROM lganzzzo/alpine-cmake:latest
22

3+
RUN apk add postgresql-dev
4+
35
ADD . /service
46

57
WORKDIR /service/build

docker-compose.yaml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
version: '3'
2+
3+
services:
4+
db:
5+
image: postgres
6+
restart: always
7+
environment:
8+
POSTGRES_PASSWORD: db-pass
9+
example-postgresql:
10+
build: .
11+
ports:
12+
- "8000:8000"
13+
links:
14+
- "db"
15+
environment:
16+
CONFIG_PROFILE: local-docker

main/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ add_definitions(
4747

4848
include(FindPkgConfig)
4949

50-
set(ENV{PKG_CONFIG_PATH} "/usr/local/pgsql/lib/pkgconfig") ## change this if needed
50+
set(ENV{PKG_CONFIG_PATH} "/usr/local/pgsql/lib/pkgconfig:$ENV{PKG_CONFIG_PATH}") ## change this if needed
5151

5252
pkg_check_modules(PKG_PQ REQUIRED libpq)
5353

main/resources/config.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"local-docker": {
1111
"port": 8000,
1212
"swaggerHost": "localhost:8000",
13-
"dbHost": "localhost",
13+
"dbHost": "db",
1414
"dbUser": "postgres",
1515
"dbPass": "db-pass",
1616
"dbName": "postgres"

main/src/AppComponent.hpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
#include "oatpp/core/base/CommandLineArguments.hpp"
1818

19-
#include <fstream>
19+
#include <cstdlib>
2020

2121
class AppComponent {
2222
private:
@@ -39,7 +39,11 @@ class AppComponent {
3939
if (configText) {
4040

4141
auto profiles = objectMapper->readFromString<ConfigDto::Fields<ConfigDto::ObjectWrapper>>(configText);
42-
const char* profileArg = m_cmdArgs.getNamedArgumentValue("--profile", "dev");
42+
43+
const char *profileArg = std::getenv("CONFIG_PROFILE"); // first read from env variable
44+
if (profileArg == nullptr) {
45+
profileArg = m_cmdArgs.getNamedArgumentValue("--profile", "dev"); // if no env varioable get from command line
46+
}
4347

4448
OATPP_LOGD("Server", "Loading configuration profile '%s'", profileArg);
4549

main/src/db/Database.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ const char* Database::DDL =
3030

3131
const char* Database::SQL_INSERT_USER =
3232
"INSERT INTO EXAMPLE_USER "
33-
"(userId, login, password, email, authType) VALUES "
33+
"(userId, login, password, email) VALUES "
3434
"(uuid_generate_v4(), $1::varchar, $2::varchar, $3::varchar) "
3535
"RETURNING *;";
3636

@@ -123,7 +123,7 @@ UserDto::ObjectWrapper Database::createUser(const UserDto::ObjectWrapper& user)
123123
std::lock_guard<std::mutex> lock(m_mutex);
124124
tryReconnect();
125125
UserDto::ObjectWrapper createdUser;
126-
const v_int32 paramsNumber = 4;
126+
const v_int32 paramsNumber = 3;
127127
const char* params[paramsNumber] = {user->login->c_str(), user->password->c_str(), user->email->c_str()};
128128
ResultWrapper result = PQexecParams(m_connection, SQL_INSERT_USER, paramsNumber, nullptr, params, nullptr, nullptr, 0);
129129
if (checkResultOrThrow(result)) {

main/src/dto/ErrorDto.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class ErrorDto : public oatpp::data::mapping::type::Object {
1818

1919
DTO_INIT(ErrorDto, Object)
2020

21-
DTO_FIELD(String, service) = "user-service";
21+
DTO_FIELD(String, service) = "example-postgresql: user-service";
2222
DTO_FIELD(Int32, code);
2323
DTO_FIELD(String, error);
2424
DTO_FIELD(String, message);

0 commit comments

Comments
 (0)