Compare commits
11 Commits
v1.2.42072
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
62ce86f1c4 | ||
|
|
ce7aecf8be | ||
|
|
f64936e0f3 | ||
|
|
a11e3b3a82 | ||
|
|
9fb046223c | ||
|
|
0d9dc14131 | ||
|
|
cf4a0ac7b7 | ||
|
|
cb4dd943bc | ||
|
|
9d4b138190 | ||
|
|
e3262d588c | ||
|
|
33229f1eb7 |
@@ -0,0 +1,22 @@
|
|||||||
|
env: "local"
|
||||||
|
host: "0.0.0.0"
|
||||||
|
port: 8000
|
||||||
|
|
||||||
|
broker:
|
||||||
|
notificationsQueueName: "molva-notification"
|
||||||
|
|
||||||
|
cache:
|
||||||
|
readOnly: false
|
||||||
|
dialTimeout: 1h
|
||||||
|
poolSize: 10
|
||||||
|
defaultTtl: 1h
|
||||||
|
rootCaFilePath: "/etc/.redis/YandexInternalRootCA.crt"
|
||||||
|
|
||||||
|
s3Storage:
|
||||||
|
bucket: "molva-staging" # TODO: change to prod bucket
|
||||||
|
defaultLinkTtl: 1h
|
||||||
|
|
||||||
|
database:
|
||||||
|
schema: test_schema # TODO: change to prod schema
|
||||||
|
sslmode: require
|
||||||
|
rootCaFilePath: "/etc/.postgres/YandexInternalRootCA.crt"
|
||||||
|
|||||||
@@ -19,4 +19,4 @@ s3Storage:
|
|||||||
database:
|
database:
|
||||||
schema: test_schema
|
schema: test_schema
|
||||||
sslmode: require
|
sslmode: require
|
||||||
rootCaFilePath: "/etc/.redis/YandexInternalRootCA.crt"
|
rootCaFilePath: "/etc/.postgres/YandexInternalRootCA.crt"
|
||||||
|
|||||||
@@ -70,79 +70,6 @@ jobs:
|
|||||||
SWAGGER_HOST=${HOST} make docs
|
SWAGGER_HOST=${HOST} make docs
|
||||||
CGO_ENABLED=0 GOOS=linux go build -ldflags="-s -w" -o main cmd/main.go
|
CGO_ENABLED=0 GOOS=linux go build -ldflags="-s -w" -o main cmd/main.go
|
||||||
|
|
||||||
push:
|
|
||||||
name: Push Docker Images
|
|
||||||
runs-on: ubuntu-22.04
|
|
||||||
needs: lint
|
|
||||||
if: ${{ gitea.ref == 'refs/heads/master' || gitea.ref == 'refs/heads/release' }}
|
|
||||||
|
|
||||||
strategy:
|
|
||||||
matrix:
|
|
||||||
project:
|
|
||||||
- api_gateway
|
|
||||||
|
|
||||||
steps:
|
|
||||||
- name: Checkout репозитория
|
|
||||||
uses: actions/checkout@v4
|
|
||||||
|
|
||||||
- name: Extract Git metadata
|
|
||||||
id: git-metadata
|
|
||||||
env:
|
|
||||||
REPO: ${{ github.repository }}
|
|
||||||
run: |
|
|
||||||
GIT_SHA=$(git rev-parse --short HEAD)
|
|
||||||
GIT_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo 'none')
|
|
||||||
TARGET_ENV=${{ github.ref == 'refs/heads/release' && 'staging' || 'production' }}
|
|
||||||
|
|
||||||
echo "GIT_SHA=${GIT_SHA}" >> $GITHUB_OUTPUT
|
|
||||||
echo "GIT_TAG=${GIT_TAG}" >> $GITHUB_OUTPUT
|
|
||||||
echo "TARGET_ENV=${TARGET_ENV}" >> $GITHUB_OUTPUT
|
|
||||||
echo "REPO_NAME=$(echo $REPO | cut -d'/' -f2)" >> $GITHUB_OUTPUT
|
|
||||||
|
|
||||||
- name: Login to Docker Registry
|
|
||||||
uses: docker/login-action@v3
|
|
||||||
with:
|
|
||||||
username: ${{ secrets.DOCKER_USERNAME }}
|
|
||||||
password: ${{ secrets.DOCKER_PASSWORD }}
|
|
||||||
|
|
||||||
- name: Extract image metadata
|
|
||||||
id: docker-metadata
|
|
||||||
needs: git-metadata
|
|
||||||
env:
|
|
||||||
REGISTRY: hub.docker.com
|
|
||||||
REPO_NAME: ${{ steps.git-metadata.outputs.REPO_NAME }}
|
|
||||||
TARGET_ENV: ${{ steps.git-metadata.outputs.TARGET_ENV }}
|
|
||||||
GIT_TAG: ${{ steps.git-metadata.outputs.GIT_TAG }}
|
|
||||||
GIT_SHA: ${{ steps.git-metadata.outputs.GIT_SHA }}
|
|
||||||
run: |
|
|
||||||
IMAGE_TAG=$TARGET_ENV-$($GIT_TAG != 'none' && echo $GIT_TAG || echo $GIT_SHA)
|
|
||||||
|
|
||||||
echo "IMAGE_NAME=molvaapp/${{ steps.git-metadata.outputs.REPO_NAME }}" >> $GITHUB_OUTPUT
|
|
||||||
echo "IMAGE_TAG=${IMAGE_TAG}" >> $GITHUB_OUTPUT
|
|
||||||
|
|
||||||
- name: Build and Push Docker Image
|
|
||||||
needs: docker-metadata
|
|
||||||
env:
|
|
||||||
IMAGE_NAME: ${{ steps.docker-metadata.outputs.IMAGE_NAME }}
|
|
||||||
IMAGE_TAG: ${{ steps.docker-metadata.outputs.IMAGE_TAG }}
|
|
||||||
CONFIG_FILE: .build/config/${{ steps.git-metadata.outputs.TARGET_ENV }}.yaml
|
|
||||||
HOST: ${{ github.event.base_ref == 'refs/heads/release' && secrets.HOST_STG || secrets.HOST_PROD }}
|
|
||||||
run: |
|
|
||||||
docker build \
|
|
||||||
--build-arg BUILD_LDFLAGS="-w -s" \
|
|
||||||
--build-arg CONFIG_FILE_PATH=$CONFIG_FILE \
|
|
||||||
--build-arg SWAGGER_HOST=$HOST \
|
|
||||||
-t $IMAGE_NAME:$IMAGE_TAG \
|
|
||||||
-t $IMAGE_NAME:latest \
|
|
||||||
.
|
|
||||||
|
|
||||||
docker tag $IMAGE_NAME:$IMAGE_TAG $IMAGE_NAME:latest
|
|
||||||
|
|
||||||
docker push $IMAGE_NAME:$IMAGE_TAG
|
|
||||||
docker push $IMAGE_NAME:latest
|
|
||||||
|
|
||||||
echo "Pushed image $IMAGE_NAME:$IMAGE_TAG and :latest"
|
|
||||||
|
|
||||||
tag:
|
tag:
|
||||||
name: Tag Commit
|
name: Tag Commit
|
||||||
runs-on: ubuntu-22.04
|
runs-on: ubuntu-22.04
|
||||||
@@ -195,3 +122,87 @@ jobs:
|
|||||||
git tag ${{ steps.get-latest-tag.outputs.NEW_TAG }}
|
git tag ${{ steps.get-latest-tag.outputs.NEW_TAG }}
|
||||||
git push origin ${{ steps.get-latest-tag.outputs.NEW_TAG }}
|
git push origin ${{ steps.get-latest-tag.outputs.NEW_TAG }}
|
||||||
echo "Successfully pushed tag: ${{ steps.get-latest-tag.outputs.NEW_TAG }}"
|
echo "Successfully pushed tag: ${{ steps.get-latest-tag.outputs.NEW_TAG }}"
|
||||||
|
|
||||||
|
push:
|
||||||
|
name: Push Docker Images
|
||||||
|
runs-on: ubuntu-22.04
|
||||||
|
needs:
|
||||||
|
lint
|
||||||
|
tag
|
||||||
|
if: ${{ gitea.ref == 'refs/heads/master' || gitea.ref == 'refs/heads/release' }}
|
||||||
|
|
||||||
|
strategy:
|
||||||
|
matrix:
|
||||||
|
project:
|
||||||
|
- api_gateway
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Checkout репозитория
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
with:
|
||||||
|
fetch-depth: 0
|
||||||
|
fetch-tags: true
|
||||||
|
|
||||||
|
- name: Extract Git metadata
|
||||||
|
id: git-metadata
|
||||||
|
env:
|
||||||
|
REPO: ${{ github.repository }}
|
||||||
|
run: |
|
||||||
|
git fetch --tags --force
|
||||||
|
GIT_SHA=$(git rev-parse --short HEAD)
|
||||||
|
GIT_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "none")
|
||||||
|
|
||||||
|
TARGET_ENV=${{ github.ref == 'refs/heads/release' && 'staging' || 'production' }}
|
||||||
|
|
||||||
|
echo "GIT_SHA=${GIT_SHA}" >> $GITHUB_OUTPUT
|
||||||
|
echo "GIT_TAG=${GIT_TAG}" >> $GITHUB_OUTPUT
|
||||||
|
echo "TARGET_ENV=${TARGET_ENV}" >> $GITHUB_OUTPUT
|
||||||
|
echo "REPO_NAME=$(echo $REPO | cut -d'/' -f2)" >> $GITHUB_OUTPUT
|
||||||
|
|
||||||
|
- name: Login to Docker Registry
|
||||||
|
uses: docker/login-action@v3
|
||||||
|
with:
|
||||||
|
username: ${{ secrets.DOCKER_USERNAME }}
|
||||||
|
password: ${{ secrets.DOCKER_PASSWORD }}
|
||||||
|
|
||||||
|
- name: Extract image metadata
|
||||||
|
id: docker-metadata
|
||||||
|
needs: git-metadata
|
||||||
|
env:
|
||||||
|
REGISTRY: hub.docker.com
|
||||||
|
REPO_NAME: ${{ steps.git-metadata.outputs.REPO_NAME }}
|
||||||
|
TARGET_ENV: ${{ steps.git-metadata.outputs.TARGET_ENV }}
|
||||||
|
GIT_TAG: ${{ steps.git-metadata.outputs.GIT_TAG }}
|
||||||
|
GIT_SHA: ${{ steps.git-metadata.outputs.GIT_SHA }}
|
||||||
|
run: |
|
||||||
|
if [ "$GIT_TAG" != "none" ]; then
|
||||||
|
IMAGE_TAG="${TARGET_ENV}-${GIT_TAG}"
|
||||||
|
else
|
||||||
|
IMAGE_TAG="${TARGET_ENV}-${GIT_SHA}"
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "IMAGE_NAME=molvaapp/${{ steps.git-metadata.outputs.REPO_NAME }}" >> $GITHUB_OUTPUT
|
||||||
|
echo "IMAGE_TAG=${IMAGE_TAG}" >> $GITHUB_OUTPUT
|
||||||
|
|
||||||
|
- name: Build and Push Docker Image
|
||||||
|
needs: docker-metadata
|
||||||
|
env:
|
||||||
|
IMAGE_NAME: ${{ steps.docker-metadata.outputs.IMAGE_NAME }}
|
||||||
|
IMAGE_TAG: ${{ steps.docker-metadata.outputs.IMAGE_TAG }}
|
||||||
|
CONFIG_FILE: .build/config/${{ steps.git-metadata.outputs.TARGET_ENV }}.yaml
|
||||||
|
HOST: ${{ github.event.base_ref == 'refs/heads/release' && secrets.HOST_STG || secrets.HOST_PROD }}
|
||||||
|
run: |
|
||||||
|
docker build \
|
||||||
|
--build-arg BUILD_LDFLAGS="-w -s" \
|
||||||
|
--build-arg CONFIG_FILE_PATH=$CONFIG_FILE \
|
||||||
|
--build-arg SWAGGER_HOST=$HOST \
|
||||||
|
-t $IMAGE_NAME:$IMAGE_TAG \
|
||||||
|
-t $IMAGE_NAME:latest \
|
||||||
|
.
|
||||||
|
|
||||||
|
docker tag $IMAGE_NAME:$IMAGE_TAG $IMAGE_NAME:latest
|
||||||
|
|
||||||
|
docker push $IMAGE_NAME:$IMAGE_TAG
|
||||||
|
docker push $IMAGE_NAME:latest
|
||||||
|
|
||||||
|
echo "Pushed image $IMAGE_NAME:$IMAGE_TAG and :latest"
|
||||||
|
|||||||
@@ -1,25 +0,0 @@
|
|||||||
name: Deploy Production
|
|
||||||
|
|
||||||
on:
|
|
||||||
push:
|
|
||||||
branches: [master, release]
|
|
||||||
pull_request:
|
|
||||||
branches: [master, release]
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
deploy_to_staging:
|
|
||||||
name: Deploy to Staging
|
|
||||||
runs-on: ubuntu-22.04
|
|
||||||
if: ${{ gitea.ref == 'refs/heads/release' }}
|
|
||||||
steps:
|
|
||||||
- name: Checkout code
|
|
||||||
uses: actions/checkout@v4
|
|
||||||
|
|
||||||
- name: Manual Approval Step
|
|
||||||
run: echo "Ручное подтверждение получено. Запуск деплоя..."
|
|
||||||
|
|
||||||
- name: Deployment Script (Заглушка)
|
|
||||||
run: |
|
|
||||||
echo "Здесь будет скрипт деплоя на staging"
|
|
||||||
# TODO: Реальный скрипт деплоя
|
|
||||||
echo "Симуляция деплоя..."
|
|
||||||
@@ -11,6 +11,8 @@ RUN go mod download -x
|
|||||||
|
|
||||||
COPY . .
|
COPY . .
|
||||||
|
|
||||||
|
RUN go mod tidy && go mod download -x
|
||||||
|
|
||||||
RUN SWAGGER_HOST=${SWAGGER_HOST} make docs
|
RUN SWAGGER_HOST=${SWAGGER_HOST} make docs
|
||||||
|
|
||||||
RUN CGO_ENABLED=0 GOOS=linux go build -ldflags="${BUILD_LDFLAGS}" -trimpath -o main ./cmd/main.go
|
RUN CGO_ENABLED=0 GOOS=linux go build -ldflags="${BUILD_LDFLAGS}" -trimpath -o main ./cmd/main.go
|
||||||
@@ -26,8 +28,8 @@ ARG CONFIG_FILE_PATH
|
|||||||
|
|
||||||
RUN apk add --no-cache ca-certificates tzdata
|
RUN apk add --no-cache ca-certificates tzdata
|
||||||
|
|
||||||
COPY --from=certs /YandexInternalRootCA.crt /root/.redis/YandexInternalRootCA.crt
|
COPY --from=certs /YandexInternalRootCA.crt /etc/.redis/YandexInternalRootCA.crt
|
||||||
COPY --from=certs /YandexInternalRootCA.crt /root/.postgres/YandexInternalRootCA.crt
|
COPY --from=certs /YandexInternalRootCA.crt /etc/.postgres/YandexInternalRootCA.crt
|
||||||
COPY ${CONFIG_FILE_PATH} /config.yaml
|
COPY ${CONFIG_FILE_PATH} /config.yaml
|
||||||
|
|
||||||
COPY --from=builder /app/main /main
|
COPY --from=builder /app/main /main
|
||||||
|
|||||||
14
Makefile
14
Makefile
@@ -10,6 +10,11 @@ ENV := "local"
|
|||||||
UNAME_S := $(shell uname -s)
|
UNAME_S := $(shell uname -s)
|
||||||
CONFIG_PATH := .build/config/
|
CONFIG_PATH := .build/config/
|
||||||
SWAGGER_DOCS_PATH := internal/http/swagger/docs
|
SWAGGER_DOCS_PATH := internal/http/swagger/docs
|
||||||
|
ifeq ($(UNAME_S),Darwin)
|
||||||
|
SED_INPLACE := -i ''
|
||||||
|
else
|
||||||
|
SED_INPLACE := -i
|
||||||
|
endif
|
||||||
|
|
||||||
ifeq ($(OS),Windows_NT)
|
ifeq ($(OS),Windows_NT)
|
||||||
CONFIG_PATH := $(subst /,\,$(CONFIG_PATH))
|
CONFIG_PATH := $(subst /,\,$(CONFIG_PATH))
|
||||||
@@ -60,15 +65,12 @@ docs: $(BIN_DIR)/swag
|
|||||||
@mkdir -p $(SWAGGER_DOCS_PATH)
|
@mkdir -p $(SWAGGER_DOCS_PATH)
|
||||||
@TEMP_MAIN="cmd/main_temp.go" && \
|
@TEMP_MAIN="cmd/main_temp.go" && \
|
||||||
cp cmd/main.go $$TEMP_MAIN && \
|
cp cmd/main.go $$TEMP_MAIN && \
|
||||||
if [[ "$$OSTYPE" == "darwin"* ]]; then \
|
ESC_HOST=$$(printf '%s\n' "$(HOST)" | sed -e 's/[\\\/&]/\\\\&/g') && \
|
||||||
sed -i '' "s/localhost:8000/$(HOST)/g" $$TEMP_MAIN; \
|
sed $(SED_INPLACE) "s|localhost:8000|$${ESC_HOST}|g" $$TEMP_MAIN && \
|
||||||
else \
|
|
||||||
sed -i "s/localhost:8000/$(HOST)/g" $$TEMP_MAIN; \
|
|
||||||
fi && \
|
|
||||||
$(BIN_DIR)/swag init -g $$TEMP_MAIN -o $(SWAGGER_DOCS_PATH) --parseDependency --parseInternal && \
|
$(BIN_DIR)/swag init -g $$TEMP_MAIN -o $(SWAGGER_DOCS_PATH) --parseDependency --parseInternal && \
|
||||||
rm -f $$TEMP_MAIN && \
|
rm -f $$TEMP_MAIN && \
|
||||||
echo "Swagger документация успешно сгенерирована с host: $(HOST)" && \
|
echo "Swagger документация успешно сгенерирована с host: $(HOST)" && \
|
||||||
echo "Документация доступна по адресу: http://$(HOST)/swagger/index.html"
|
echo "Документация доступна по адресу: $(HOST)/swagger/index.html"
|
||||||
|
|
||||||
## -- Run --
|
## -- Run --
|
||||||
## To change env use: make run CONFIG_PATH={config file dir path} ENV={env}
|
## To change env use: make run CONFIG_PATH={config file dir path} ENV={env}
|
||||||
|
|||||||
@@ -4,9 +4,8 @@ services:
|
|||||||
molva-api-gateway:
|
molva-api-gateway:
|
||||||
image: molvaapp/test_deploy:${VERSION}
|
image: molvaapp/test_deploy:${VERSION}
|
||||||
ports:
|
ports:
|
||||||
- target: 8000
|
- "8001:8000"
|
||||||
published: 8001
|
- "[::]:8001:8000"
|
||||||
protocol: tcp
|
|
||||||
environment:
|
environment:
|
||||||
APP_VERSION: ${APP_VERSION}
|
APP_VERSION: ${APP_VERSION}
|
||||||
APP_COMMIT: ${APP_COMMIT}
|
APP_COMMIT: ${APP_COMMIT}
|
||||||
|
|||||||
Reference in New Issue
Block a user