forked from ebhomengo/niki
1
0
Fork 0

refactor(niki): stage deployment docker setup (#130)

This commit is contained in:
Ruhollah 2024-08-28 00:06:38 +03:30 committed by ErfanTech
parent 4f4ae64100
commit 3fb173036e
13 changed files with 71 additions and 119 deletions

1
.gitignore vendored
View File

@ -20,6 +20,7 @@ activate.mise.toml
# Dependency directories (remove the comment below to include it)
.idea
bin
tmp
#.env
*.env

View File

@ -1,18 +1,12 @@
# Build Stage
# First pull Golang image
FROM golang:1.23.0-alpine as builder
FROM golang:1.23.0-alpine AS builder
# Set environment variable
ENV APP_NAME niki
ENV CMD_PATH main.go
# Add a work directory
WORKDIR /$APP_NAME
## Cache and install dependencies
#COPY go.mod go.sum ./
#RUN go mod download
# Copy app files
COPY . .
@ -20,18 +14,16 @@ COPY . .
RUN CGO_ENABLED=0 go build -mod=vendor -v -o $APP_NAME .
# Run Stage
FROM alpine:3.20 AS runtime
FROM alpine:3.20 as Runtime
# Copy the binary from the builder stage
COPY --from=builder /niki/niki .
# Copy migration files
COPY --from=builder /niki/repository/mysql/migration ./repository/mysql/migration
# Set environment variable
ENV APP_NAME niki
# Copy only required data into this image
COPY --from=builder /$APP_NAME .
# Expose application port
EXPOSE 8313
# Start app
CMD ./$APP_NAME
# Start the application
CMD ["./niki", "--migrate"]

View File

@ -20,10 +20,6 @@ redis:
password: ""
db: 0
sms_provider:
host: localhost
port: 443
benefactor_service:
length_of_otp_code: 5

View File

@ -0,0 +1,11 @@
COMPOSE_MARIADB_PORT=3306
COMPOSE_MARIADB_DATABASE=niki_db
COMPOSE_MARIADB_USER=niki
COMPOSE_MARIADB_UR_PASSWORD=n0ki2agd23
COMPOSE_REDIS_PORT=6379
COMPOSE_REDIS_DB=0
COMPOSE_REDIS_PASSWORD=n0ki2agd23
COMPOSE_AUTH_SIGN_KEY=jwt_secret_stage_nik
COMPOSE_ADMIN_AUTH_SIGN_KEY=admin-jwt_secret_stage_nik

View File

@ -0,0 +1,12 @@
---
type: yml
http_server:
port: 1313
benefactor_service:
length_of_otp_code: 5
kavenegar_sms_provider:
api_key: insert_your_api_key
sender: insert_sender_number

View File

@ -1,12 +1,26 @@
version: '3.7'
version: '3.9'
services:
niki_app_stage:
image: niki:${STAGE_NIKI_IMAGE_VERSION}
image: niki:${STAGE_NIKI_IMAGE_VERSION?error}
container_name: niki_app_stage
environment:
EB_MARIADB__HOST: niki_stage_mariadb
EB_MARIADB__PORT: ${COMPOSE_MARIADB_PORT?error}
EB_MARIADB__DB_NAME: ${COMPOSE_MARIADB_DATABASE?error}
EB_MARIADB__USERNAME: ${COMPOSE_MARIADB_USER?error}
EB_MARIADB__PASSWORD: ${COMPOSE_MARIADB_UR_PASSWORD?error}
EB_REDIS__HOST: niki_stage_redis
EB_REDIS__PORT: ${COMPOSE_REDIS_PORT?error}
EB_REDIS__DB: ${COMPOSE_REDIS_DB?error}
EB_REDIS__PASSWORD: ${COMPOSE_REDIS_PASSWORD?error}
EB_AUTH__SIGN_KEY: ${COMPOSE_AUTH_SIGN_KEY?error}
EB_ADMIN_AUTH__SIGN_KEY: ${COMPOSE_ADMIN_AUTH_SIGN_KEY?error}
restart: always
ports:
- '127.0.0.1:8198:1313'
- "127.0.0.1:8313:1313"
networks:
- niki-stage
volumes:

View File

@ -1,36 +0,0 @@
---
type: yml
auth:
sign_key: jwt_secret_stage_nik
http_server:
port: 1313
mysql:
port: 3306
host: niki_stage_mariadb
db_name: niki_db
username: niki
password: n0ki2agd23
redis:
port: 6379
host: niki_stage_redis
password: ""
db: 0
sms_provider:
host: localhost
port: 443
benefactor_service:
length_of_otp_code: 5
kavenegar_sms_provider:
api_key: insert_your_api_key
otp_template_new_user: ebhomeverify
otp_template_registered_user: ebhomeverify
admin_auth:
sign_key: admin-jwt_secret_test_nik

View File

@ -0,0 +1,4 @@
COMPOSE_MARIADB_DATABASE=niki_db
COMPOSE_MARIADB_USER=niki
COMPOSE_MARIADB_UR_PASSWORD=n0ki2agd23
COMPOSE_MARIADB_RT_PASSWORD=n0ki2agd23

View File

@ -1,22 +1,22 @@
version: '3.1'
version: '3.9'
services:
niki_stage_mariadb:
image: docker.io/bitnami/mariadb:11.1
container_name: niki_stage_mariadb
restart: always
ports:
- '127.0.0.1:3429:3306'
networks:
- niki-stage
expose:
- "3306"
volumes:
- 'niki_stage_mariadb_data:/bitnami/mariadb'
environment:
- MARIADB_USER=niki
- MARIADB_PASSWORD=${NIKI_STAGE_MARIADB_UR_PASSWORD}
- MARIADB_DATABASE=niki_db
- MARIADB_ROOT_PASSWORD=${NIKI_STAGE_MARIADB_RT_PASSWORD}
- ALLOW_EMPTY_PASSWORD=no
MARIADB_USER: ${COMPOSE_MARIADB_USER?error}
MARIADB_PASSWORD: ${COMPOSE_MARIADB_UR_PASSWORD?error}
MARIADB_DATABASE: ${COMPOSE_MARIADB_DATABASE?error}
MARIADB_ROOT_PASSWORD: ${COMPOSE_MARIADB_RT_PASSWORD?error}
ALLOW_EMPTY_PASSWORD: no
healthcheck:
test: ['CMD', '/opt/bitnami/scripts/mariadb/healthcheck.sh']
interval: 15s

View File

@ -0,0 +1 @@
COMPOSE_REDIS_PASSWORD=n0ki2agd23

View File

@ -1,18 +1,17 @@
version: '3.1'
version: '3.9'
services:
niki_stage_redis:
image: bitnami/redis:6.2
container_name: niki_stage_redis
restart: always
ports:
- '127.0.0.1:6380:6379'
# TODO - remove `--save "" --appendonly no` from command to persist data
command: redis-server --loglevel warning --protected-mode no --save "" --appendonly no
command: redis-server --loglevel warning --protected-mode no
environment:
- ALLOW_EMPTY_PASSWORD=yes
REDIS_PASSWORD: ${COMPOSE_REDIS_PASSWORD?error}
networks:
- core
- niki-stage
expose:
- "6379"
volumes:
- niki__stage_redis_data:/data

View File

@ -1,40 +0,0 @@
version: '3.9'
services:
mysqltest:
image: mysql:8.0
ports:
- "3305:3306"
container_name: niki-database-test
volumes:
- dbdatatest:/var/lib/mysql
restart: always
command: [ 'mysqld', '--character-set-server=utf8mb4', '--collation-server=utf8mb4_unicode_ci' ]
environment:
MYSQL_ROOT_PASSWORD: 123456
MYSQL_DATABASE: test_db
MYSQL_USER: testuser
MYSQL_PASSWORD: test1234
niki-redis-test:
image: bitnami/redis:6.2
container_name: niki-redis-test
restart: always
ports:
- '6381:6379'
# TODO - remove `--save "" --appendonly no` from command to persist data
command: redis-server --loglevel warning --protected-mode no --save "" --appendonly no
environment:
- ALLOW_EMPTY_PASSWORD=yes
volumes:
- niki-redis-data-test:/data
volumes:
dbdatatest:
niki-redis-data-test:
# docker-compose -f docker-compose.dev.yaml up -d

2
go.mod
View File

@ -2,8 +2,6 @@ module git.gocasts.ir/ebhomengo/niki
go 1.23
toolchain go1.23.0
require (
github.com/go-ozzo/ozzo-validation v3.6.0+incompatible
github.com/go-ozzo/ozzo-validation/v4 v4.3.0