Skip to content

Commit

Permalink
Merge branch 'dev' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
jaggerwang authored Oct 9, 2023
2 parents c8afa1c + d03335e commit adcadc5
Show file tree
Hide file tree
Showing 20 changed files with 134 additions and 660 deletions.
241 changes: 3 additions & 238 deletions .ops/.gitlab-ci.yml
Original file line number Diff line number Diff line change
@@ -1,242 +1,7 @@
stages:
- build-package
- build-image
- deploy
include:
- project: 'basicai/xtreme1/common'
file: '/ci/template/xtreme1-app.yml'

variables:
APP_NAME: "xtreme1"
APP_VERSION: "0.7.2"

FRONTEND_PACKAGE_DIR: "dist"
BACKEND_PACKAGE_NAME: "${APP_NAME}-backend-${APP_VERSION}-SNAPSHOT.jar"

FRONTEND_IMAGE_NAME: "$CI_REGISTRY_IMAGE/frontend"
BACKEND_IMAGE_NAME: "$CI_REGISTRY_IMAGE/backend"

DOCKER_HUB_FRONTEND_IMAGE_NAME: "basicai/${APP_NAME}-frontend"
DOCKER_HUB_BACKEND_IMAGE_NAME: "basicai/${APP_NAME}-backend"

KUBERNETES_NAMESPACE: "x1-community"

build-backend-package:
stage: build-package
tags:
- openjdk-11
rules:
- if: $CI_COMMIT_BRANCH == "dev" || $CI_COMMIT_BRANCH == "main"
changes:
- .ops/*
- .ops/**/*
- backend/*
- backend/**/*
- if: $CI_COMMIT_TAG =~ /^v/
variables:
MAVEN_OPTS: "-Dmaven.repo.local=$CI_PROJECT_DIR/backend/.m2/repository"
MAVEN_ARGS: "--batch-mode"
script:
- cd backend
- mvn $MAVEN_ARGS package
artifacts:
paths:
- backend/target/$BACKEND_PACKAGE_NAME
cache:
paths:
- backend/.m2/repository

build-frontend-package:
stage: build-package
tags:
- nodejs-16
rules:
- if: $CI_COMMIT_BRANCH == "dev" || $CI_COMMIT_BRANCH == "main"
changes:
- .ops/*
- .ops/**/*
- frontend/*
- frontend/**/*
- if: $CI_COMMIT_TAG =~ /^v/
script:
- cd frontend/main
- npm install
- npm run build
- cd ../image-tool
- npm install
- npm run build
- cd ../pc-tool
- npm install
- npm run build
- cd ../text-tool
- npm install
- npm run build
artifacts:
paths:
- frontend/$FRONTEND_PACKAGE_DIR
cache:
paths:
- frontend/main/node_modules
- frontend/image-tool/node_modules
- frontend/pc-tool/node_modules
- frontend/text-tool/node_modules

build-release-package:
stage: build-package
tags:
- ubuntu
rules:
- if: $CI_COMMIT_BRANCH == "dev" || $CI_COMMIT_BRANCH == "main"
changes:
- .ops/*
- .ops/**/*
- deploy/*
- deploy/**/*
- docker-compose.yml
- if: $CI_COMMIT_TAG =~ /^v/
script:
- ls
artifacts:
name: "${APP_NAME}-${CI_COMMIT_REF_NAME}"
paths:
- deploy/
- docker-compose.yml

.build-image:
stage: build-image
tags:
- docker
variables:
DOCKER_HOST: tcp://docker:2376
DOCKER_TLS_CERTDIR: "/certs"
DOCKER_TLS_VERIFY: 1
DOCKER_CERT_PATH: "$DOCKER_TLS_CERTDIR/client"
services:
- docker:20-dind
before_script:
- until docker info; do sleep 1; done
- docker login -u $CI_DEPLOY_USER -p $CI_DEPLOY_PASSWORD $CI_REGISTRY
- docker login -u $DOCKER_HUB_REGISTRY_USER -p $DOCKER_HUB_REGISTRY_PASS
after_script:
- cd $WORKING_DIR
- docker pull $IMAGE_NAME:latest || true
- docker build --cache-from $IMAGE_NAME:latest -t $IMAGE_NAME:$CI_COMMIT_REF_NAME -t $IMAGE_NAME:$CI_COMMIT_SHORT_SHA -t $IMAGE_NAME:latest .
- docker push $IMAGE_NAME:$CI_COMMIT_REF_NAME
- docker push $IMAGE_NAME:$CI_COMMIT_SHORT_SHA
- docker push $IMAGE_NAME:latest
# Push main and tag image to Docker Hub.
# - if [[ $CI_COMMIT_REF_NAME == main ]]; then docker tag $IMAGE_NAME:$CI_COMMIT_REF_NAME $DOCKER_HUB_IMAGE_NAME:latest; docker push $DOCKER_HUB_IMAGE_NAME:latest; fi
# - if [[ $CI_COMMIT_REF_NAME == v* ]]; then docker tag $IMAGE_NAME:$CI_COMMIT_REF_NAME $DOCKER_HUB_IMAGE_NAME:$CI_COMMIT_REF_NAME; docker push $DOCKER_HUB_IMAGE_NAME:$CI_COMMIT_REF_NAME; fi

build-backend-image:
extends: .build-image
rules:
- if: $CI_COMMIT_BRANCH == "dev" || $CI_COMMIT_BRANCH == "main"
changes:
- .ops/*
- .ops/**/*
- backend/*
- backend/**/*
- if: $CI_COMMIT_TAG =~ /^v/
variables:
WORKING_DIR: backend
IMAGE_NAME: $BACKEND_IMAGE_NAME
DOCKER_HUB_IMAGE_NAME: $DOCKER_HUB_BACKEND_IMAGE_NAME
script:
- cd $WORKING_DIR
- cp ../.ops/backend.dockerfile ./Dockerfile
- cp ../.ops/backend.dockerignore ./.dockerignore
- sed -i 's/$BACKEND_PACKAGE_NAME/'"$BACKEND_PACKAGE_NAME"'/g' Dockerfile

build-frontend-image:
extends: .build-image
rules:
- if: $CI_COMMIT_BRANCH == "dev" || $CI_COMMIT_BRANCH == "main"
changes:
- .ops/*
- .ops/**/*
- frontend/*
- frontend/**/*
- if: $CI_COMMIT_TAG =~ /^v/
variables:
WORKING_DIR: frontend
IMAGE_NAME: $FRONTEND_IMAGE_NAME
DOCKER_HUB_IMAGE_NAME: $DOCKER_HUB_FRONTEND_IMAGE_NAME
script:
- cd $WORKING_DIR
- cp ../.ops/frontend.dockerfile ./Dockerfile
- cp ../.ops/frontend.dockerignore ./.dockerignore
- sed -i 's/$FRONTEND_PACKAGE_DIR/'"$FRONTEND_PACKAGE_DIR"'/g' Dockerfile

.deploy:
stage: deploy
tags:
- kubectl
before_script:
- cd .ops/$ENV
- sed -i 's/$APP_NAME/'"$APP_NAME"'/g' $DEPLOYMENT
- sed -i 's/$APP_VERSION/'"$APP_VERSION"'/g' $DEPLOYMENT
- sed -i 's/$CI_COMMIT_SHORT_SHA/'"$CI_COMMIT_SHORT_SHA"'/g' $DEPLOYMENT

deploy-backend-to-alidev:
extends: .deploy
rules:
- if: $CI_COMMIT_BRANCH == "dev"
changes:
- .ops/*
- .ops/**/*
- backend/*
- backend/**/*
variables:
ENV: alidev
DEPLOYMENT: backend-deployment.yml
script:
- sed -i 's|$BACKEND_IMAGE_NAME|'"$BACKEND_IMAGE_NAME"'|g' $DEPLOYMENT
- kubectl apply -f $DEPLOYMENT -n $KUBERNETES_NAMESPACE --kubeconfig=$KUBECONFIG_ALIYUN_DEVELOPMENT

deploy-frontend-to-alidev:
extends: .deploy
rules:
- if: $CI_COMMIT_BRANCH == "dev"
changes:
- .ops/*
- .ops/**/*
- frontend/*
- frontend/**/*
variables:
ENV: alidev
DEPLOYMENT: frontend-deployment.yml
script:
- sed -i 's|$FRONTEND_IMAGE_NAME|'"$FRONTEND_IMAGE_NAME"'|g' $DEPLOYMENT
- kubectl apply -f $DEPLOYMENT -n $KUBERNETES_NAMESPACE --kubeconfig=$KUBECONFIG_ALIYUN_DEVELOPMENT

deploy-backend-to-alitest:
extends: .deploy
rules:
- if: $CI_COMMIT_BRANCH == "dev"
changes:
- .ops/*
- .ops/**/*
- backend/*
- backend/**/*
when: manual
variables:
ENV: alitest
DEPLOYMENT: backend-deployment.yml
script:
- sed -i 's|$BACKEND_IMAGE_NAME|'"$BACKEND_IMAGE_NAME"'|g' $DEPLOYMENT
- kubectl apply -f $DEPLOYMENT -n $KUBERNETES_NAMESPACE --kubeconfig=$KUBECONFIG_ALIYUN_TESTING

deploy-frontend-to-alitest:
extends: .deploy
rules:
- if: $CI_COMMIT_BRANCH == "dev"
changes:
- .ops/*
- .ops/**/*
- frontend/*
- frontend/**/*
when: manual
variables:
ENV: alitest
DEPLOYMENT: frontend-deployment.yml
script:
- sed -i 's|$FRONTEND_IMAGE_NAME|'"$FRONTEND_IMAGE_NAME"'|g' $DEPLOYMENT
- kubectl apply -f $DEPLOYMENT -n $KUBERNETES_NAMESPACE --kubeconfig=$KUBECONFIG_ALIYUN_TESTING
14 changes: 7 additions & 7 deletions .ops/alidev/backend-deployment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ spec:
replicas: 1
selector:
matchLabels:
app.kubernetes.io/name: x1-community
app.kubernetes.io/instance: x1-community
app.kubernetes.io/name: xtreme1
app.kubernetes.io/instance: xtreme1
app.kubernetes.io/component: backend
template:
metadata:
labels:
app.kubernetes.io/name: x1-community
app.kubernetes.io/instance: x1-community
app.kubernetes.io/name: xtreme1
app.kubernetes.io/instance: xtreme1
app.kubernetes.io/component: backend
spec:
nodeSelector:
Expand All @@ -22,7 +22,7 @@ spec:
- name: basicai-registry
containers:
- name: backend
image: $BACKEND_IMAGE_NAME:$CI_COMMIT_SHORT_SHA
image: $BACKEND_IMAGE
env:
- name: JAVA_OPTS
value: "-XX:InitialRAMPercentage=20.0 -XX:MinRAMPercentage=80.0 -XX:MaxRAMPercentage=80.0 -XshowSettings:vm"
Expand Down Expand Up @@ -68,8 +68,8 @@ metadata:
name: backend
spec:
selector:
app.kubernetes.io/name: x1-community
app.kubernetes.io/instance: x1-community
app.kubernetes.io/name: xtreme1
app.kubernetes.io/instance: xtreme1
app.kubernetes.io/component: backend
ports:
- name: http
Expand Down
14 changes: 7 additions & 7 deletions .ops/alidev/frontend-deployment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ spec:
replicas: 1
selector:
matchLabels:
app.kubernetes.io/name: x1-community
app.kubernetes.io/instance: x1-community
app.kubernetes.io/name: xtreme1
app.kubernetes.io/instance: xtreme1
app.kubernetes.io/component: frontend
template:
metadata:
labels:
app.kubernetes.io/name: x1-community
app.kubernetes.io/instance: x1-community
app.kubernetes.io/name: xtreme1
app.kubernetes.io/instance: xtreme1
app.kubernetes.io/component: frontend
spec:
nodeSelector:
Expand All @@ -22,7 +22,7 @@ spec:
- name: basicai-registry
containers:
- name: frontend
image: $FRONTEND_IMAGE_NAME:$CI_COMMIT_SHORT_SHA
image: $FRONTEND_IMAGE
resources:
requests:
memory: 200Mi
Expand All @@ -40,8 +40,8 @@ metadata:
name: frontend
spec:
selector:
app.kubernetes.io/name: x1-community
app.kubernetes.io/instance: x1-community
app.kubernetes.io/name: xtreme1
app.kubernetes.io/instance: xtreme1
app.kubernetes.io/component: frontend
ports:
- name: http
Expand Down
Loading

0 comments on commit adcadc5

Please sign in to comment.