Skip to content

Commit 9b6ddf8

Browse files
authored
feat(deploy): enhance Docker deployment workflow with mirror configuration and improved error handling (#303)
1 parent 4d5a01d commit 9b6ddf8

File tree

1 file changed

+27
-19
lines changed

1 file changed

+27
-19
lines changed

.github/workflows/deploy.yml

Lines changed: 27 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,33 @@ jobs:
2525
script: |
2626
IMAGE="${DOCKER_USERNAME}/docflow:latest"
2727
28+
# Configure Docker mirrors (only if not configured)
29+
if [ ! -f /etc/docker/daemon.json ] || ! grep -q "registry-mirrors" /etc/docker/daemon.json; then
30+
echo "⚙️ Configuring Docker mirrors..."
31+
sudo tee /etc/docker/daemon.json > /dev/null <<'EOF'
32+
{
33+
"registry-mirrors": [
34+
"https://docker.m.daocloud.io",
35+
"https://docker.1panel.live",
36+
"https://hub.rat.dev"
37+
]
38+
}
39+
EOF
40+
sudo systemctl daemon-reload
41+
sudo systemctl restart docker
42+
sleep 5
43+
fi
44+
45+
# Login to Docker Hub
46+
echo "🔐 Logging in to Docker Hub..."
47+
echo "${DOCKER_PASSWORD}" | docker login -u "${DOCKER_USERNAME}" --password-stdin || {
48+
echo "❌ Docker login failed"
49+
exit 1
50+
}
51+
2852
# Get remote image digest
2953
echo "🔍 Checking for updates..."
30-
REMOTE_DIGEST=$(docker manifest inspect $IMAGE 2>/dev/null | grep -m1 '"digest"' | cut -d'"' -f4)
54+
REMOTE_DIGEST=$(docker manifest inspect "$IMAGE" 2>/dev/null | grep -m1 '"digest"' | cut -d'"' -f4)
3155
3256
if [ -z "$REMOTE_DIGEST" ]; then
3357
echo "❌ Failed to fetch remote image info"
@@ -45,24 +69,8 @@ jobs:
4569
4670
echo "🆕 New version available, deploying..."
4771
48-
# Configure Docker mirrors (only if not configured)
49-
if [ ! -f /etc/docker/daemon.json ] || ! grep -q "registry-mirrors" /etc/docker/daemon.json; then
50-
sudo tee /etc/docker/daemon.json > /dev/null <<'EOF'
51-
{
52-
"registry-mirrors": [
53-
"https://docker.m.daocloud.io",
54-
"https://docker.1panel.live",
55-
"https://hub.rat.dev"
56-
]
57-
}
58-
EOF
59-
sudo systemctl daemon-reload
60-
sudo systemctl restart docker
61-
sleep 5
62-
fi
63-
6472
# Pull new image
65-
docker pull $IMAGE || exit 1
73+
docker pull "$IMAGE" || exit 1
6674
6775
# Stop and remove old container
6876
docker stop docflow 2>/dev/null || true
@@ -74,7 +82,7 @@ jobs:
7482
--restart unless-stopped \
7583
-p 3000:3000 \
7684
-e NODE_ENV=production \
77-
$IMAGE)
85+
"$IMAGE")
7886
7987
if [ -z "$CONTAINER_ID" ]; then
8088
echo "❌ Failed to start container"

0 commit comments

Comments
 (0)