Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

first commit #1

Merged
merged 1 commit into from
Feb 28, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
75 changes: 75 additions & 0 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
# See here for image contents: https://github.com/microsoft/vscode-dev-containers/tree/v0.245.2/containers/go/.devcontainer/base.Dockerfile

ARG VARIANT="1.21"
ARG LINT="1.53.3"

ARG USERNAME=vscode
ARG USER_UID=1000
ARG USER_GID=$USER_UID

FROM mcr.microsoft.com/vscode/devcontainers/go:${VARIANT}

# Update packages
RUN apt-get update

# [Package] Install golangci-lint
RUN go install github.com/golangci/golangci-lint/cmd/[email protected]

# [Package] Install act
RUN curl -s https://raw.githubusercontent.com/nektos/act/master/install.sh | sudo bash

# [Pakage] Install openapi
RUN go install github.com/deepmap/oapi-codegen/cmd/oapi-codegen@latest

RUN chmod -R a+rwX /go/pkg

RUN BIN="/usr/local/bin" && \
VERSION="1.26.1" && \
curl -sSL \
"https://github.com/bufbuild/buf/releases/download/v${VERSION}/buf-$(uname -s)-$(uname -m)" \
-o "${BIN}/buf" && \
chmod +x "${BIN}/buf"

# [Package] Terraform

# RUN sudo apt-get update && sudo apt-get install -y gnupg software-properties-common
# RUN wget -O- https://apt.releases.hashicorp.com/gpg | \
# gpg --dearmor | \
# sudo tee /usr/share/keyrings/hashicorp-archive-keyring.gpg

# RUN gpg --no-default-keyring \
# --keyring /usr/share/keyrings/hashicorp-archive-keyring.gpg \
# --fingerprint

# RUN echo "deb [signed-by=/usr/share/keyrings/hashicorp-archive-keyring.gpg] \
# https://apt.releases.hashicorp.com $(lsb_release -cs) main" | \
# sudo tee /etc/apt/sources.list.d/hashicorp.list

# RUN sudo apt update
# RUN sudo apt-get install terraform

# [Package] jsonnet

RUN apt-get install
RUN sudo apt-get install jsonnet

# [Package] yq
RUN go install github.com/mikefarah/yq/v4@latest

# [Package] yc
RUN curl -sSL https://storage.yandexcloud.net/yandexcloud-yc/install.sh | bash

# [Package] node

RUN apt-get install
RUN sudo apt-get install -y nodejs
RUN sudo apt-get install -y npm

# [Package] migrate

RUN curl -L https://github.com/golang-migrate/migrate/releases/download/v4.17.0/migrate.linux-arm64.tar.gz | tar xvz && \
mv migrate /usr/local/bin/migrate

# [Package] wire

RUN go install github.com/google/wire/cmd/wire@latest
31 changes: 31 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// For format details, see https://aka.ms/devcontainer.json. For config options, see the README at:
// https://github.com/microsoft/vscode-dev-containers/tree/v0.245.2/containers/go
{
"name": "Go",
"dockerComposeFile": "docker-compose.yaml",
"service": "app",
"workspaceFolder": "/workspaces/${localWorkspaceFolderBasename}",
"customizations": {
"vscode": {
"extensions": [
"GitHub.copilot",
"aldijav.golangwithdidi",
"golang.go",
"neonxp.gotools",
"premparihar.gotestexplorer",
"actboy168.tasks",
"42Crunch.vscode-openapi",
"github.vscode-github-actions",
"yokoe.vscode-postfix-go",
"seunlanlege.action-buttons",
"adpyke.vscode-sql-formatter",
"augustocdias.tasks-shell-input",
"rioj7.command-variable",
"eamodio.gitlens"
]
}
},
"features": {
"ghcr.io/devcontainers/features/docker-outside-of-docker:1": {},
},
}
113 changes: 113 additions & 0 deletions .devcontainer/docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
version: "3.7"

services:
app:
build:
context: .
dockerfile: Dockerfile
command: sleep infinity
volumes:
- ../..:/workspaces:cached
- /var/run/docker.sock:/var/run/docker.sock

postgres:
image: postgres:16.0
restart: always
command: postgres -c 'max_connections=200'
environment:
POSTGRES_USER: default
POSTGRES_PASSWORD: secret
POSTGRES_DB: main
ports:
- "5400:5432"

redis:
image: redis:7.2
restart: always
ports:
- "6300:6379"
environment:
- REDIS_PASSWORD=secret

elasticsearch:
image: elasticsearch:8.0.0
environment:
- discovery.type=single-node
- xpack.security.enabled=false
restart: always
ports:
- "9200:9200"
- "9300:9300"

s3:
image: quay.io/minio/minio:latest
command: minio server --console-address ":9001" /data
ports:
- "9000:9000"
- "9001:9001"
environment:
MINIO_ROOT_USER: minio
MINIO_ROOT_PASSWORD: secretsecret
MINIO_ACCESS_KEY: secretsecret
MINIO_SECRET_KEY: secretsecret
MINIO_DOMAIN: s3
restart: always
volumes:
- ./data:/data

createbuckets:
image: minio/mc:latest
depends_on:
- s3
entrypoint: >
/bin/sh -c " /usr/bin/mc alias set myminio http://localhost:9000 minio secretsecret; /usr/bin/mc mb myminio/open; /usr/bin/mc anonymous set public myminio/open; exit 0; "

createbuckets2:
image: minio/mc:latest
depends_on:
- s3
entrypoint: >
/bin/sh -c " /usr/bin/mc alias set myminio http://localhost:9000 minio secretsecret; /usr/bin/mc mb myminio/priv; /usr/bin/mc anonymous set public myminio/priv; exit 0; "

jaeger:
image: jaegertracing/all-in-one:1.27
restart: always
ports:
- "16686:16686"
- "6831:6831/udp"
- "6832:6832/udp"

zookeeper:
image: confluentinc/cp-zookeeper:latest
environment:
ZOOKEEPER_CLIENT_PORT: 2181
ZOOKEEPER_TICK_TIME: 2000
ports:
- 2181:2181

kafka:
image: confluentinc/cp-kafka:latest
depends_on:
- zookeeper
ports:
- 9092:9092
- 29092:29092
environment:
KAFKA_BROKER_ID: 1
KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181
KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://kafka:9092,PLAINTEXT_HOST://localhost:29092
KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: PLAINTEXT:PLAINTEXT,PLAINTEXT_HOST:PLAINTEXT
KAFKA_INTER_BROKER_LISTENER_NAME: PLAINTEXT
KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR: 1

kafdrop:
image: obsidiandynamics/kafdrop
restart: always
ports:
- "9100:9000"
environment:
KAFKA_BROKERCONNECT: "kafka:9092"
JVM_OPTS: "-Xms32M -Xmx64M"
depends_on:
- kafka

9 changes: 9 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
.vscode
.github
.devcontainer
bin
testify
.idea
docs
.git
__debug**
45 changes: 45 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# ENV
ENV=dev # dev, prod

# DB
DB_CREDS=postgres://default:secret@postgres:5432/main

# REDIS
REDIS_CREDS=redis://secret@redis:6379/0

# EMAILS
SMTP_CREDS=smtp://password:[email protected]:smtp.yandex.ru:465

# APP
LOG_LEVEL=info
LOG_FORMAT=json
APP_NAME=crmbackend
SOLT=xxxxxxxxxxxxxxxxxx

# FEATURES
METRICS=true
MIGRATE=true
RATE_LIMITER=1000

# CDN
CDN_AVATARS_URL=https://storage.yandexcloud.net/test/avatars/
#
CDN_PUBLIC_REGION=ru-central1
CDN_PUBLIC_ACCESS_KEY_ID=
CDN_PUBLIC_SECRET_ACCESS_KEY=
CDN_PUBLIC_BUCKET_NAME=oviovi-public
#
CDN_PRIVATE_REGION=ru-central1
CDN_PRIVATE_ACCESS_KEY_ID=
CDN_PRIVATE_SECRET_ACCESS_KEY=
CDN_PRIVATE_BUCKET_NAME=studyproject

# Sentry
SENTRY_ENABLE=false
SENTRY_DSN=

# YANDEX CLOUD
YANDEX_CLOUD_REGISTRY_PASSWORD=

# SMS
SMS_API_ID=
Empty file added .github/CODEOWNERS
Empty file.
89 changes: 89 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
name: main
run-name: ${{ github.actor }} - Testing and publishing

on:
push:
paths-ignore:
- '*.md'
- '**/*.md'

env:
GOLANG_VERSION: "1.21"
REGISTRY_IMAGE_NAME: "crm-back"

jobs:
prepare:
name: Prepare variables
runs-on: ubuntu-latest
outputs:
version: ${{ steps.prepare.outputs.version }}
commit: ${{ steps.prepare.outputs.commit }}
branch: ${{ steps.prepare.outputs.branch }}
tag: ${{ steps.prepare.outputs.tag }}
steps:
- name: Prepare variables
id: prepare
shell: bash
run: |
BRANCH=$(echo ${GITHUB_REF#refs/heads/} | tr '\' '-')
COMMIT_SHA_SHORT=$(echo ${GITHUB_SHA} | cut -c1-7)
VERSION=$(echo ${BRANCH}-${COMMIT_SHA_SHORT})
TAG=$(echo ${GITHUB_REF#refs/*/})

echo "tag=${GITHUB_REF#refs/*/}" >> $GITHUB_OUTPUT
echo "version=${VERSION}" >> $GITHUB_OUTPUT
echo "commit=${COMMIT_SHA_SHORT}" >> $GITHUB_OUTPUT
echo "branch=${BRANCH}" >> $GITHUB_OUTPUT

echo version: $VERSION
echo commit: $COMMIT_SHA_SHORT
echo branch: $BRANCH
echo tag: $TAG

lint:
name: Linting
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v3
with:
go-version: ${{ env.GOLANG_VERSION }}
go-version-file: 'go.mod'
cache-dependency-path: 'go.sum'
- uses: golangci/golangci-lint-action@v3
with:
version: v1.55.2
args: "--fix=false"

test:
name: Unit tests
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v3
with:
go-version: ${{ env.GOLANG_VERSION }}
go-version-file: 'go.mod'
cache-dependency-path: 'go.sum'
- name: Caches
uses: actions/cache@v3
with:
path: ~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
- name: Install dependencies
run: |
go mod download
- name: Check tidiness
run: |
touch .env
make tidy
if [[ $(git diff --stat) != '' ]]; then
git diff
echo 'run `make tidy` and commit changes'
exit 1
fi
- name: Run unit tests
run: |
make test
24 changes: 24 additions & 0 deletions .github/workflows/manual.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: manual
run-name: Manula - Deploy

on:
workflow_dispatch:
inputs:
tag:
description: 'Version to deploy'
required: true
default: '-'

env:
REGISTRY_IMAGE_NAME: "crm-back"

jobs:
deploy:
name: Deploy
runs-on: ubuntu-latest
steps:


- name: Update image tag
shell: bash
run:
Loading
Loading