diff --git a/.dockerignore b/.dockerignore index b978a4b..b6f7556 100644 --- a/.dockerignore +++ b/.dockerignore @@ -17,3 +17,4 @@ skaffold.yml .woodpecker .kpt-pipeline tmp +dist diff --git a/.gorelearser.yml b/.gorelearser.yml new file mode 100644 index 0000000..73b8282 --- /dev/null +++ b/.gorelearser.yml @@ -0,0 +1,26 @@ +# Visit https://goreleaser.com for documentation on how to customize this +# behavior. +before: + hooks: [] +builds: + - env: + - CGO_ENABLED=0 + mod_timestamp: "{{ .CommitTimestamp }}" + flags: + - -trimpath + ldflags: + - -X main.version={{.Version}} + goos: + - linux + goarch: + - amd64 + - arm64 + binary: "{{ .ProjectName }}_v{{ .Version }}" +archives: + - format: binary + name_template: "{{ .ProjectName }}_{{ .Version }}_{{ .Os }}_{{ .Arch }}" +checksum: + name_template: "{{ .ProjectName }}_{{ .Version }}_SHA256SUMS" + algorithm: sha256 +changelog: + skip: false diff --git a/.woodpecker/govulncheck.yml b/.woodpecker/govulncheck.yml index 615beed..b6bde87 100644 --- a/.woodpecker/govulncheck.yml +++ b/.woodpecker/govulncheck.yml @@ -21,21 +21,17 @@ steps: notify: image: deblan/woodpecker-email settings: + dsn: + from_secret: email_dsn from: - from_secret: email_from - from.name: Woodpecker - host: - from_secret: email_host - username: - from_secret: email_username - password: - from_secret: email_password + address: + from_secret: email_from_address + name: Woodpecker recipients: - - notifications@dwysokinski.me + - notifications@twhelp.app recipients_only: true subject: - "[govulncheck - {{ build.status }}] {{ repo.owner }}/{{ repo.name }} - ({{ build.branch }} - {{ truncate build.commit 8 }})" + "[govulncheck - {{ pipeline.status }}] {{ repo.full_name }} ({{ commit.branch }} - {{ commit.sha[0:8] }}" when: status: [success, failure] event: cron diff --git a/.woodpecker/release.yml b/.woodpecker/release.yml new file mode 100644 index 0000000..01ee67b --- /dev/null +++ b/.woodpecker/release.yml @@ -0,0 +1,41 @@ +when: + event: tag + +variables: + - &go_image 'golang:1.22' + - &goreleaser_image 'goreleaser/goreleaser' + - &docker_buildx_image 'woodpeckerci/plugin-docker-buildx' + +steps: + generate: + image: *go_image + pull: true + commands: + - go mod vendor + - make generate + + release: + image: *goreleaser_image + depends_on: + - generate + commands: + - goreleaser release --clean + secrets: + - gitea_token + + docker: + image: *docker_buildx_image + depends_on: + - release + settings: + platforms: linux/amd64,linux/arm64 + repo: gitea.dwysokinski.me/twhelp/core + registry: gitea.dwysokinski.me + dockerfile: ./build/docker/twhelp/prod/Dockerfile + auto_tag: true + build_args: + - CI_COMMIT_TAG=${CI_COMMIT_TAG} + username: + from_secret: docker_username + password: + from_secret: docker_password diff --git a/README.md b/README.md index a09e907..182d09a 100644 --- a/README.md +++ b/README.md @@ -15,14 +15,14 @@ · Discord Bot · - Report Bug + Report Bug · - Request Feature + Request Feature

## Contributing -If you would like to contribute to the software, please contact me via [email](mailto:contact@tribalwarshelp.com). +If you would like to contribute to the software, please contact me via [email](mailto:contact@twhelp.app). ## License diff --git a/build/docker/twhelp/prod/Dockerfile b/build/docker/twhelp/prod/Dockerfile index 52bc249..8b9e251 100644 --- a/build/docker/twhelp/prod/Dockerfile +++ b/build/docker/twhelp/prod/Dockerfile @@ -1,21 +1,11 @@ -FROM golang:1.22.1-alpine3.19 AS builder +FROM --platform=$BUILDPLATFORM alpine:3.19 +LABEL maintainer="contact@twhelp.app" -WORKDIR /twhelp +ARG TARGETOS +ARG TARGETARCH -COPY go.mod go.sum ./ -RUN go mod download && apk --no-cache add make - -COPY . . -RUN make generate -ARG CI_COMMIT_TAG="development" -RUN CGO_ENABLED=0 go build -ldflags "-X main.version=${CI_COMMIT_TAG##v}" -trimpath -o twhelp ./cmd/twhelp - -######## Start a new stage from scratch ####### -FROM alpine:3.19 - -RUN apk --no-cache add ca-certificates tzdata - -COPY --from=builder /twhelp/twhelp /usr/bin/ +RUN apk --no-cache add ca-certificates tzdata wget +RUN wget -O /usr/bin/twhelp https://gitea.dwysokinski.me/twhelp/core/releases/download/${CI_COMMIT_TAG}/core_${CI_COMMIT_TAG##v}_${TARGETOS}_${TARGETARCH} EXPOSE 9234/tcp diff --git a/k8s/base/api.yml b/k8s/base/api.yml index 4ca8e67..0b5476a 100644 --- a/k8s/base/api.yml +++ b/k8s/base/api.yml @@ -41,8 +41,8 @@ spec: value: "true" resources: requests: - cpu: 100m - memory: 100Mi + cpu: 20m + memory: 300Mi limits: cpu: 200m memory: 300Mi diff --git a/k8s/base/ennoblement-consumer.yml b/k8s/base/ennoblement-consumer.yml index cc74aba..c3c9492 100644 --- a/k8s/base/ennoblement-consumer.yml +++ b/k8s/base/ennoblement-consumer.yml @@ -43,8 +43,8 @@ spec: periodSeconds: 10 resources: requests: - cpu: 100m - memory: 100Mi + cpu: 20m + memory: 300Mi limits: cpu: 300m memory: 300Mi diff --git a/k8s/base/jobs.yml b/k8s/base/jobs.yml index 4d3994c..a4120bb 100644 --- a/k8s/base/jobs.yml +++ b/k8s/base/jobs.yml @@ -38,7 +38,7 @@ spec: key: rabbitmq-connection-string resources: requests: - cpu: 50m + cpu: 20m memory: 64Mi limits: cpu: 100m @@ -84,7 +84,7 @@ spec: key: rabbitmq-connection-string resources: requests: - cpu: 50m + cpu: 20m memory: 64Mi limits: cpu: 100m @@ -130,7 +130,7 @@ spec: key: rabbitmq-connection-string resources: requests: - cpu: 50m + cpu: 20m memory: 64Mi limits: cpu: 100m @@ -176,7 +176,7 @@ spec: key: rabbitmq-connection-string resources: requests: - cpu: 50m + cpu: 20m memory: 64Mi limits: cpu: 100m @@ -211,8 +211,8 @@ spec: value: 60s resources: requests: - cpu: 50m - memory: 64Mi + cpu: 20m + memory: 128Mi limits: cpu: 100m memory: 128Mi diff --git a/k8s/base/player-consumer.yml b/k8s/base/player-consumer.yml index f69ad6f..190caf5 100644 --- a/k8s/base/player-consumer.yml +++ b/k8s/base/player-consumer.yml @@ -43,8 +43,8 @@ spec: periodSeconds: 10 resources: requests: - cpu: 100m - memory: 100Mi + cpu: 20m + memory: 300Mi limits: cpu: 300m memory: 300Mi diff --git a/k8s/base/server-consumer.yml b/k8s/base/server-consumer.yml index 9e88775..a33c7ea 100644 --- a/k8s/base/server-consumer.yml +++ b/k8s/base/server-consumer.yml @@ -43,8 +43,8 @@ spec: periodSeconds: 10 resources: requests: - cpu: 100m - memory: 100Mi + cpu: 20m + memory: 150Mi limits: - cpu: 300m - memory: 300Mi + cpu: 150m + memory: 150Mi diff --git a/k8s/base/tribe-consumer.yml b/k8s/base/tribe-consumer.yml index 0a3e0cd..4870f59 100644 --- a/k8s/base/tribe-consumer.yml +++ b/k8s/base/tribe-consumer.yml @@ -43,8 +43,8 @@ spec: periodSeconds: 10 resources: requests: - cpu: 100m - memory: 100Mi + cpu: 20m + memory: 300Mi limits: cpu: 300m memory: 300Mi diff --git a/k8s/base/village-consumer.yml b/k8s/base/village-consumer.yml index 049495f..f27c8f3 100644 --- a/k8s/base/village-consumer.yml +++ b/k8s/base/village-consumer.yml @@ -43,8 +43,8 @@ spec: periodSeconds: 10 resources: requests: - cpu: 100m - memory: 100Mi + cpu: 20m + memory: 300Mi limits: cpu: 300m memory: 300Mi diff --git a/k8s/overlays/prod/api.yml b/k8s/overlays/prod/api.yml new file mode 100644 index 0000000..f19c7d0 --- /dev/null +++ b/k8s/overlays/prod/api.yml @@ -0,0 +1,31 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: twhelp-api-v2-deployment +spec: + template: + spec: + containers: + - name: twhelp-api-v2 + image: twhelp + env: + - name: APP_MODE + value: production + - name: LOG_LEVEL + value: info + - name: DB_CONNECTION_STRING + valueFrom: + secretKeyRef: + name: twhelp-secret + key: db-connection-string + - name: DB_MAX_OPEN_CONNS + value: "10" + - name: DB_MAX_IDLE_CONNS + value: "3" + - name: RABBITMQ_CONNECTION_STRING + valueFrom: + secretKeyRef: + name: twhelp-secret + key: rabbitmq-connection-string + - name: AUTO_MAX_PROCS + value: "true" diff --git a/k8s/overlays/prod/ennoblement-consumer.yml b/k8s/overlays/prod/ennoblement-consumer.yml new file mode 100644 index 0000000..8073543 --- /dev/null +++ b/k8s/overlays/prod/ennoblement-consumer.yml @@ -0,0 +1,32 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: twhelp-ennoblement-consumer-deployment +spec: + replicas: 2 + template: + spec: + containers: + - name: twhelp-ennoblement-consumer + image: twhelp + env: + - name: APP_MODE + value: production + - name: LOG_LEVEL + value: info + - name: DB_CONNECTION_STRING + valueFrom: + secretKeyRef: + name: twhelp-secret + key: db-connection-string + - name: DB_MAX_OPEN_CONNS + value: "3" + - name: DB_MAX_IDLE_CONNS + value: "1" + - name: RABBITMQ_CONNECTION_STRING + valueFrom: + secretKeyRef: + name: twhelp-secret + key: rabbitmq-connection-string + - name: AUTO_MAX_PROCS + value: "true" diff --git a/k8s/overlays/prod/ingress.yml b/k8s/overlays/prod/ingress.yml new file mode 100644 index 0000000..36c7b53 --- /dev/null +++ b/k8s/overlays/prod/ingress.yml @@ -0,0 +1,31 @@ +apiVersion: networking.k8s.io/v1 +kind: Ingress +metadata: + name: twhelp-api-v2-ingress + annotations: + traefik.ingress.kubernetes.io/router.entrypoints: web + traefik.ingress.kubernetes.io/router.tls: "false" + traefik.ingress.kubernetes.io/router.middlewares: + kube-system-cors-twhelp@kubernetescrd,kube-system-compress@kubernetescrd,kube-system-ratelimit-twhelp@kubernetescrd +spec: + rules: + - host: tribalwarshelp.com + http: + paths: + - path: /api/v2 + pathType: Prefix + backend: + service: + name: twhelp-api-v2-service + port: + number: 9234 + - host: twhelp.app + http: + paths: + - path: /api/v2 + pathType: Prefix + backend: + service: + name: twhelp-api-v2-service + port: + number: 9234 diff --git a/k8s/overlays/prod/jobs.yml b/k8s/overlays/prod/jobs.yml new file mode 100644 index 0000000..5549b8a --- /dev/null +++ b/k8s/overlays/prod/jobs.yml @@ -0,0 +1,163 @@ +apiVersion: batch/v1 +kind: CronJob +metadata: + name: twhelp-job-sync-data +spec: + jobTemplate: + spec: + template: + spec: + restartPolicy: Never + containers: + - name: twhelp-job-sync-data + image: twhelp + args: [job, sync, data] + env: + - name: APP_MODE + value: production + - name: LOG_LEVEL + value: info + - name: DB_CONNECTION_STRING + valueFrom: + secretKeyRef: + name: twhelp-secret + key: db-connection-string + - name: DB_MAX_OPEN_CONNS + value: "1" + - name: DB_MAX_IDLE_CONNS + value: "1" + - name: RABBITMQ_CONNECTION_STRING + valueFrom: + secretKeyRef: + name: twhelp-secret + key: rabbitmq-connection-string +--- +apiVersion: batch/v1 +kind: CronJob +metadata: + name: twhelp-job-sync-ennoblements +spec: + jobTemplate: + spec: + template: + spec: + restartPolicy: Never + containers: + - name: twhelp-job-sync-ennoblements + image: twhelp + args: [job, sync, ennoblements] + env: + - name: APP_MODE + value: production + - name: LOG_LEVEL + value: info + - name: DB_CONNECTION_STRING + valueFrom: + secretKeyRef: + name: twhelp-secret + key: db-connection-string + - name: DB_MAX_OPEN_CONNS + value: "1" + - name: DB_MAX_IDLE_CONNS + value: "1" + - name: RABBITMQ_CONNECTION_STRING + valueFrom: + secretKeyRef: + name: twhelp-secret + key: rabbitmq-connection-string +--- +apiVersion: batch/v1 +kind: CronJob +metadata: + name: twhelp-job-create-snapshots +spec: + jobTemplate: + spec: + template: + spec: + restartPolicy: Never + containers: + - name: twhelp-job-create-snapshots + image: twhelp + args: [job, create, snapshots] + env: + - name: APP_MODE + value: production + - name: LOG_LEVEL + value: info + - name: DB_CONNECTION_STRING + valueFrom: + secretKeyRef: + name: twhelp-secret + key: db-connection-string + - name: DB_MAX_OPEN_CONNS + value: "1" + - name: DB_MAX_IDLE_CONNS + value: "1" + - name: RABBITMQ_CONNECTION_STRING + valueFrom: + secretKeyRef: + name: twhelp-secret + key: rabbitmq-connection-string +--- +apiVersion: batch/v1 +kind: CronJob +metadata: + name: twhelp-job-cleanup +spec: + jobTemplate: + spec: + template: + spec: + restartPolicy: Never + containers: + - name: twhelp-job-cleanup + image: twhelp + args: [job, cleanup] + env: + - name: APP_MODE + value: production + - name: LOG_LEVEL + value: info + - name: DB_CONNECTION_STRING + valueFrom: + secretKeyRef: + name: twhelp-secret + key: db-connection-string + - name: DB_MAX_OPEN_CONNS + value: "1" + - name: DB_MAX_IDLE_CONNS + value: "1" + - name: RABBITMQ_CONNECTION_STRING + valueFrom: + secretKeyRef: + name: twhelp-secret + key: rabbitmq-connection-string +--- +apiVersion: batch/v1 +kind: Job +metadata: + name: twhelp-migrations-job +spec: + template: + spec: + containers: + - name: twhelp-migrations + image: twhelp + args: [db, migrate] + env: + - name: APP_MODE + value: production + - name: LOG_LEVEL + value: info + - name: DB_CONNECTION_STRING + valueFrom: + secretKeyRef: + name: twhelp-secret + key: db-connection-string + - name: DB_MAX_OPEN_CONNS + value: "1" + - name: DB_MAX_IDLE_CONNS + value: "1" + - name: DB_READ_TIMEOUT + value: 60s diff --git a/k8s/overlays/prod/kustomization.yml b/k8s/overlays/prod/kustomization.yml new file mode 100644 index 0000000..7379a1d --- /dev/null +++ b/k8s/overlays/prod/kustomization.yml @@ -0,0 +1,14 @@ +apiVersion: kustomize.config.k8s.io/v1beta1 +kind: Kustomization +namespace: twhelp +resources: + - ../../base + - ingress.yml +patchesStrategicMerge: + - api.yml + - ennoblement-consumer.yml + - jobs.yml + - player-consumer.yml + - server-consumer.yml + - tribe-consumer.yml + - village-consumer.yml diff --git a/k8s/overlays/prod/player-consumer.yml b/k8s/overlays/prod/player-consumer.yml new file mode 100644 index 0000000..0c29af6 --- /dev/null +++ b/k8s/overlays/prod/player-consumer.yml @@ -0,0 +1,31 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: twhelp-player-consumer-deployment +spec: + template: + spec: + containers: + - name: twhelp-player-consumer + image: twhelp + env: + - name: APP_MODE + value: production + - name: LOG_LEVEL + value: info + - name: DB_CONNECTION_STRING + valueFrom: + secretKeyRef: + name: twhelp-secret + key: db-connection-string + - name: DB_MAX_OPEN_CONNS + value: "3" + - name: DB_MAX_IDLE_CONNS + value: "1" + - name: RABBITMQ_CONNECTION_STRING + valueFrom: + secretKeyRef: + name: twhelp-secret + key: rabbitmq-connection-string + - name: AUTO_MAX_PROCS + value: "true" diff --git a/k8s/overlays/prod/server-consumer.yml b/k8s/overlays/prod/server-consumer.yml new file mode 100644 index 0000000..ad9ebd9 --- /dev/null +++ b/k8s/overlays/prod/server-consumer.yml @@ -0,0 +1,31 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: twhelp-server-consumer-deployment +spec: + template: + spec: + containers: + - name: twhelp-server-consumer + image: twhelp + env: + - name: APP_MODE + value: production + - name: LOG_LEVEL + value: info + - name: DB_CONNECTION_STRING + valueFrom: + secretKeyRef: + name: twhelp-secret + key: db-connection-string + - name: DB_MAX_OPEN_CONNS + value: "3" + - name: DB_MAX_IDLE_CONNS + value: "1" + - name: RABBITMQ_CONNECTION_STRING + valueFrom: + secretKeyRef: + name: twhelp-secret + key: rabbitmq-connection-string + - name: AUTO_MAX_PROCS + value: "true" diff --git a/k8s/overlays/prod/tribe-consumer.yml b/k8s/overlays/prod/tribe-consumer.yml new file mode 100644 index 0000000..8bfb6b7 --- /dev/null +++ b/k8s/overlays/prod/tribe-consumer.yml @@ -0,0 +1,31 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: twhelp-tribe-consumer-deployment +spec: + template: + spec: + containers: + - name: twhelp-tribe-consumer + image: twhelp + env: + - name: APP_MODE + value: production + - name: LOG_LEVEL + value: info + - name: DB_CONNECTION_STRING + valueFrom: + secretKeyRef: + name: twhelp-secret + key: db-connection-string + - name: DB_MAX_OPEN_CONNS + value: "3" + - name: DB_MAX_IDLE_CONNS + value: "1" + - name: RABBITMQ_CONNECTION_STRING + valueFrom: + secretKeyRef: + name: twhelp-secret + key: rabbitmq-connection-string + - name: AUTO_MAX_PROCS + value: "true" diff --git a/k8s/overlays/prod/village-consumer.yml b/k8s/overlays/prod/village-consumer.yml new file mode 100644 index 0000000..3e4dfbe --- /dev/null +++ b/k8s/overlays/prod/village-consumer.yml @@ -0,0 +1,32 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: twhelp-village-consumer-deployment +spec: + replicas: 2 + template: + spec: + containers: + - name: twhelp-village-consumer + image: twhelp + env: + - name: APP_MODE + value: production + - name: LOG_LEVEL + value: info + - name: DB_CONNECTION_STRING + valueFrom: + secretKeyRef: + name: twhelp-secret + key: db-connection-string + - name: DB_MAX_OPEN_CONNS + value: "3" + - name: DB_MAX_IDLE_CONNS + value: "1" + - name: RABBITMQ_CONNECTION_STRING + valueFrom: + secretKeyRef: + name: twhelp-secret + key: rabbitmq-connection-string + - name: AUTO_MAX_PROCS + value: "true"