forked from ebhomengo/niki
refactor(niki): stage deployment docker setup (#130)
This commit is contained in:
parent
4f4ae64100
commit
3fb173036e
|
@ -20,6 +20,7 @@ activate.mise.toml
|
||||||
# Dependency directories (remove the comment below to include it)
|
# Dependency directories (remove the comment below to include it)
|
||||||
.idea
|
.idea
|
||||||
bin
|
bin
|
||||||
|
tmp
|
||||||
|
|
||||||
#.env
|
#.env
|
||||||
*.env
|
*.env
|
||||||
|
|
30
Dockerfile
30
Dockerfile
|
@ -1,18 +1,12 @@
|
||||||
# Build Stage
|
# 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
|
# Set environment variable
|
||||||
ENV APP_NAME niki
|
ENV APP_NAME niki
|
||||||
ENV CMD_PATH main.go
|
|
||||||
|
|
||||||
# Add a work directory
|
# Add a work directory
|
||||||
WORKDIR /$APP_NAME
|
WORKDIR /$APP_NAME
|
||||||
|
|
||||||
## Cache and install dependencies
|
|
||||||
#COPY go.mod go.sum ./
|
|
||||||
#RUN go mod download
|
|
||||||
|
|
||||||
# Copy app files
|
# Copy app files
|
||||||
COPY . .
|
COPY . .
|
||||||
|
|
||||||
|
@ -20,18 +14,16 @@ COPY . .
|
||||||
RUN CGO_ENABLED=0 go build -mod=vendor -v -o $APP_NAME .
|
RUN CGO_ENABLED=0 go build -mod=vendor -v -o $APP_NAME .
|
||||||
|
|
||||||
# Run Stage
|
# 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 application port
|
||||||
EXPOSE 8313
|
EXPOSE 8313
|
||||||
|
|
||||||
# Start app
|
# Start the application
|
||||||
CMD ./$APP_NAME
|
CMD ["./niki", "--migrate"]
|
||||||
|
|
|
@ -20,10 +20,6 @@ redis:
|
||||||
password: ""
|
password: ""
|
||||||
db: 0
|
db: 0
|
||||||
|
|
||||||
sms_provider:
|
|
||||||
host: localhost
|
|
||||||
port: 443
|
|
||||||
|
|
||||||
benefactor_service:
|
benefactor_service:
|
||||||
length_of_otp_code: 5
|
length_of_otp_code: 5
|
||||||
|
|
||||||
|
|
|
@ -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
|
|
@ -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
|
|
@ -1,12 +1,26 @@
|
||||||
version: '3.7'
|
version: '3.9'
|
||||||
|
|
||||||
services:
|
services:
|
||||||
niki_app_stage:
|
niki_app_stage:
|
||||||
image: niki:${STAGE_NIKI_IMAGE_VERSION}
|
image: niki:${STAGE_NIKI_IMAGE_VERSION?error}
|
||||||
container_name: niki_app_stage
|
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
|
restart: always
|
||||||
ports:
|
ports:
|
||||||
- '127.0.0.1:8198:1313'
|
- "127.0.0.1:8313:1313"
|
||||||
networks:
|
networks:
|
||||||
- niki-stage
|
- niki-stage
|
||||||
volumes:
|
volumes:
|
||||||
|
|
|
@ -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
|
|
|
@ -0,0 +1,4 @@
|
||||||
|
COMPOSE_MARIADB_DATABASE=niki_db
|
||||||
|
COMPOSE_MARIADB_USER=niki
|
||||||
|
COMPOSE_MARIADB_UR_PASSWORD=n0ki2agd23
|
||||||
|
COMPOSE_MARIADB_RT_PASSWORD=n0ki2agd23
|
|
@ -1,22 +1,22 @@
|
||||||
version: '3.1'
|
version: '3.9'
|
||||||
|
|
||||||
services:
|
services:
|
||||||
niki_stage_mariadb:
|
niki_stage_mariadb:
|
||||||
image: docker.io/bitnami/mariadb:11.1
|
image: docker.io/bitnami/mariadb:11.1
|
||||||
container_name: niki_stage_mariadb
|
container_name: niki_stage_mariadb
|
||||||
restart: always
|
restart: always
|
||||||
ports:
|
|
||||||
- '127.0.0.1:3429:3306'
|
|
||||||
networks:
|
networks:
|
||||||
- niki-stage
|
- niki-stage
|
||||||
|
expose:
|
||||||
|
- "3306"
|
||||||
volumes:
|
volumes:
|
||||||
- 'niki_stage_mariadb_data:/bitnami/mariadb'
|
- 'niki_stage_mariadb_data:/bitnami/mariadb'
|
||||||
environment:
|
environment:
|
||||||
- MARIADB_USER=niki
|
MARIADB_USER: ${COMPOSE_MARIADB_USER?error}
|
||||||
- MARIADB_PASSWORD=${NIKI_STAGE_MARIADB_UR_PASSWORD}
|
MARIADB_PASSWORD: ${COMPOSE_MARIADB_UR_PASSWORD?error}
|
||||||
- MARIADB_DATABASE=niki_db
|
MARIADB_DATABASE: ${COMPOSE_MARIADB_DATABASE?error}
|
||||||
- MARIADB_ROOT_PASSWORD=${NIKI_STAGE_MARIADB_RT_PASSWORD}
|
MARIADB_ROOT_PASSWORD: ${COMPOSE_MARIADB_RT_PASSWORD?error}
|
||||||
- ALLOW_EMPTY_PASSWORD=no
|
ALLOW_EMPTY_PASSWORD: no
|
||||||
healthcheck:
|
healthcheck:
|
||||||
test: ['CMD', '/opt/bitnami/scripts/mariadb/healthcheck.sh']
|
test: ['CMD', '/opt/bitnami/scripts/mariadb/healthcheck.sh']
|
||||||
interval: 15s
|
interval: 15s
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
COMPOSE_REDIS_PASSWORD=n0ki2agd23
|
|
@ -1,18 +1,17 @@
|
||||||
version: '3.1'
|
version: '3.9'
|
||||||
|
|
||||||
services:
|
services:
|
||||||
niki_stage_redis:
|
niki_stage_redis:
|
||||||
image: bitnami/redis:6.2
|
image: bitnami/redis:6.2
|
||||||
container_name: niki_stage_redis
|
container_name: niki_stage_redis
|
||||||
restart: always
|
restart: always
|
||||||
ports:
|
command: redis-server --loglevel warning --protected-mode no
|
||||||
- '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
|
|
||||||
environment:
|
environment:
|
||||||
- ALLOW_EMPTY_PASSWORD=yes
|
REDIS_PASSWORD: ${COMPOSE_REDIS_PASSWORD?error}
|
||||||
networks:
|
networks:
|
||||||
- core
|
- niki-stage
|
||||||
|
expose:
|
||||||
|
- "6379"
|
||||||
volumes:
|
volumes:
|
||||||
- niki__stage_redis_data:/data
|
- niki__stage_redis_data:/data
|
||||||
|
|
||||||
|
|
|
@ -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
2
go.mod
|
@ -2,8 +2,6 @@ module git.gocasts.ir/ebhomengo/niki
|
||||||
|
|
||||||
go 1.23
|
go 1.23
|
||||||
|
|
||||||
toolchain go1.23.0
|
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/go-ozzo/ozzo-validation v3.6.0+incompatible
|
github.com/go-ozzo/ozzo-validation v3.6.0+incompatible
|
||||||
github.com/go-ozzo/ozzo-validation/v4 v4.3.0
|
github.com/go-ozzo/ozzo-validation/v4 v4.3.0
|
||||||
|
|
Loading…
Reference in New Issue