57
Some checks failed
Deploy Production / Deploy to Staging (push) Has been skipped
Go Linter / Run golangci-lint (api_gateway) (push) Failing after 4m59s
Go Linter / Build golang services (api_gateway) (push) Has been skipped
Go Linter / Push Docker Images (api_gateway) (push) Has been skipped

This commit is contained in:
Alex Shevchuk
2025-08-20 23:42:28 +03:00
parent bde8a20a16
commit 94c1bb727b
4 changed files with 131 additions and 67 deletions

View File

@@ -11,61 +11,61 @@ on:
- release - release
jobs: jobs:
# lint: lint:
# name: Run golangci-lint name: Run golangci-lint
# runs-on: ubuntu-22.04 runs-on: ubuntu-22.04
# strategy: strategy:
# matrix: matrix:
# project: project:
# - api_gateway - api_gateway
# steps: steps:
# - name: Checkout repository - name: Checkout repository
# uses: actions/checkout@v3 uses: actions/checkout@v3
# - name: Set up Go - name: Set up Go
# uses: actions/setup-go@v4 uses: actions/setup-go@v4
# with: with:
# go-version: 1.23 go-version: 1.23
# - name: Install golangci-lint - name: Install golangci-lint
# run: | run: |
# curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.62.2 curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.62.2
# - name: Run golangci-lint - name: Run golangci-lint
# run: | run: |
# go mod tidy go mod tidy
# golangci-lint run -c ./.golangci-lint.yaml --fix=false --color=always golangci-lint run -c ./.golangci-lint.yaml --fix=false --color=always
# build: build:
# name: Build golang services name: Build golang services
# runs-on: ubuntu-22.04 runs-on: ubuntu-22.04
# needs: lint needs: lint
# strategy: strategy:
# matrix: matrix:
# project: project:
# - api_gateway - api_gateway
# steps: steps:
# - name: Checkout repository - name: Checkout repository
# uses: actions/checkout@v3 uses: actions/checkout@v3
# - name: Set up Go - name: Set up Go
# uses: actions/setup-go@v4 uses: actions/setup-go@v4
# with: with:
# go-version: 1.23 go-version: 1.23
# - name: Build golang services - name: Build golang services
# run: | run: |
# go mod tidy go mod tidy
# 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: push:
name: Push Docker Images name: Push Docker Images
runs-on: ubuntu-22.04 runs-on: ubuntu-22.04
# needs: lint needs: lint
if: ${{ gitea.ref == 'refs/heads/master' || gitea.ref == 'refs/heads/release' }} if: ${{ gitea.ref == 'refs/heads/master' || gitea.ref == 'refs/heads/release' }}
strategy: strategy:

View File

@@ -7,14 +7,18 @@ on:
description: Environment to deploy to description: Environment to deploy to
required: true required: true
default: staging default: staging
type: choice
options:
- staging
- production
version: version:
description: Version to deploy (default is new, to see other versions use the 'Get available versions' workflow) description: Version to deploy (default is latest, to see other versions use the 'Get available versions' workflow)
required: false required: false
default: new default: latest
jobs: jobs:
deploy_to_staging: deploy:
name: Deploy to Staging name: Deploy to ${{ inputs.environment }}
runs-on: ubuntu-22.04 runs-on: ubuntu-22.04
env: env:
@@ -29,15 +33,8 @@ jobs:
env: env:
REPO: ${{ github.repository }} REPO: ${{ github.repository }}
run: | run: |
VERSION=${{ inputs.version }}
if [ ${VERSION} == "new" ]; then
GIT_SHA=$(git rev-parse --short HEAD) GIT_SHA=$(git rev-parse --short HEAD)
GIT_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo 'none') GIT_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo 'none')
else
GIT_SHA=$(echo ${VERSION} | cut -d'-' -f2)
GIT_TAG='none'
fi
echo "GIT_SHA=${GIT_SHA}" >> $GITHUB_OUTPUT echo "GIT_SHA=${GIT_SHA}" >> $GITHUB_OUTPUT
echo "GIT_TAG=${GIT_TAG}" >> $GITHUB_OUTPUT echo "GIT_TAG=${GIT_TAG}" >> $GITHUB_OUTPUT
@@ -58,15 +55,8 @@ jobs:
REGISTRY: hub.docker.com REGISTRY: hub.docker.com
REPO_NAME: ${{ steps.git-metadata.outputs.REPO_NAME }} REPO_NAME: ${{ steps.git-metadata.outputs.REPO_NAME }}
run: | run: |
TARGET_TAG=${{ inputs.version }}
if [ ${TARGET_TAG} == "new" ]; then
PUSH_DATE=$(date +"%Y-%m-%d %T %Z")
IMAGE_TAG=${{ inputs.environment }}-${{ steps.git-metadata.outputs.GIT_TAG != 'none' && steps.git-metadata.outputs.GIT_TAG || steps.git-metadata.outputs.GIT_SHA }}
else
PUSH_DATE=$(wget -q -O - "https://$REGISTRY/v2/namespaces/molvaapp/repositories/$REPO_NAME/tags/${TARGET_TAG}/" | jq -r '.tag_last_pushed')
IMAGE_TAG=${{ inputs.version }} IMAGE_TAG=${{ inputs.version }}
fi PUSH_DATE=$(wget -q -O - "https://$REGISTRY/v2/namespaces/molvaapp/repositories/$REPO_NAME/tags/${IMAGE_TAG}/" | jq -r '.tag_last_pushed')
echo "IMAGE_NAME=molvaapp/${{ steps.git-metadata.outputs.REPO_NAME }}" >> $GITHUB_OUTPUT echo "IMAGE_NAME=molvaapp/${{ steps.git-metadata.outputs.REPO_NAME }}" >> $GITHUB_OUTPUT
echo "IMAGE_TAG=${IMAGE_TAG}" >> $GITHUB_OUTPUT echo "IMAGE_TAG=${IMAGE_TAG}" >> $GITHUB_OUTPUT
@@ -98,7 +88,7 @@ jobs:
DOCKER_TLS_VERIFY: 1 DOCKER_TLS_VERIFY: 1
DOCKER_CERT_PATH: /tmp/swarm-certs DOCKER_CERT_PATH: /tmp/swarm-certs
VERSION: ${{ inputs.version == 'new' && 'latest' || inputs.version }} VERSION: ${{ inputs.version }}
APP_VERSION: ${{ inputs.environment }}-${{ steps.git-metadata.outputs.APP_COMMIT }} APP_VERSION: ${{ inputs.environment }}-${{ steps.git-metadata.outputs.APP_COMMIT }}
APP_COMMIT: ${{ steps.git-metadata.outputs.APP_COMMIT }} APP_COMMIT: ${{ steps.git-metadata.outputs.APP_COMMIT }}
@@ -121,13 +111,13 @@ jobs:
DB_HOSTS: ${{ secrets.DB_HOSTS }} DB_HOSTS: ${{ secrets.DB_HOSTS }}
DB_PORT: ${{ secrets.DB_PORT }} DB_PORT: ${{ secrets.DB_PORT }}
DB_USERNAME: ${{ secrets.DB_STG_USERNAME }} DB_USERNAME: ${{ inputs.environment == 'staging' && secrets.DB_STG_USERNAME || secrets.DB_PROD_USERNAME }}
DB_PASSWORD: ${{ secrets.DB_STG_PASSWORD }} DB_PASSWORD: ${{ inputs.environment == 'staging' && secrets.DB_STG_PASSWORD || secrets.DB_PROD_PASSWORD }}
DB_DBNAME: ${{ secrets.DB_DBNAME }} DB_DBNAME: ${{ secrets.DB_DBNAME }}
INTEGRATION_VKUSVILL_API_TOKEN: ${{ secrets.INTEGRATION_VKUSVILL_API_TOKEN }} INTEGRATION_VKUSVILL_API_TOKEN: ${{ secrets.INTEGRATION_VKUSVILL_API_TOKEN }}
run: | run: |
envsubst < docker-compose.staging.yaml > docker-compose.runtime.yaml envsubst < docker-compose.$VERSION.yaml > docker-compose.runtime.yaml
echo "Deploying version $VERSION to ${{ inputs.environment }}..." echo "Deploying version $VERSION to ${{ inputs.environment }}..."
echo "Log level: ${{ inputs.logLevel }}" echo "Log level: ${{ inputs.logLevel }}"

View File

@@ -0,0 +1,72 @@
version: "3.9"
services:
molva-api-gateway:
image: molvaapp/test_deploy:${VERSION}
ports:
- target: 8000
published: 8002
protocol: tcp
environment:
APP_VERSION: ${APP_VERSION}
APP_COMMIT: ${APP_COMMIT}
APP_BUILD_DATE: ${APP_BUILD_DATE}
KEYCLOAK_BASE_URL: ${KEYCLOAK_BASE_URL}
KEYCLOAK_REALM: ${KEYCLOAK_REALM}
KEYCLOAK_CLIENT_ID: ${KEYCLOAK_CLIENT_ID}
KEYCLOAK_CLIENT_SECRET: ${KEYCLOAK_CLIENT_SECRET}
BROKER_HOST: ${BROKER_HOST}
BROKER_PORT: ${BROKER_PORT}
BROKER_USERNAME: ${BROKER_USERNAME}
BROKER_PASSWORD: ${BROKER_PASSWORD}
SHORTENER_SECRET_KEY: ${SHORTENER_SECRET_KEY}
CACHE_ADDRS: ${CACHE_ADDRS}
CACHE_PASSWORD: ${CACHE_PASSWORD}
DB_HOSTS: ${DB_HOSTS}
DB_PORT: ${DB_PORT}
DB_USERNAME: ${DB_USERNAME}
DB_PASSWORD: ${DB_PASSWORD}
DB_DBNAME: ${DB_DBNAME}
INTEGRATION_VKUSVILL_API_TOKEN: ${INTEGRATION_VKUSVILL_API_TOKEN}
volumes:
- /opt/molva:/opt/molva
- /opt/molva/object_storage/credentials:/root/.aws/credentials:ro
- /opt/molva/object_storage/config:/root/.aws/config:ro
networks:
- molva
healthcheck:
test: ["CMD", "wget", "--spider", "-q", "localhost:8000/api/v1/healthcheck"]
deploy:
mode: replicated
replicas: 1
restart_policy:
condition: none
delay: 20s
window: 120s
update_config:
parallelism: 1
failure_action: rollback
monitor: 30s
max_failure_ratio: 0.3
order: start-first
rollback_config:
parallelism: 0
failure_action: continue
order: start-first
placement:
constraints:
- node.labels.env == prod
- node.labels.app == true
preferences:
- spread: node.labels.TZ
networks:
molva:
driver: overlay
attachable: true

View File

@@ -40,6 +40,8 @@ services:
- /opt/molva/object_storage/config:/root/.aws/config:ro - /opt/molva/object_storage/config:/root/.aws/config:ro
networks: networks:
- molva - molva
healthcheck:
test: ["CMD", "wget", "--spider", "-q", "localhost:8000/api/v1/healthcheck"]
deploy: deploy:
mode: replicated mode: replicated
replicas: 1 replicas: 1