Compare commits
No commits in common. "airlabs" and "main" have entirely different histories.
@ -3,128 +3,84 @@ name: Build and Deploy
|
|||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
branches:
|
branches:
|
||||||
- airlabs
|
- main
|
||||||
|
- master
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
build-and-deploy:
|
build-and-deploy:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
run: |
|
uses: actions/checkout@v3
|
||||||
git clone --depth=1 --branch=${{ github.ref_name }} https://gitea.airlabs.art/${{ github.repository }}.git .
|
|
||||||
|
|
||||||
- name: Set environment by branch
|
- name: Set up Docker Buildx
|
||||||
run: |
|
uses: docker/setup-buildx-action@v2
|
||||||
SHORT_SHA=$(echo "${{ github.sha }}" | cut -c1-7)
|
with:
|
||||||
BUILD_DATE=$(date +%Y%m%d)
|
config-inline: |
|
||||||
|
[registry."docker.io"]
|
||||||
|
mirrors = ["https://docker.m.daocloud.io", "https://docker.1panel.live", "https://hub.rat.dev"]
|
||||||
|
|
||||||
echo "IMAGE_TAG=internal-${BUILD_DATE}-${SHORT_SHA}" >> $GITHUB_ENV
|
- name: Login to Huawei Cloud SWR
|
||||||
echo "CR_SERVER_ACTIVE=${{ secrets.CR_SERVER }}" >> $GITHUB_ENV
|
uses: docker/login-action@v2
|
||||||
echo "CR_USERNAME_ACTIVE=${{ secrets.CR_USERNAME }}" >> $GITHUB_ENV
|
with:
|
||||||
echo "CR_PASSWORD_ACTIVE=${{ secrets.CR_PASSWORD }}" >> $GITHUB_ENV
|
registry: ${{ secrets.SWR_SERVER }}
|
||||||
echo "CR_ORG=internal" >> $GITHUB_ENV
|
username: ${{ secrets.SWR_USERNAME }}
|
||||||
echo "DEPLOY_ENV=internal" >> $GITHUB_ENV
|
password: ${{ secrets.SWR_PASSWORD }}
|
||||||
echo "DOMAIN_WEB=airgate.airlabs.art" >> $GITHUB_ENV
|
|
||||||
echo "DOMAIN_API=airgate-api.airlabs.art" >> $GITHUB_ENV
|
|
||||||
|
|
||||||
- name: Login to Volcano Engine CR
|
|
||||||
run: |
|
|
||||||
echo "${{ env.CR_PASSWORD_ACTIVE }}" | docker login --username "${{ env.CR_USERNAME_ACTIVE }}" --password-stdin ${{ env.CR_SERVER_ACTIVE }}
|
|
||||||
|
|
||||||
- name: Build and Push Backend
|
- name: Build and Push Backend
|
||||||
id: build_backend
|
id: build_backend
|
||||||
run: |
|
run: |
|
||||||
set -o pipefail
|
set -o pipefail
|
||||||
for attempt in 1 2 3; do
|
docker buildx build \
|
||||||
echo "Build backend attempt $attempt/3..."
|
--push \
|
||||||
DOCKER_BUILDKIT=0 docker build \
|
--provenance=false \
|
||||||
--tag ${{ env.CR_SERVER_ACTIVE }}/${{ env.CR_ORG }}/airgate-backend:${{ env.IMAGE_TAG }} \
|
--tag ${{ secrets.SWR_SERVER }}/${{ secrets.SWR_ORG }}/airgate-backend:latest \
|
||||||
--tag ${{ env.CR_SERVER_ACTIVE }}/${{ env.CR_ORG }}/airgate-backend:latest \
|
./backend 2>&1 | tee /tmp/build.log
|
||||||
./backend 2>&1 | tee /tmp/build.log && break
|
|
||||||
echo "Attempt $attempt failed, retrying in 10s..." && sleep 10
|
|
||||||
done
|
|
||||||
for attempt in 1 2 3; do
|
|
||||||
docker push ${{ env.CR_SERVER_ACTIVE }}/${{ env.CR_ORG }}/airgate-backend:${{ env.IMAGE_TAG }} && \
|
|
||||||
docker push ${{ env.CR_SERVER_ACTIVE }}/${{ env.CR_ORG }}/airgate-backend:latest && break
|
|
||||||
echo "Push attempt $attempt failed, retrying in 10s..." && sleep 10
|
|
||||||
done
|
|
||||||
|
|
||||||
- name: Build and Push Web
|
- name: Build and Push Web
|
||||||
id: build_web
|
id: build_web
|
||||||
run: |
|
run: |
|
||||||
set -o pipefail
|
set -o pipefail
|
||||||
for attempt in 1 2 3; do
|
docker buildx build \
|
||||||
echo "Build web attempt $attempt/3..."
|
--push \
|
||||||
DOCKER_BUILDKIT=0 docker build \
|
--provenance=false \
|
||||||
--tag ${{ env.CR_SERVER_ACTIVE }}/${{ env.CR_ORG }}/airgate-web:${{ env.IMAGE_TAG }} \
|
--tag ${{ secrets.SWR_SERVER }}/${{ secrets.SWR_ORG }}/airgate-web:latest \
|
||||||
--tag ${{ env.CR_SERVER_ACTIVE }}/${{ env.CR_ORG }}/airgate-web:latest \
|
./frontend 2>&1 | tee -a /tmp/build.log
|
||||||
./frontend 2>&1 | tee -a /tmp/build.log && break
|
|
||||||
echo "Attempt $attempt failed, retrying in 10s..." && sleep 10
|
|
||||||
done
|
|
||||||
for attempt in 1 2 3; do
|
|
||||||
docker push ${{ env.CR_SERVER_ACTIVE }}/${{ env.CR_ORG }}/airgate-web:${{ env.IMAGE_TAG }} && \
|
|
||||||
docker push ${{ env.CR_SERVER_ACTIVE }}/${{ env.CR_ORG }}/airgate-web:latest && break
|
|
||||||
echo "Push attempt $attempt failed, retrying in 10s..." && sleep 10
|
|
||||||
done
|
|
||||||
|
|
||||||
- name: Setup Kubectl
|
- name: Setup SSH
|
||||||
run: |
|
run: |
|
||||||
if ! command -v kubectl &>/dev/null; then
|
mkdir -p ~/.ssh
|
||||||
for attempt in 1 2 3; do
|
echo "${{ secrets.K3S_SSH_KEY }}" > ~/.ssh/id_rsa
|
||||||
curl -LO "https://files.m.daocloud.io/dl.k8s.io/release/v1.28.0/bin/linux/amd64/kubectl" && break
|
chmod 600 ~/.ssh/id_rsa
|
||||||
echo "Download attempt $attempt failed, retrying in 5s..." && sleep 5
|
ssh-keyscan -H ${{ secrets.K3S_HOST }} >> ~/.ssh/known_hosts 2>/dev/null
|
||||||
done
|
|
||||||
chmod +x kubectl && mv kubectl /usr/bin/kubectl
|
|
||||||
fi
|
|
||||||
kubectl version --client
|
|
||||||
|
|
||||||
- name: Set kubeconfig
|
- name: Deploy to K3s via SSH
|
||||||
run: |
|
|
||||||
mkdir -p $HOME/.kube
|
|
||||||
printf '%s\n' '${{ secrets.VOLCANO_INTERNAL_KUBE_CONFIG }}' > $HOME/.kube/config
|
|
||||||
chmod 600 $HOME/.kube/config
|
|
||||||
echo "kubeconfig lines: $(wc -l < $HOME/.kube/config)"
|
|
||||||
grep server $HOME/.kube/config || echo "WARNING: no server found in kubeconfig"
|
|
||||||
|
|
||||||
- name: Deploy to K3s
|
|
||||||
id: deploy
|
id: deploy
|
||||||
run: |
|
run: |
|
||||||
echo "Environment: ${{ env.DEPLOY_ENV }}"
|
SWR_IMAGE="${{ secrets.SWR_SERVER }}/${{ secrets.SWR_ORG }}"
|
||||||
CR_IMAGE="${{ env.CR_SERVER_ACTIVE }}/${{ env.CR_ORG }}"
|
|
||||||
|
|
||||||
# Replace image placeholders
|
# Replace image placeholders in yaml files
|
||||||
sed -i "s|\${CI_REGISTRY_IMAGE}/airgate-backend:latest|${CR_IMAGE}/airgate-backend:${{ env.IMAGE_TAG }}|g" k8s/backend-deployment.yaml
|
sed -i "s|\${CI_REGISTRY_IMAGE}/airgate-backend:latest|${SWR_IMAGE}/airgate-backend:latest|g" k8s/backend-deployment.yaml
|
||||||
sed -i "s|\${CI_REGISTRY_IMAGE}/airgate-web:latest|${CR_IMAGE}/airgate-web:${{ env.IMAGE_TAG }}|g" k8s/web-deployment.yaml
|
sed -i "s|\${CI_REGISTRY_IMAGE}/airgate-web:latest|${SWR_IMAGE}/airgate-web:latest|g" k8s/web-deployment.yaml
|
||||||
|
|
||||||
# Replace domain placeholders in ingress
|
# Copy k8s manifests to server
|
||||||
sed -i "s|airgate.airlabs.art|${{ env.DOMAIN_WEB }}|g" k8s/ingress.yaml
|
scp -o StrictHostKeyChecking=no k8s/backend-deployment.yaml k8s/web-deployment.yaml k8s/ingress.yaml root@${{ secrets.K3S_HOST }}:/tmp/
|
||||||
sed -i "s|airgate-api.airlabs.art|${{ env.DOMAIN_API }}|g" k8s/ingress.yaml
|
|
||||||
|
|
||||||
# Replace CORS origin
|
# Create/update secrets and apply manifests on server
|
||||||
sed -i "s|https://airgate.airlabs.art|https://${{ env.DOMAIN_WEB }}|g" k8s/backend-deployment.yaml
|
set -o pipefail
|
||||||
|
ssh -o StrictHostKeyChecking=no root@${{ secrets.K3S_HOST }} << ENDSSH
|
||||||
|
export KUBECONFIG=/etc/rancher/k3s/k3s.yaml
|
||||||
|
|
||||||
for attempt in 1 2 3; do
|
kubectl apply -f /tmp/backend-deployment.yaml
|
||||||
echo "Deploy attempt $attempt/3..."
|
kubectl apply -f /tmp/web-deployment.yaml
|
||||||
{
|
kubectl apply -f /tmp/ingress.yaml
|
||||||
# Create/update image pull secret
|
kubectl rollout restart deployment/airgate-backend
|
||||||
kubectl create secret docker-registry cr-pull-secret \
|
kubectl rollout restart deployment/airgate-web
|
||||||
--docker-server="${{ env.CR_SERVER_ACTIVE }}" \
|
|
||||||
--docker-username="${{ env.CR_USERNAME_ACTIVE }}" \
|
|
||||||
--docker-password="${{ env.CR_PASSWORD_ACTIVE }}" \
|
|
||||||
--dry-run=client -o yaml | kubectl apply -f -
|
|
||||||
|
|
||||||
# Apply manifests
|
rm -f /tmp/backend-deployment.yaml /tmp/web-deployment.yaml /tmp/ingress.yaml
|
||||||
kubectl apply -f k8s/backend-deployment.yaml
|
ENDSSH
|
||||||
kubectl apply -f k8s/web-deployment.yaml
|
|
||||||
kubectl apply -f k8s/ingress.yaml
|
|
||||||
|
|
||||||
kubectl rollout restart deployment/airgate-backend
|
|
||||||
kubectl rollout restart deployment/airgate-web
|
|
||||||
} 2>&1 | tee /tmp/deploy.log && break
|
|
||||||
echo "Attempt $attempt failed, retrying in 10s..."
|
|
||||||
sleep 10
|
|
||||||
done
|
|
||||||
|
|
||||||
|
# ===== Log Center: failure reporting =====
|
||||||
- name: Report failure to Log Center
|
- name: Report failure to Log Center
|
||||||
if: failure()
|
if: failure()
|
||||||
run: |
|
run: |
|
||||||
@ -161,11 +117,11 @@ jobs:
|
|||||||
-H "Content-Type: application/json" \
|
-H "Content-Type: application/json" \
|
||||||
-d "{
|
-d "{
|
||||||
\"project_id\": \"airgate\",
|
\"project_id\": \"airgate\",
|
||||||
\"environment\": \"${{ env.DEPLOY_ENV }}\",
|
\"environment\": \"${{ github.ref_name }}\",
|
||||||
\"level\": \"ERROR\",
|
\"level\": \"ERROR\",
|
||||||
\"source\": \"${SOURCE}\",
|
\"source\": \"${SOURCE}\",
|
||||||
\"commit_hash\": \"${{ github.sha }}\",
|
\"commit_hash\": \"${{ github.sha }}\",
|
||||||
\"repo_url\": \"https://gitea.airlabs.art/${{ github.repository }}.git\",
|
\"repo_url\": \"${{ github.server_url }}/${{ github.repository }}\",
|
||||||
\"error\": {
|
\"error\": {
|
||||||
\"type\": \"${ERROR_TYPE}\",
|
\"type\": \"${ERROR_TYPE}\",
|
||||||
\"message\": \"[${FAILED_STEP}] Build and Deploy failed on branch ${{ github.ref_name }}\",
|
\"message\": \"[${FAILED_STEP}] Build and Deploy failed on branch ${{ github.ref_name }}\",
|
||||||
@ -179,15 +135,6 @@ jobs:
|
|||||||
\"branch\": \"${{ github.ref_name }}\",
|
\"branch\": \"${{ github.ref_name }}\",
|
||||||
\"actor\": \"${{ github.actor }}\",
|
\"actor\": \"${{ github.actor }}\",
|
||||||
\"commit\": \"${{ github.sha }}\",
|
\"commit\": \"${{ github.sha }}\",
|
||||||
\"run_url\": \"https://gitea.airlabs.art/${{ github.repository }}/actions/runs/${{ github.run_number }}\"
|
\"run_url\": \"${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_number }}\"
|
||||||
}
|
}
|
||||||
}" || true
|
}" || true
|
||||||
|
|
||||||
- name: Docker Cleanup
|
|
||||||
if: always()
|
|
||||||
run: |
|
|
||||||
docker container prune -f
|
|
||||||
docker image prune -f
|
|
||||||
docker builder prune -a -f
|
|
||||||
echo "Disk usage after cleanup:"
|
|
||||||
df -h / | tail -1
|
|
||||||
|
|||||||
@ -15,7 +15,7 @@ spec:
|
|||||||
app: airgate-backend
|
app: airgate-backend
|
||||||
spec:
|
spec:
|
||||||
imagePullSecrets:
|
imagePullSecrets:
|
||||||
- name: cr-pull-secret
|
- name: swr-secret
|
||||||
containers:
|
containers:
|
||||||
- name: airgate-backend
|
- name: airgate-backend
|
||||||
image: ${CI_REGISTRY_IMAGE}/airgate-backend:latest
|
image: ${CI_REGISTRY_IMAGE}/airgate-backend:latest
|
||||||
|
|||||||
@ -15,7 +15,7 @@ spec:
|
|||||||
app: airgate-web
|
app: airgate-web
|
||||||
spec:
|
spec:
|
||||||
imagePullSecrets:
|
imagePullSecrets:
|
||||||
- name: cr-pull-secret
|
- name: swr-secret
|
||||||
containers:
|
containers:
|
||||||
- name: airgate-web
|
- name: airgate-web
|
||||||
image: ${CI_REGISTRY_IMAGE}/airgate-web:latest
|
image: ${CI_REGISTRY_IMAGE}/airgate-web:latest
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user