fix: auto repair bugs #85
This commit is contained in:
parent
6733bcf41c
commit
394f30255e
@ -1,10 +1,11 @@
|
|||||||
name: Build and Deploy Log Center
|
name: Build and Deploy Log Center
|
||||||
|
|
||||||
on:
|
"on":
|
||||||
push:
|
push:
|
||||||
branches:
|
branches:
|
||||||
- main
|
- main
|
||||||
- master
|
- master
|
||||||
|
- dev
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
build-and-deploy:
|
build-and-deploy:
|
||||||
@ -13,78 +14,85 @@ jobs:
|
|||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: actions/checkout@v3
|
uses: actions/checkout@v3
|
||||||
|
|
||||||
- name: Set up Docker Buildx
|
- name: Set environment by branch
|
||||||
uses: docker/setup-buildx-action@v2
|
run: |
|
||||||
with:
|
SHORT_SHA=$(echo "${{ github.sha }}" | cut -c1-7)
|
||||||
config-inline: |
|
BUILD_DATE=$(date +%Y%m%d)
|
||||||
[registry."docker.io"]
|
|
||||||
mirrors = ["https://docker.m.daocloud.io", "https://docker.1panel.live", "https://hub.rat.dev"]
|
|
||||||
|
|
||||||
- name: Login to Huawei Cloud SWR
|
if [[ "${{ github.ref_name }}" == "main" || "${{ github.ref_name }}" == "master" ]]; then
|
||||||
uses: docker/login-action@v2
|
echo "IMAGE_TAG=prod-${BUILD_DATE}-${SHORT_SHA}" >> $GITHUB_ENV
|
||||||
with:
|
echo "DEPLOY_ENV=production" >> $GITHUB_ENV
|
||||||
registry: ${{ secrets.SWR_SERVER }}
|
echo "DOMAIN_API=qiyuan-log-center-api.airlabs.art" >> $GITHUB_ENV
|
||||||
username: ${{ secrets.SWR_USERNAME }}
|
echo "DOMAIN_WEB=qiyuan-log-center-web.airlabs.art" >> $GITHUB_ENV
|
||||||
password: ${{ secrets.SWR_PASSWORD }}
|
elif [[ "${{ github.ref_name }}" == "dev" ]]; then
|
||||||
|
echo "IMAGE_TAG=dev-${BUILD_DATE}-${SHORT_SHA}" >> $GITHUB_ENV
|
||||||
|
echo "DEPLOY_ENV=development" >> $GITHUB_ENV
|
||||||
|
echo "DOMAIN_API=qiyuan-log-center-api.test.airlabs.art" >> $GITHUB_ENV
|
||||||
|
echo "DOMAIN_WEB=qiyuan-log-center-web.test.airlabs.art" >> $GITHUB_ENV
|
||||||
|
fi
|
||||||
|
|
||||||
|
- name: Login to Registry
|
||||||
|
run: |
|
||||||
|
echo "${{ secrets.SWR_PASSWORD }}" | docker login --username "${{ secrets.SWR_USERNAME }}" --password-stdin ${{ secrets.SWR_SERVER }}
|
||||||
|
|
||||||
# Build API Image
|
# Build API Image
|
||||||
- name: Build and Push API
|
- name: Build and Push API
|
||||||
id: build-api
|
id: build-api
|
||||||
run: |
|
run: |
|
||||||
set -o pipefail
|
set -o pipefail
|
||||||
docker buildx build \
|
docker build \
|
||||||
--push \
|
--tag ${{ secrets.SWR_SERVER }}/${{ secrets.SWR_ORG }}/log-center-api:${{ env.IMAGE_TAG }} \
|
||||||
--provenance=false \
|
|
||||||
--tag ${{ secrets.SWR_SERVER }}/${{ secrets.SWR_ORG }}/log-center-api:latest \
|
--tag ${{ secrets.SWR_SERVER }}/${{ secrets.SWR_ORG }}/log-center-api:latest \
|
||||||
-f ./Dockerfile \
|
-f ./Dockerfile \
|
||||||
. 2>&1 | tee /tmp/build-api.log
|
. 2>&1 | tee /tmp/build-api.log
|
||||||
|
docker push ${{ secrets.SWR_SERVER }}/${{ secrets.SWR_ORG }}/log-center-api:${{ env.IMAGE_TAG }}
|
||||||
|
docker push ${{ secrets.SWR_SERVER }}/${{ secrets.SWR_ORG }}/log-center-api:latest
|
||||||
|
|
||||||
# Build Web Image
|
# Build Web Image
|
||||||
- name: Build and Push Web
|
- name: Build and Push Web
|
||||||
id: build-web
|
id: build-web
|
||||||
run: |
|
run: |
|
||||||
set -o pipefail
|
set -o pipefail
|
||||||
docker buildx build \
|
docker build \
|
||||||
--push \
|
--build-arg VITE_API_BASE_URL=https://${{ env.DOMAIN_API }} \
|
||||||
--provenance=false \
|
--tag ${{ secrets.SWR_SERVER }}/${{ secrets.SWR_ORG }}/log-center-web:${{ env.IMAGE_TAG }} \
|
||||||
--build-arg VITE_API_BASE_URL=https://qiyuan-log-center-api.airlabs.art \
|
|
||||||
--tag ${{ secrets.SWR_SERVER }}/${{ secrets.SWR_ORG }}/log-center-web:latest \
|
--tag ${{ secrets.SWR_SERVER }}/${{ secrets.SWR_ORG }}/log-center-web:latest \
|
||||||
-f ./web/Dockerfile \
|
-f ./web/Dockerfile \
|
||||||
./web 2>&1 | tee /tmp/build-web.log
|
./web 2>&1 | tee /tmp/build-web.log
|
||||||
|
docker push ${{ secrets.SWR_SERVER }}/${{ secrets.SWR_ORG }}/log-center-web:${{ env.IMAGE_TAG }}
|
||||||
|
docker push ${{ secrets.SWR_SERVER }}/${{ secrets.SWR_ORG }}/log-center-web:latest
|
||||||
|
|
||||||
# Build K8s Monitor Image
|
# Build K8s Monitor Image
|
||||||
- name: Build and Push K8s Monitor
|
- name: Build and Push K8s Monitor
|
||||||
id: build-monitor
|
id: build-monitor
|
||||||
run: |
|
run: |
|
||||||
set -o pipefail
|
set -o pipefail
|
||||||
docker buildx build \
|
docker build \
|
||||||
--push \
|
--tag ${{ secrets.SWR_SERVER }}/${{ secrets.SWR_ORG }}/k8s-pod-monitor:${{ env.IMAGE_TAG }} \
|
||||||
--provenance=false \
|
|
||||||
--tag ${{ secrets.SWR_SERVER }}/${{ secrets.SWR_ORG }}/k8s-pod-monitor:latest \
|
--tag ${{ secrets.SWR_SERVER }}/${{ secrets.SWR_ORG }}/k8s-pod-monitor:latest \
|
||||||
-f ./k8s-monitor/Dockerfile \
|
-f ./k8s-monitor/Dockerfile \
|
||||||
./k8s-monitor 2>&1 | tee /tmp/build-monitor.log
|
./k8s-monitor 2>&1 | tee /tmp/build-monitor.log
|
||||||
|
docker push ${{ secrets.SWR_SERVER }}/${{ secrets.SWR_ORG }}/k8s-pod-monitor:${{ env.IMAGE_TAG }}
|
||||||
|
docker push ${{ secrets.SWR_SERVER }}/${{ secrets.SWR_ORG }}/k8s-pod-monitor:latest
|
||||||
|
|
||||||
- name: Setup Kubectl
|
- name: Setup Kubectl and Kubeconfig
|
||||||
run: |
|
run: |
|
||||||
curl -LO "https://files.m.daocloud.io/dl.k8s.io/release/v1.28.2/bin/linux/amd64/kubectl"
|
curl -LO "https://files.m.daocloud.io/dl.k8s.io/release/v1.28.2/bin/linux/amd64/kubectl"
|
||||||
chmod +x kubectl
|
chmod +x kubectl
|
||||||
mv kubectl /usr/local/bin/
|
mv kubectl /usr/local/bin/
|
||||||
|
mkdir -p $HOME/.kube
|
||||||
|
echo "${{ secrets.KUBE_CONFIG }}" > $HOME/.kube/config
|
||||||
|
chmod 600 $HOME/.kube/config
|
||||||
|
|
||||||
- name: Deploy to K3s
|
- name: Deploy to K8s
|
||||||
uses: Azure/k8s-set-context@v3
|
|
||||||
with:
|
|
||||||
method: kubeconfig
|
|
||||||
kubeconfig: ${{ secrets.KUBE_CONFIG }}
|
|
||||||
|
|
||||||
- name: Update K8s Manifests
|
|
||||||
id: deploy
|
id: deploy
|
||||||
run: |
|
run: |
|
||||||
echo "Environment: Production"
|
echo "Environment: ${{ env.DEPLOY_ENV }}"
|
||||||
|
|
||||||
# Replace image placeholders
|
# Replace image placeholders
|
||||||
sed -i "s|\${CI_REGISTRY_IMAGE}/log-center-api:latest|${{ secrets.SWR_SERVER }}/${{ secrets.SWR_ORG }}/log-center-api:latest|g" k8s/api-deployment-prod.yaml
|
sed -i "s|\${CI_REGISTRY_IMAGE}/log-center-api:latest|${{ secrets.SWR_SERVER }}/${{ secrets.SWR_ORG }}/log-center-api:${{ env.IMAGE_TAG }}|g" k8s/api-deployment-prod.yaml
|
||||||
sed -i "s|\${CI_REGISTRY_IMAGE}/log-center-web:latest|${{ secrets.SWR_SERVER }}/${{ secrets.SWR_ORG }}/log-center-web:latest|g" k8s/web-deployment-prod.yaml
|
sed -i "s|\${CI_REGISTRY_IMAGE}/log-center-web:latest|${{ secrets.SWR_SERVER }}/${{ secrets.SWR_ORG }}/log-center-web:${{ env.IMAGE_TAG }}|g" k8s/web-deployment-prod.yaml
|
||||||
sed -i "s|\${CI_REGISTRY_IMAGE}/k8s-pod-monitor:latest|${{ secrets.SWR_SERVER }}/${{ secrets.SWR_ORG }}/k8s-pod-monitor:latest|g" k8s/monitor-cronjob.yaml
|
sed -i "s|\${CI_REGISTRY_IMAGE}/k8s-pod-monitor:latest|${{ secrets.SWR_SERVER }}/${{ secrets.SWR_ORG }}/k8s-pod-monitor:${{ env.IMAGE_TAG }}|g" k8s/monitor-cronjob.yaml
|
||||||
|
|
||||||
# Apply configurations and capture output
|
# Apply configurations and capture output
|
||||||
set -o pipefail
|
set -o pipefail
|
||||||
|
|||||||
@ -5,7 +5,7 @@ WORKDIR /app
|
|||||||
|
|
||||||
# Install dependencies
|
# Install dependencies
|
||||||
COPY requirements.txt ./
|
COPY requirements.txt ./
|
||||||
RUN pip install --no-cache-dir -r requirements.txt
|
RUN pip install --no-cache-dir -i https://mirrors.aliyun.com/pypi/simple/ --trusted-host mirrors.aliyun.com -r requirements.txt
|
||||||
|
|
||||||
# Production stage
|
# Production stage
|
||||||
FROM python:3.12-slim AS production-stage
|
FROM python:3.12-slim AS production-stage
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user