fix(ci/cd)
This commit is contained in:
@@ -74,36 +74,92 @@ jobs:
|
|||||||
- name: Checkout code
|
- name: Checkout code
|
||||||
uses: actions/checkout@v3
|
uses: actions/checkout@v3
|
||||||
|
|
||||||
|
- name: Force IPv4 for DNS
|
||||||
|
run: |
|
||||||
|
echo 'precedence ::ffff:0:0/96 100' | sudo tee -a /etc/gai.conf
|
||||||
|
|
||||||
- name: Set up Docker Buildx
|
- name: Set up Docker Buildx
|
||||||
uses: docker/setup-buildx-action@v2
|
uses: docker/setup-buildx-action@v2
|
||||||
|
|
||||||
- name: Login to Gitea Container Registry
|
- name: Login to Gitea Container Registry (with retry)
|
||||||
uses: docker/login-action@v2
|
run: |
|
||||||
with:
|
for i in 1 2 3 4 5; do
|
||||||
registry: ${{ secrets.REGISTRY_URL }}
|
echo "🔐 Login attempt $i..."
|
||||||
username: ${{ secrets.REGISTRY_USERNAME }}
|
echo "${{ secrets.REGISTRY_TOKEN }}" | docker login ${{ secrets.REGISTRY_URL }} -u ${{ secrets.REGISTRY_USERNAME }} --password-stdin && break || sleep 5
|
||||||
password: ${{ secrets.REGISTRY_TOKEN }}
|
done
|
||||||
|
|
||||||
- name: Build and push backend image
|
# ===== BACKEND =====
|
||||||
|
- name: Build backend image
|
||||||
uses: docker/build-push-action@v4
|
uses: docker/build-push-action@v4
|
||||||
with:
|
with:
|
||||||
context: ./backend
|
context: ./backend
|
||||||
file: ./backend/Dockerfile
|
file: ./backend/Dockerfile
|
||||||
push: true
|
push: false
|
||||||
|
load: true
|
||||||
tags: |
|
tags: |
|
||||||
${{ secrets.REGISTRY_URL }}/${{ secrets.REGISTRY_USERNAME }}/lediscord-backend:prod
|
${{ secrets.REGISTRY_URL }}/${{ secrets.REGISTRY_USERNAME }}/lediscord:prod-backend
|
||||||
${{ secrets.REGISTRY_URL }}/${{ secrets.REGISTRY_USERNAME }}/lediscord-backend:latest
|
${{ secrets.REGISTRY_URL }}/${{ secrets.REGISTRY_USERNAME }}/lediscord:latest-backend
|
||||||
cache-from: type=registry,ref=${{ secrets.REGISTRY_URL }}/${{ secrets.REGISTRY_USERNAME }}/lediscord-backend:prod
|
cache-from: type=registry,ref=${{ secrets.REGISTRY_URL }}/${{ secrets.REGISTRY_USERNAME }}/lediscord:prod-backend
|
||||||
cache-to: type=inline
|
cache-to: type=inline
|
||||||
|
|
||||||
- name: Build and push frontend image
|
- name: Push backend image (with retry)
|
||||||
|
run: |
|
||||||
|
push_with_retry() {
|
||||||
|
local image=$1
|
||||||
|
for i in 1 2 3 4 5; do
|
||||||
|
echo "📤 Push attempt $i for $image..."
|
||||||
|
if docker push "$image"; then
|
||||||
|
echo "✅ Successfully pushed $image"
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
echo "⚠️ Push failed, waiting 10s..."
|
||||||
|
sleep 10
|
||||||
|
done
|
||||||
|
echo "❌ Failed to push $image after 5 attempts"
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
|
||||||
|
push_with_retry "${{ secrets.REGISTRY_URL }}/${{ secrets.REGISTRY_USERNAME }}/lediscord:prod-backend"
|
||||||
|
push_with_retry "${{ secrets.REGISTRY_URL }}/${{ secrets.REGISTRY_USERNAME }}/lediscord:latest-backend"
|
||||||
|
|
||||||
|
# ===== FRONTEND =====
|
||||||
|
- name: Build frontend image
|
||||||
uses: docker/build-push-action@v4
|
uses: docker/build-push-action@v4
|
||||||
with:
|
with:
|
||||||
context: ./frontend
|
context: ./frontend
|
||||||
file: ./frontend/Dockerfile
|
file: ./frontend/Dockerfile
|
||||||
push: true
|
push: false
|
||||||
|
load: true
|
||||||
tags: |
|
tags: |
|
||||||
${{ secrets.REGISTRY_URL }}/${{ secrets.REGISTRY_USERNAME }}/lediscord-frontend:prod
|
${{ secrets.REGISTRY_URL }}/${{ secrets.REGISTRY_USERNAME }}/lediscord:prod-frontend
|
||||||
${{ secrets.REGISTRY_URL }}/${{ secrets.REGISTRY_USERNAME }}/lediscord-frontend:latest
|
${{ secrets.REGISTRY_URL }}/${{ secrets.REGISTRY_USERNAME }}/lediscord:latest-frontend
|
||||||
cache-from: type=registry,ref=${{ secrets.REGISTRY_URL }}/${{ secrets.REGISTRY_USERNAME }}/lediscord-frontend:prod
|
cache-from: type=registry,ref=${{ secrets.REGISTRY_URL }}/${{ secrets.REGISTRY_USERNAME }}/lediscord:prod-frontend
|
||||||
cache-to: type=inline
|
cache-to: type=inline
|
||||||
|
|
||||||
|
- name: Push frontend image (with retry)
|
||||||
|
run: |
|
||||||
|
push_with_retry() {
|
||||||
|
local image=$1
|
||||||
|
for i in 1 2 3 4 5; do
|
||||||
|
echo "📤 Push attempt $i for $image..."
|
||||||
|
if docker push "$image"; then
|
||||||
|
echo "✅ Successfully pushed $image"
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
echo "⚠️ Push failed, waiting 10s..."
|
||||||
|
sleep 10
|
||||||
|
done
|
||||||
|
echo "❌ Failed to push $image after 5 attempts"
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
|
||||||
|
push_with_retry "${{ secrets.REGISTRY_URL }}/${{ secrets.REGISTRY_USERNAME }}/lediscord:prod-frontend"
|
||||||
|
push_with_retry "${{ secrets.REGISTRY_URL }}/${{ secrets.REGISTRY_USERNAME }}/lediscord:latest-frontend"
|
||||||
|
|
||||||
|
# ===== DEPLOY =====
|
||||||
|
- name: Deploy to Nomad
|
||||||
|
if: success()
|
||||||
|
run: |
|
||||||
|
echo "🚀 Deployment ready!"
|
||||||
|
echo "Run on your server:"
|
||||||
|
echo " nomad job run -force lediscord.nomad"
|
||||||
Reference in New Issue
Block a user