diff --git a/.gitea/workflows/ci.yaml b/.gitea/workflows/ci.yaml index fedfad8..c64b4ee 100644 --- a/.gitea/workflows/ci.yaml +++ b/.gitea/workflows/ci.yaml @@ -11,61 +11,61 @@ on: - release jobs: - # lint: - # name: Run golangci-lint - # runs-on: ubuntu-22.04 + lint: + name: Run golangci-lint + runs-on: ubuntu-22.04 - # strategy: - # matrix: - # project: - # - api_gateway + strategy: + matrix: + project: + - api_gateway - # steps: - # - name: Checkout repository - # uses: actions/checkout@v3 + steps: + - name: Checkout repository + uses: actions/checkout@v3 - # - name: Set up Go - # uses: actions/setup-go@v4 - # with: - # go-version: 1.23 + - name: Set up Go + uses: actions/setup-go@v4 + with: + go-version: 1.23 - # - name: Install golangci-lint - # run: | - # curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.62.2 + - name: Install golangci-lint + run: | + 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 - # run: | - # go mod tidy - # golangci-lint run -c ./.golangci-lint.yaml --fix=false --color=always + - name: Run golangci-lint + run: | + go mod tidy + golangci-lint run -c ./.golangci-lint.yaml --fix=false --color=always - # build: - # name: Build golang services - # runs-on: ubuntu-22.04 - # needs: lint + build: + name: Build golang services + runs-on: ubuntu-22.04 + needs: lint - # strategy: - # matrix: - # project: - # - api_gateway + strategy: + matrix: + project: + - api_gateway - # steps: - # - name: Checkout repository - # uses: actions/checkout@v3 + steps: + - name: Checkout repository + uses: actions/checkout@v3 - # - name: Set up Go - # uses: actions/setup-go@v4 - # with: - # go-version: 1.23 + - name: Set up Go + uses: actions/setup-go@v4 + with: + go-version: 1.23 - # - name: Build golang services - # run: | - # go mod tidy - # CGO_ENABLED=0 GOOS=linux go build -ldflags="-s -w" -o main cmd/main.go + - name: Build golang services + run: | + go mod tidy + 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 + needs: lint if: ${{ gitea.ref == 'refs/heads/master' || gitea.ref == 'refs/heads/release' }} strategy: diff --git a/.gitea/workflows/deploy_staging.yaml b/.gitea/workflows/deploy_staging.yaml index 4d9c2bd..e8fe0f7 100644 --- a/.gitea/workflows/deploy_staging.yaml +++ b/.gitea/workflows/deploy_staging.yaml @@ -7,14 +7,18 @@ on: description: Environment to deploy to required: true default: staging + type: choice + options: + - staging + - production 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 - default: new + default: latest jobs: - deploy_to_staging: - name: Deploy to Staging + deploy: + name: Deploy to ${{ inputs.environment }} runs-on: ubuntu-22.04 env: @@ -29,15 +33,8 @@ jobs: env: REPO: ${{ github.repository }} run: | - VERSION=${{ inputs.version }} - - if [ ${VERSION} == "new" ]; then - GIT_SHA=$(git rev-parse --short HEAD) - GIT_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo 'none') - else - GIT_SHA=$(echo ${VERSION} | cut -d'-' -f2) - GIT_TAG='none' - fi + GIT_SHA=$(git rev-parse --short HEAD) + GIT_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo 'none') echo "GIT_SHA=${GIT_SHA}" >> $GITHUB_OUTPUT echo "GIT_TAG=${GIT_TAG}" >> $GITHUB_OUTPUT @@ -58,15 +55,8 @@ jobs: REGISTRY: hub.docker.com REPO_NAME: ${{ steps.git-metadata.outputs.REPO_NAME }} 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 }} - fi + IMAGE_TAG=${{ inputs.version }} + 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_TAG=${IMAGE_TAG}" >> $GITHUB_OUTPUT @@ -98,7 +88,7 @@ jobs: DOCKER_TLS_VERIFY: 1 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_COMMIT: ${{ steps.git-metadata.outputs.APP_COMMIT }} @@ -121,13 +111,13 @@ jobs: DB_HOSTS: ${{ secrets.DB_HOSTS }} DB_PORT: ${{ secrets.DB_PORT }} - DB_USERNAME: ${{ secrets.DB_STG_USERNAME }} - DB_PASSWORD: ${{ secrets.DB_STG_PASSWORD }} + DB_USERNAME: ${{ inputs.environment == 'staging' && secrets.DB_STG_USERNAME || secrets.DB_PROD_USERNAME }} + DB_PASSWORD: ${{ inputs.environment == 'staging' && secrets.DB_STG_PASSWORD || secrets.DB_PROD_PASSWORD }} DB_DBNAME: ${{ secrets.DB_DBNAME }} INTEGRATION_VKUSVILL_API_TOKEN: ${{ secrets.INTEGRATION_VKUSVILL_API_TOKEN }} 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 "Log level: ${{ inputs.logLevel }}" diff --git a/docker-compose.production.yaml b/docker-compose.production.yaml new file mode 100644 index 0000000..76618bc --- /dev/null +++ b/docker-compose.production.yaml @@ -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 \ No newline at end of file diff --git a/docker-compose.staging.yaml b/docker-compose.staging.yaml index 2781c6d..42313a2 100644 --- a/docker-compose.staging.yaml +++ b/docker-compose.staging.yaml @@ -40,6 +40,8 @@ services: - /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