Compare commits

...
Author SHA1 Message Date
aefril 7b46da7007 Merge pull request 'staging' (#23) from staging into main
Reviewed-on: #23
2026-07-09 15:43:23 +00:00
Efril 2b80c92caa feat: deployment 2026-07-09 22:43:01 +07:00
Efril f7dd0bd5e8 config: update port 2026-07-09 22:19:53 +07:00
Efril 1533914e4d config: prod and staging 2026-07-09 22:11:03 +07:00
Efril bfce4b865b update purchase date 2026-07-02 12:49:28 +07:00
Efril 581e4a5453 update purchase date 2026-07-02 12:23:12 +07:00
6 changed files with 147 additions and 23 deletions
+4
View File
@@ -9,3 +9,7 @@ vendor
# Firebase service account credentials # Firebase service account credentials
infra/firebase-service-account.json infra/firebase-service-account.json
# Config files containing secrets (manage manually on each server)
# infra/production.yaml
# infra/staging.yaml
+27 -7
View File
@@ -1,9 +1,21 @@
#PROJECT_NAME = "enaklo-pos-backend" #PROJECT_NAME = "enaklo-pos-backend"
DB_USERNAME :=apskel
DB_PASSWORD :=7a8UJbM2GgBWaseh0lnP3O5i1i5nINXk # ─── Environment (default: staging) ──────────────────────────────────────────
DB_HOST :=62.72.45.250 ENV ?= staging
DB_PORT :=5433
DB_NAME :=apskel_pos ifeq ($(ENV),production)
DB_USERNAME :=apskel
DB_PASSWORD :=7a8UJbM2GgBWaseh0lnP3O5i1i5nINXk
DB_HOST :=62.72.45.250
DB_PORT :=5433
DB_NAME :=apskel_pos
else
DB_USERNAME :=apskel
DB_PASSWORD :=7a8UJbM2GgBWaseh0lnP3O5i1i5nINXk
DB_HOST :=62.72.45.250
DB_PORT :=5433
DB_NAME :=apskel_pos_staging
endif
DB_URL = postgres://$(DB_USERNAME):$(DB_PASSWORD)@$(DB_HOST):$(DB_PORT)/$(DB_NAME)?sslmode=disable DB_URL = postgres://$(DB_USERNAME):$(DB_PASSWORD)@$(DB_HOST):$(DB_PORT)/$(DB_NAME)?sslmode=disable
@@ -16,15 +28,19 @@ endif
.SILENT: help .SILENT: help
help: help:
@echo @echo
@echo "Usage: make [command]" @echo "Usage: make [command] [ENV=staging|production]"
@echo @echo
@echo "Commands:" @echo "Commands:"
@echo " run Run server (default: staging)"
@echo " run ENV=production Run server with production config"
@echo
@echo " rename-project name={name} Rename project" @echo " rename-project name={name} Rename project"
@echo @echo
@echo " build-http Build http server" @echo " build-http Build http server"
@echo @echo
@echo " migration-create name={name} Create migration" @echo " migration-create name={name} Create migration"
@echo " migration-up Up migrations" @echo " migration-up Up migrations"
@echo " migration-up ENV=production Up migrations (production DB)"
@echo " migration-down Down last migration" @echo " migration-down Down last migration"
@echo @echo
@echo " docker-up Up docker services" @echo " docker-up Up docker services"
@@ -114,7 +130,11 @@ fmt:
@go fmt ./... @go fmt ./...
start: start:
go run main.go --env-path .env ENV_MODE=$(ENV) go run cmd/server/main.go
.SILENT: run
run:
ENV_MODE=$(ENV) go run cmd/server/main.go
# Default # Default
+2 -1
View File
@@ -12,13 +12,14 @@ import (
const ( const (
YAML_PATH = "infra/%s" YAML_PATH = "infra/%s"
ENV_MODE = "ENV_MODE" ENV_MODE = "ENV_MODE"
DEFAULT_ENV_MODE = "development" DEFAULT_ENV_MODE = "staging"
) )
var ( var (
validEnvMode = map[string]struct{}{ validEnvMode = map[string]struct{}{
"local": {}, "local": {},
"development": {}, "development": {},
"staging": {},
"production": {}, "production": {},
} }
) )
+46 -8
View File
@@ -2,23 +2,61 @@
set -euo pipefail set -euo pipefail
APP_NAME="apskel-pos" APP_NAME="apskel-pos"
PORT="4000"
# ─── Deteksi environment dari branch aktif ───────────────────────────────────
CURRENT_BRANCH=$(git rev-parse --abbrev-ref HEAD)
case "$CURRENT_BRANCH" in
main)
ENV_MODE="production"
PORT="4000"
;;
staging)
ENV_MODE="staging"
PORT="4001"
;;
*)
echo "❌ Branch '$CURRENT_BRANCH' tidak dikenali untuk deployment."
echo " Gunakan branch 'main' (production) atau 'staging' (staging)."
exit 1
;;
esac
CONTAINER_NAME="$APP_NAME"
IMAGE_NAME="$APP_NAME:$ENV_MODE"
echo "📦 Environment : $ENV_MODE"
echo "🌿 Branch : $CURRENT_BRANCH"
echo "🐳 Container : $CONTAINER_NAME"
echo "🔌 Port : $PORT"
echo ""
# ─── Pastikan config file ada ─────────────────────────────────────────────────
CONFIG_FILE="infra/$ENV_MODE.yaml"
if [ ! -f "$CONFIG_FILE" ]; then
echo "❌ Config file '$CONFIG_FILE' tidak ditemukan."
exit 1
fi
echo "🔄 Pulling latest code..." echo "🔄 Pulling latest code..."
git pull git pull
echo "🐳 Building Docker image (production target)..." echo "🐳 Building Docker image ($ENV_MODE)..."
docker build --target production -t $APP_NAME:latest . docker build --target production -t "$IMAGE_NAME" .
echo "🛑 Stopping and removing old container..." echo "🛑 Stopping and removing old container..."
docker rm -f $APP_NAME 2>/dev/null || true docker rm -f "$CONTAINER_NAME" 2>/dev/null || true
echo "🚀 Running new container..." echo "🚀 Running new container..."
docker run -d --name $APP_NAME \ docker run -d --name "$CONTAINER_NAME" \
-p $PORT:$PORT \ -p "$PORT:4000" \
-e TZ=Asia/Jakarta \ -e TZ=Asia/Jakarta \
-e ENV_MODE="$ENV_MODE" \
-v "$(pwd)/infra":/infra:ro \ -v "$(pwd)/infra":/infra:ro \
-v "$(pwd)/templates":/templates:ro \ -v "$(pwd)/templates":/templates:ro \
$APP_NAME:latest "$IMAGE_NAME"
echo "✅ Deployment complete." echo ""
echo "✅ Deployment $ENV_MODE complete."
echo " Container : $CONTAINER_NAME"
echo " Port : $PORT"
@@ -1,7 +1,7 @@
server: server:
base-url: base-url:
local-url: local-url:
self-order-url: http://localhost:5173 self-order-url:
port: 4000 port: 4000
jwt: jwt:
@@ -9,7 +9,7 @@ jwt:
expires-ttl: 144000 expires-ttl: 144000
secret: "5Lm25V3Qd7aut8dr4QUxm5PZUrSFs" secret: "5Lm25V3Qd7aut8dr4QUxm5PZUrSFs"
refresh_token: refresh_token:
expires-ttl: 7776000 # 3 months in minutes (90 days * 24 hours * 60 minutes) expires-ttl: 7776000
secret: "R3fr3sh_T0k3n_S3cr3t_K3y_2024_P0S" secret: "R3fr3sh_T0k3n_S3cr3t_K3y_2024_P0S"
customer: customer:
expires-ttl: 7776000 expires-ttl: 7776000
@@ -21,7 +21,7 @@ postgresql:
driver: postgres driver: postgres
db: apskel_pos db: apskel_pos
username: apskel username: apskel
password: '7a8UJbM2GgBWaseh0lnP3O5i1i5nINXk' password: "7a8UJbM2GgBWaseh0lnP3O5i1i5nINXk"
ssl-mode: disable ssl-mode: disable
max-idle-connections-in-second: 600 max-idle-connections-in-second: 600
max-open-connections-in-second: 600 max-open-connections-in-second: 600
@@ -45,11 +45,11 @@ s3:
endpoint: sin1.contabostorage.com endpoint: sin1.contabostorage.com
bucket_name: enaklo bucket_name: enaklo
log_level: Error log_level: Error
host_url: 'https://sin1.contabostorage.com/fda98c2228f246f29a7e466b86b3b9e7:' host_url: "https://sin1.contabostorage.com/fda98c2228f246f29a7e466b86b3b9e7:"
log: log:
log_format: 'json' log_format: "json"
log_level: 'debug' log_level: "info"
fonnte: fonnte:
api_url: "https://api.fonnte.com/send" api_url: "https://api.fonnte.com/send"
+61
View File
@@ -0,0 +1,61 @@
server:
base-url:
local-url:
self-order-url:
port: 4000
jwt:
token:
expires-ttl: 144000
secret: "eZ7LAZJuSOGSHxb1ZYaZCkrBo5YBvc"
refresh_token:
expires-ttl: 7776000
secret: "EMx2DKPtMp0jQNpLvzzCsZkoUHe0d9"
customer:
expires-ttl: 7776000
secret: "layCV2rne0X57acWzSS3NxENmYJs7B"
postgresql:
host: 62.72.45.250
port: 5433
driver: postgres
db: apskel_pos_staging
username: apskel
password: "7a8UJbM2GgBWaseh0lnP3O5i1i5nINXk"
ssl-mode: disable
max-idle-connections-in-second: 600
max-open-connections-in-second: 600
connection-max-life-time-in-second: 600
debug: false
redis:
host: 62.72.45.250
port: 6380
password: "CmICdmnX1EZPhVBYzQPEGw==U"
db: 1
dial_timeout: 5s
read_timeout: 3s
write_timeout: 3s
pool_size: 10
min_idle_connections: 5
s3:
access_key_id: cf9a475e18bc7626cbdbf09709d82a64
access_key_secret: 91f3321294d3e23035427a0ecb893ada
endpoint: sin1.contabostorage.com
bucket_name: enaklo
log_level: Error
host_url: "https://sin1.contabostorage.com/fda98c2228f246f29a7e466b86b3b9e7:"
log:
log_format: "json"
log_level: "info"
fonnte:
api_url: "https://api.fonnte.com/send"
token: "bADQrf9NTXfLZQCK2wGg"
timeout: 30
fcm:
credentials_file: "infra/firebase-service-account.json"
project_id: "apskel-pos-v2"