Our upstream is dropping TCP SYNs to github.com/ghcr.io often enough that single docker login/push attempts time out. Wrap in a 5-attempt retry loop with 15s backoff. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
91 lines
2.6 KiB
YAML
91 lines
2.6 KiB
YAML
name: Docker Images
|
|
|
|
on:
|
|
push:
|
|
branches: [main]
|
|
paths:
|
|
- 'src/food-market.api/**'
|
|
- 'src/food-market.web/**'
|
|
- 'src/food-market.application/**'
|
|
- 'src/food-market.domain/**'
|
|
- 'src/food-market.infrastructure/**'
|
|
- 'src/food-market.shared/**'
|
|
- 'deploy/**'
|
|
- '.github/workflows/docker.yml'
|
|
workflow_dispatch:
|
|
|
|
permissions:
|
|
contents: read
|
|
packages: write
|
|
|
|
jobs:
|
|
api:
|
|
name: API image
|
|
runs-on: [self-hosted, linux]
|
|
steps:
|
|
- uses: actions/checkout@v4
|
|
|
|
- name: Login to ghcr
|
|
env:
|
|
TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
ACTOR: ${{ github.actor }}
|
|
run: |
|
|
for i in 1 2 3 4 5; do
|
|
if echo "$TOKEN" | docker login ghcr.io -u "$ACTOR" --password-stdin; then
|
|
exit 0
|
|
fi
|
|
echo "login attempt $i failed, retrying in 15s"
|
|
sleep 15
|
|
done
|
|
exit 1
|
|
|
|
- name: Build + push api
|
|
env:
|
|
OWNER: ${{ github.repository_owner }}
|
|
SHA: ${{ github.sha }}
|
|
run: |
|
|
docker build -f deploy/Dockerfile.api -t ghcr.io/$OWNER/food-market-api:$SHA -t ghcr.io/$OWNER/food-market-api:latest .
|
|
for tag in $SHA latest; do
|
|
for i in 1 2 3 4 5; do
|
|
if docker push ghcr.io/$OWNER/food-market-api:$tag; then break; fi
|
|
echo "push $tag attempt $i failed, retrying in 15s"
|
|
sleep 15
|
|
[ $i -eq 5 ] && exit 1
|
|
done
|
|
done
|
|
|
|
web:
|
|
name: Web image
|
|
runs-on: [self-hosted, linux]
|
|
steps:
|
|
- uses: actions/checkout@v4
|
|
|
|
- name: Login to ghcr
|
|
env:
|
|
TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
ACTOR: ${{ github.actor }}
|
|
run: |
|
|
for i in 1 2 3 4 5; do
|
|
if echo "$TOKEN" | docker login ghcr.io -u "$ACTOR" --password-stdin; then
|
|
exit 0
|
|
fi
|
|
echo "login attempt $i failed, retrying in 15s"
|
|
sleep 15
|
|
done
|
|
exit 1
|
|
|
|
- name: Build + push web
|
|
env:
|
|
OWNER: ${{ github.repository_owner }}
|
|
SHA: ${{ github.sha }}
|
|
run: |
|
|
docker build -f deploy/Dockerfile.web -t ghcr.io/$OWNER/food-market-web:$SHA -t ghcr.io/$OWNER/food-market-web:latest .
|
|
for tag in $SHA latest; do
|
|
for i in 1 2 3 4 5; do
|
|
if docker push ghcr.io/$OWNER/food-market-web:$tag; then break; fi
|
|
echo "push $tag attempt $i failed, retrying in 15s"
|
|
sleep 15
|
|
[ $i -eq 5 ] && exit 1
|
|
done
|
|
done
|