Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
79 commits
Select commit Hold shift + click to select a range
ea69db2
feat(deploy): add staging deployment workflow with commit hash tracking
ZeroDayZ7 Apr 3, 2026
9a39443
up
ZeroDayZ7 Apr 3, 2026
66d1e44
up
ZeroDayZ7 Apr 3, 2026
3e62f9f
up
ZeroDayZ7 Apr 3, 2026
fc458ee
up
ZeroDayZ7 Apr 3, 2026
bc41cce
up
ZeroDayZ7 Apr 3, 2026
d5a3ecc
up
ZeroDayZ7 Apr 3, 2026
07ab364
up
ZeroDayZ7 Apr 3, 2026
d075f73
up
ZeroDayZ7 Apr 3, 2026
0752ec5
up
ZeroDayZ7 Apr 3, 2026
0814211
up
ZeroDayZ7 Apr 3, 2026
b766290
add separate dockerfiles for api and worker
ZeroDayZ7 Apr 3, 2026
4f75d6d
up
ZeroDayZ7 Apr 3, 2026
64dcf52
up
ZeroDayZ7 Apr 4, 2026
de824c4
up
ZeroDayZ7 Apr 4, 2026
2cf428f
up
ZeroDayZ7 Apr 4, 2026
0e745c7
up
ZeroDayZ7 Apr 4, 2026
c647889
up
ZeroDayZ7 Apr 4, 2026
713507c
Refactor config loading and add Nginx configuration files
ZeroDayZ7 Apr 4, 2026
0c5c1a8
Refactor code structure for improved readability and maintainability
ZeroDayZ7 Apr 4, 2026
1061ba6
build image
ZeroDayZ7 Apr 5, 2026
ccf0ecc
up
ZeroDayZ7 Apr 5, 2026
25520d1
up
ZeroDayZ7 Apr 5, 2026
423fbf1
up
ZeroDayZ7 Apr 5, 2026
3d6ce61
up
ZeroDayZ7 Apr 5, 2026
6c30852
up
ZeroDayZ7 Apr 5, 2026
df3354f
up
ZeroDayZ7 Apr 5, 2026
93f4713
up
ZeroDayZ7 Apr 5, 2026
922f10b
up
ZeroDayZ7 Apr 5, 2026
30fad3f
up
ZeroDayZ7 Apr 5, 2026
d6ddd76
up
ZeroDayZ7 Apr 5, 2026
9e7d7c7
up
ZeroDayZ7 Apr 5, 2026
ddcc9b5
up
ZeroDayZ7 Apr 5, 2026
50e051f
update
ZeroDayZ7 Apr 5, 2026
50cb757
rozkład jazdy, jazda z kurwami
ZeroDayZ7 Apr 5, 2026
7e7276f
gnoju zrób ten deploy wkoncu
ZeroDayZ7 Apr 5, 2026
c8310e2
add GitHub Actions workflow for Kubernetes deployment and create kust…
ZeroDayZ7 Apr 5, 2026
0a81b0e
add Kubernetes deployment, service, and ingress configurations for go…
ZeroDayZ7 Apr 5, 2026
5fd9cc6
add MySQL and Redis deployment and service configurations for staging
ZeroDayZ7 Apr 5, 2026
cfad31e
update kustomization.yaml to replace mysql.yaml with databases.yaml
ZeroDayZ7 Apr 5, 2026
c40d6bf
update
ZeroDayZ7 Apr 5, 2026
fb03ae0
update containerPort in deployment and service configurations for go-…
ZeroDayZ7 Apr 5, 2026
42f1fd1
refactor: update server configuration to use WorkerPort and adjust de…
ZeroDayZ7 Apr 5, 2026
8df9782
update
ZeroDayZ7 Apr 5, 2026
f3aedb4
update
ZeroDayZ7 Apr 5, 2026
b3efcf5
refactor: update motto in main.go and change go-api port to 8080 in i…
ZeroDayZ7 Apr 5, 2026
904c25e
feat(k8s): add background worker deployment to staging
ZeroDayZ7 Apr 6, 2026
ac87561
ci: unify api & worker deployment via ghcr and gitops
ZeroDayZ7 Apr 6, 2026
a9076fd
fix: lowercase
ZeroDayZ7 Apr 6, 2026
3b1c9c9
ci: fix manifest paths and enforce lowercase ghcr owner
ZeroDayZ7 Apr 6, 2026
d0641b9
Deploy: images update to 3b1c9c9
invalid-email-address Apr 6, 2026
2269b78
fix: resolve config validation and database connection issues
ZeroDayZ7 Apr 6, 2026
d91811e
Merge branch 'staging' of https://github.com/ZeroDayZ7/http-server in…
ZeroDayZ7 Apr 6, 2026
71f1860
refactor: sync k8s env variables with app config structure
ZeroDayZ7 Apr 6, 2026
818de8d
Deploy: images update to 71f1860
invalid-email-address Apr 6, 2026
81672f4
Field 'WorkerPort' failed on 'required' (value: )
ZeroDayZ7 Apr 6, 2026
ea5b31a
Merge branch 'staging' of https://github.com/ZeroDayZ7/http-server in…
ZeroDayZ7 Apr 6, 2026
a903b71
change dev - staging
ZeroDayZ7 Apr 6, 2026
7455acb
Deploy: images update to a903b71
invalid-email-address Apr 6, 2026
f32cb2e
fast fix
ZeroDayZ7 Apr 6, 2026
8f6168a
Merge branch 'staging' of https://github.com/ZeroDayZ7/http-server in…
ZeroDayZ7 Apr 6, 2026
9c5fea0
Deploy: images update to 8f6168a
invalid-email-address Apr 6, 2026
a4e6caa
build: trigger first cross-repo deploy
ZeroDayZ7 Apr 6, 2026
8817c1e
Merge branch 'staging' of https://github.com/ZeroDayZ7/http-server in…
ZeroDayZ7 Apr 6, 2026
4496908
chore: remove deprecated configuration files and resources for stagin…
ZeroDayZ7 Apr 7, 2026
99e046b
chore: remove outdated documentation and add new migration instructions
ZeroDayZ7 Apr 10, 2026
639452b
chore: update Go version to 1.26.2 and add govulncheck commands
ZeroDayZ7 Apr 16, 2026
bbcf18c
chore: add mock implementations for interaction services and update c…
ZeroDayZ7 Apr 16, 2026
74d2323
Ratelimiter: Singleton for Storage
ZeroDayZ7 Apr 16, 2026
c63e865
fix: align env variables and cleanup Viper-MySQL mismatch" -m "Fixed …
ZeroDayZ7 Apr 17, 2026
dc5e177
refactor: implement two-tier rate limiting for enhanced DoS protection
ZeroDayZ7 Apr 17, 2026
3f1abd6
refactor: update Dockerfiles for improved security and build efficiency
ZeroDayZ7 Apr 22, 2026
fa42f2c
Dev (#5)
ZeroDayZ7 Apr 22, 2026
40bb813
refactor: streamline Dockerfile for improved build efficiency and sec…
ZeroDayZ7 Apr 22, 2026
601fcaa
Merge branch 'staging' into dev
ZeroDayZ7 Apr 22, 2026
f68d8e9
Dev (#7)
ZeroDayZ7 Apr 22, 2026
c08cd10
fix: add user and group ownership to server binary copy in Dockerfile
ZeroDayZ7 Apr 22, 2026
f582001
refactor: enhance Dockerfile and logger for staging environment support
ZeroDayZ7 Apr 23, 2026
66b877b
Merge branch 'main' into staging
ZeroDayZ7 Apr 23, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 76 additions & 0 deletions .github/workflows/deploy-staging-k8s.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
name: Ghost Ops - API & Worker Deployment

on:
push:
branches: [staging]

permissions:
contents: write
packages: write

jobs:
build-and-push:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Prepare variables
id: vars
run: |
echo "sha_short=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT
echo "owner_lc=${GITHUB_REPOSITORY_OWNER,,}" >> $GITHUB_OUTPUT

- name: Login to GHCR
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

# --- Budowanie API ---
- name: Build & Push API
uses: docker/build-push-action@v5
with:
context: .
file: cmd/api/Dockerfile
push: true
tags: ghcr.io/${{ steps.vars.outputs.owner_lc }}/http-server-api:${{ steps.vars.outputs.sha_short }}

# --- Budowanie WORKERA ---
- name: Build & Push Worker
uses: docker/build-push-action@v5
with:
context: .
file: cmd/worker/Dockerfile
push: true
tags: ghcr.io/${{ steps.vars.outputs.owner_lc }}/http-server-worker:${{ steps.vars.outputs.sha_short }}

# --- ENTERPRISE GITOPS: Aktualizacja OSOBNEGO repozytorium infrastruktury ---
- name: Update Infrastructure Repo
env:
INFRA_TOKEN: ${{ secrets.INFRA_REPO_TOKEN }}
SHA: ${{ steps.vars.outputs.sha_short }}
OWNER: ${{ steps.vars.outputs.owner_lc }}
run: |
# 1. Konfiguracja tożsamości Gita
git config --global user.name "github-actions"
git config --global user.email "github-actions@github.com"

# 2. Klonowanie repozytorium INFRA (używamy PAT do autoryzacji)
# Zwróć uwagę na nazwę repo: k3s-gitops-infra
git clone https://$INFRA_TOKEN@github.com/${{ github.repository_owner }}/k3s-gitops-infra.git temp_infra

cd temp_infra

# 3. Aktualizacja tagów obrazów w nowej strukturze folderów
# Szukamy linii z obrazem i podmieniamy na nowy SHA
echo "Updating images to version: $SHA"

sed -i "s|image: ghcr.io/.*/http-server-api:.*|image: ghcr.io/$OWNER/http-server-api:$SHA|g" overlays/staging/api/deployment.yaml
sed -i "s|image: ghcr.io/.*/http-server-worker:.*|image: ghcr.io/$OWNER/http-server-worker:$SHA|g" overlays/staging/worker/deployment.yaml

# 4. Commit i Push zmian do repozytorium INFRA
git add .
git commit -m "Deploy: API & Worker update to $SHA (triggered by http-server commit)" || echo "No changes to commit"
git push origin main
7 changes: 7 additions & 0 deletions cmd/api/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
.git
.gitignore
docker-compose*
Dockerfile*
bin
obj
*.md
39 changes: 31 additions & 8 deletions cmd/api/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,20 +1,43 @@
# Dockerfile.api
FROM golang:1.26-alpine AS builder

FROM golang:1.25-alpine AS builder
RUN apk add --no-cache ca-certificates git tzdata

WORKDIR /app
WORKDIR /src

COPY go.mod go.sum ./
RUN go mod download

COPY . .

RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o app ./cmd/api
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 \
go build -trimpath -ldflags="-w -s" -o /app/server ./cmd/api

FROM alpine:latest
FROM alpine:3.19.1 AS final

WORKDIR /app
LABEL org.opencontainers.image.source="https://github.com/ZeroDayZ7/http-server"
LABEL org.opencontainers.image.description="Hardened Go API"

COPY --from=builder /app/app .
RUN apk update && \
apk add --no-cache ca-certificates tzdata && \
rm -rf /var/cache/apk/*

CMD ["./app"]
RUN addgroup -S appgroup && \
adduser -S -u 10001 -g appgroup appuser

WORKDIR /home/appuser

COPY --from=builder --chown=appuser:appgroup /app/server .
COPY --from=builder --chown=appuser:appgroup /src/migrations ./migrations

RUN chmod 500 ./server && \
chmod 500 ./migrations && \
chmod 400 ./migrations/*

USER appuser

EXPOSE 8080

HEALTHCHECK --interval=30s --timeout=5s --start-period=5s --retries=3 \
CMD wget --no-verbose --tries=1 --spider http://localhost:8080/health || exit 1

ENTRYPOINT ["./server"]
2 changes: 1 addition & 1 deletion cmd/api/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func main() {
defer stop()

// 3. Inicjalizacja infrastruktury
db, err := config.InitDB(ctx, cfg.Database, log)
db, err := config.InitDB(ctx, cfg.Database, log, true)
if err != nil {
log.Fatal("Database initialization failed", zap.Error(err))
}
Expand Down
7 changes: 7 additions & 0 deletions cmd/worker/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
.git
.gitignore
docker-compose*
Dockerfile*
bin
obj
*.md
37 changes: 25 additions & 12 deletions cmd/worker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,22 +1,35 @@
# Dockerfile.worker

FROM golang:1.25-alpine AS builder

WORKDIR /app
FROM golang:1.26-alpine AS builder

RUN apk add --no-cache ca-certificates git tzdata
WORKDIR /src
COPY go.mod go.sum ./
RUN go mod download

COPY . .

RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o worker ./cmd/worker
# Dodano -trimpath dla bezpieczeństwa logów
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 \
go build -trimpath -ldflags="-w -s" -o /app/worker ./cmd/worker

FROM alpine:3.19 AS final

# Dodano LABEL dla porządku w GitHubie
LABEL org.opencontainers.image.source="https://github.com/ZeroDayZ7/http-server"
LABEL org.opencontainers.image.description="Hardened Go Worker"

# Dodano apk update i czyszczenie cache
RUN apk update && \
apk add --no-cache ca-certificates tzdata && \
rm -rf /var/cache/apk/*

RUN addgroup -S workergroup && \
adduser -S -u 10002 -g workergroup workeruser

FROM alpine:latest
WORKDIR /home/workeruser

WORKDIR /app
COPY --from=builder --chown=workeruser:workergroup /app/worker .

COPY --from=builder /app/worker .
RUN chmod 500 ./worker

COPY --from=builder /app/migrations ./migrations
USER workeruser

CMD ["./worker"]
ENTRYPOINT ["./worker"]
2 changes: 1 addition & 1 deletion cmd/worker/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func main() {
g, gCtx := errgroup.WithContext(ctx)

// infra init
db, err := config.InitDB(ctx, cfg.Database, log)
db, err := config.InitDB(ctx, cfg.Database, log, false)
if err != nil {
log.Fatal("Database initialization failed", zap.Error(err))
}
Expand Down
2 changes: 1 addition & 1 deletion config/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func NewFiberApp(cfg *env.Config, log logger.Logger) *fiber.App {

app.Use(cors.New(CorsConfig(cfg)))
app.Use(helmet.New(HelmetConfig()))
// app.Use(NewLimiter(cfg, "global"))
app.Use(GetLimiter(cfg, LimitApp))
app.Use(compress.New(CompressConfig()))

return app
Expand Down
12 changes: 8 additions & 4 deletions config/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"go.uber.org/zap"
)

func InitDB(ctx context.Context, cfg env.DBConfig, log logger.Logger) (*sql.DB, error) {
func InitDB(ctx context.Context, cfg env.DBConfig, log logger.Logger, runMigrations bool) (*sql.DB, error) {
dsn := fmt.Sprintf(
"%s:%s@tcp(%s:%s)/%s?parseTime=true",
cfg.User, cfg.Password, cfg.Host, cfg.Port, cfg.DBName,
Expand All @@ -34,10 +34,14 @@ func InitDB(ctx context.Context, cfg env.DBConfig, log logger.Logger) (*sql.DB,
return nil, fmt.Errorf("db ping failed: %w", err)
}

if err := RunMigrations(db, log); err != nil {
return nil, fmt.Errorf("migrations failed: %w", err)
if runMigrations {
if err := RunMigrations(db, log); err != nil {
return nil, fmt.Errorf("migrations failed: %w", err)
}
log.Info("MySQL connected and migrations applied", zap.String("database", cfg.DBName))
} else {
log.Info("MySQL connected (migrations skipped)", zap.String("database", cfg.DBName))
}

log.Info("MySQL connected and migrations applied", zap.String("database", cfg.DBName))
return db, nil
}
4 changes: 2 additions & 2 deletions config/env/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ func setDefaults() {
// Server
viper.SetDefault("APP_NAME", "http-server")
viper.SetDefault("PORT", "8080")
viper.SetDefault("WORKERPORT", "8081")
viper.SetDefault("WORKER_PORT", "8081")
viper.SetDefault("BODY_LIMIT_MB", 2)
viper.SetDefault("APP_VERSION", "0.1.0")
viper.SetDefault("ENV", "development")
Expand All @@ -27,7 +27,7 @@ func setDefaults() {
viper.SetDefault("DB_PASSWORD", "password")
viper.SetDefault("DB_HOST", "localhost")
viper.SetDefault("DB_PORT", "3306")
viper.SetDefault("DB_NAME", "appdb")
viper.SetDefault("DB_NAME", "portfolio_db")
viper.SetDefault("DB_MAX_OPEN_CONNS", 50)
viper.SetDefault("DB_MAX_IDLE_CONNS", 10)
viper.SetDefault("DB_CONN_MAX_LIFETIME", 30*time.Minute)
Expand Down
4 changes: 4 additions & 0 deletions config/env/loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ func LoadConfig(cfg *Config) error {
viper.AutomaticEnv()
viper.SetEnvKeyReplacer(strings.NewReplacer(".", "_"))

viper.BindEnv("WORKER_PORT")
viper.BindEnv("DB_HOST")
viper.BindEnv("ENV")

// AUTO detect pliku .env
if fileExists(".env") {
viper.SetConfigFile(".env")
Expand Down
Loading
Loading