fix(ci/cd)
This commit is contained in:
@@ -11,91 +11,31 @@ jobs:
|
|||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout code
|
- name: Checkout code
|
||||||
uses: actions/checkout@v3
|
run: |
|
||||||
|
git clone --depth 1 --branch prod https://${{ secrets.REGISTRY_USERNAME }}:${{ secrets.REGISTRY_TOKEN }}@git.local.evan.casa/evan/lediscord.git .
|
||||||
|
|
||||||
- name: Force IPv4 for DNS
|
- name: Force IPv4 for DNS
|
||||||
run: |
|
run: |
|
||||||
echo 'precedence ::ffff:0:0/96 100' | sudo tee -a /etc/gai.conf
|
echo 'precedence ::ffff:0:0/96 100' | sudo tee -a /etc/gai.conf
|
||||||
|
|
||||||
- name: Set up Docker Buildx
|
- name: Login to Registry
|
||||||
uses: docker/setup-buildx-action@v2
|
|
||||||
|
|
||||||
- name: Login to Gitea Container Registry (with retry)
|
|
||||||
run: |
|
run: |
|
||||||
|
echo "${{ secrets.REGISTRY_TOKEN }}" | docker login ${{ secrets.REGISTRY_URL }} -u ${{ secrets.REGISTRY_USERNAME }} --password-stdin
|
||||||
|
|
||||||
|
- name: Build and push backend
|
||||||
|
run: |
|
||||||
|
docker build -t ${{ secrets.REGISTRY_URL }}/${{ secrets.REGISTRY_USERNAME }}/lediscord:prod-backend ./backend
|
||||||
for i in 1 2 3 4 5; do
|
for i in 1 2 3 4 5; do
|
||||||
echo "🔐 Login attempt $i..."
|
docker push ${{ secrets.REGISTRY_URL }}/${{ secrets.REGISTRY_USERNAME }}/lediscord:prod-backend && break || sleep 10
|
||||||
echo "${{ secrets.REGISTRY_TOKEN }}" | docker login ${{ secrets.REGISTRY_URL }} -u ${{ secrets.REGISTRY_USERNAME }} --password-stdin && break || sleep 5
|
|
||||||
done
|
done
|
||||||
|
|
||||||
- name: Build backend image
|
- name: Build and push frontend
|
||||||
uses: docker/build-push-action@v4
|
|
||||||
with:
|
|
||||||
context: ./backend
|
|
||||||
file: ./backend/Dockerfile
|
|
||||||
push: false
|
|
||||||
load: true
|
|
||||||
tags: |
|
|
||||||
${{ secrets.REGISTRY_URL }}/${{ secrets.REGISTRY_USERNAME }}/lediscord:prod-backend
|
|
||||||
${{ secrets.REGISTRY_URL }}/${{ secrets.REGISTRY_USERNAME }}/lediscord:latest-backend
|
|
||||||
cache-from: type=registry,ref=${{ secrets.REGISTRY_URL }}/${{ secrets.REGISTRY_USERNAME }}/lediscord:prod-backend
|
|
||||||
cache-to: type=inline
|
|
||||||
|
|
||||||
- name: Push backend image (with retry)
|
|
||||||
run: |
|
run: |
|
||||||
push_with_retry() {
|
docker build -t ${{ secrets.REGISTRY_URL }}/${{ secrets.REGISTRY_USERNAME }}/lediscord:prod-frontend ./frontend
|
||||||
local image=$1
|
|
||||||
for i in 1 2 3 4 5; do
|
for i in 1 2 3 4 5; do
|
||||||
echo "📤 Push attempt $i for $image..."
|
docker push ${{ secrets.REGISTRY_URL }}/${{ secrets.REGISTRY_USERNAME }}/lediscord:prod-frontend && break || sleep 10
|
||||||
if docker push "$image"; then
|
|
||||||
echo "✅ Successfully pushed $image"
|
|
||||||
return 0
|
|
||||||
fi
|
|
||||||
echo "⚠️ Push failed, waiting 10s..."
|
|
||||||
sleep 10
|
|
||||||
done
|
done
|
||||||
echo "❌ Failed to push $image after 5 attempts"
|
|
||||||
return 1
|
|
||||||
}
|
|
||||||
|
|
||||||
push_with_retry "${{ secrets.REGISTRY_URL }}/${{ secrets.REGISTRY_USERNAME }}/lediscord:prod-backend"
|
- name: Done
|
||||||
push_with_retry "${{ secrets.REGISTRY_URL }}/${{ secrets.REGISTRY_USERNAME }}/lediscord:latest-backend"
|
|
||||||
|
|
||||||
- name: Build frontend image
|
|
||||||
uses: docker/build-push-action@v4
|
|
||||||
with:
|
|
||||||
context: ./frontend
|
|
||||||
file: ./frontend/Dockerfile
|
|
||||||
push: false
|
|
||||||
load: true
|
|
||||||
tags: |
|
|
||||||
${{ secrets.REGISTRY_URL }}/${{ secrets.REGISTRY_USERNAME }}/lediscord:prod-frontend
|
|
||||||
${{ secrets.REGISTRY_URL }}/${{ secrets.REGISTRY_USERNAME }}/lediscord:latest-frontend
|
|
||||||
cache-from: type=registry,ref=${{ secrets.REGISTRY_URL }}/${{ secrets.REGISTRY_USERNAME }}/lediscord:prod-frontend
|
|
||||||
cache-to: type=inline
|
|
||||||
|
|
||||||
- name: Push frontend image (with retry)
|
|
||||||
run: |
|
run: |
|
||||||
push_with_retry() {
|
echo "🚀 Images pushed! Run: nomad job run -force lediscord.nomad"
|
||||||
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"
|
|
||||||
|
|
||||||
- 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