enabled tag based deployment
All checks were successful
continuous-integration/drone/tag Build is passing
All checks were successful
continuous-integration/drone/tag Build is passing
This commit is contained in:
73
.drone.yml
73
.drone.yml
@@ -16,6 +16,48 @@ volumes:
|
|||||||
path: /var/run/docker.sock
|
path: /var/run/docker.sock
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
|
# -----------------------------------------------------
|
||||||
|
# 1. Fetch latest Git tag
|
||||||
|
# -----------------------------------------------------
|
||||||
|
- name: fetch-tags
|
||||||
|
image: docker:24
|
||||||
|
volumes:
|
||||||
|
- name: dockersock
|
||||||
|
path: /var/run/docker.sock
|
||||||
|
commands:
|
||||||
|
- apk add --no-cache git
|
||||||
|
- git fetch --tags
|
||||||
|
- |
|
||||||
|
LATEST_TAG=$(git describe --tags --abbrev=0 2>/dev/null | tr -d '\n')
|
||||||
|
echo "Latest Git tag: $LATEST_TAG"
|
||||||
|
echo "$LATEST_TAG" > /drone/src/LATEST_TAG.txt
|
||||||
|
if [ -z "$LATEST_TAG" ]; then
|
||||||
|
echo "❌ No git tags found. Cannot continue."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# -----------------------------------------------------
|
||||||
|
# 2. Check if remote image already exists
|
||||||
|
# -----------------------------------------------------
|
||||||
|
- name: check-remote-image
|
||||||
|
image: docker:24
|
||||||
|
volumes:
|
||||||
|
- name: dockersock
|
||||||
|
path: /var/run/docker.sock
|
||||||
|
environment:
|
||||||
|
REGISTRY_HOST:
|
||||||
|
from_secret: REGISTRY_HOST
|
||||||
|
commands:
|
||||||
|
- IMAGE_TAG=$(cat /drone/src/LATEST_TAG.txt | tr -d '\n')
|
||||||
|
- echo "Checking if $REGISTRY_HOST/lila-games/nakama-server:$IMAGE_TAG exists..."
|
||||||
|
- |
|
||||||
|
if docker pull $REGISTRY_HOST/lila-games/nakama-server:$IMAGE_TAG > /dev/null 2>&1; then
|
||||||
|
echo "✅ Image already exists: $REGISTRY_HOST/lila-games/nakama-server:$IMAGE_TAG"
|
||||||
|
exit 78
|
||||||
|
else
|
||||||
|
echo "⚙️ Image does not exist. Will build."
|
||||||
|
fi
|
||||||
|
|
||||||
# -----------------------------------------------------
|
# -----------------------------------------------------
|
||||||
# 3. Build Nakama Docker image
|
# 3. Build Nakama Docker image
|
||||||
# -----------------------------------------------------
|
# -----------------------------------------------------
|
||||||
@@ -26,13 +68,40 @@ steps:
|
|||||||
path: /var/run/docker.sock
|
path: /var/run/docker.sock
|
||||||
commands:
|
commands:
|
||||||
- IMAGE_TAG=$(cat /drone/src/LATEST_TAG.txt | tr -d '\n')
|
- IMAGE_TAG=$(cat /drone/src/LATEST_TAG.txt | tr -d '\n')
|
||||||
- echo "🔨 Building Nakama image lila-games/nakama-server:latest"
|
- echo "🔨 Building Nakama image lila-games/nakama-server:$IMAGE_TAG"
|
||||||
- |
|
- |
|
||||||
docker build \
|
docker build \
|
||||||
--network=host \
|
--network=host \
|
||||||
|
-t lila-games/nakama-server:$IMAGE_TAG \
|
||||||
-t lila-games/nakama-server:latest \
|
-t lila-games/nakama-server:latest \
|
||||||
/drone/src
|
/drone/src
|
||||||
|
|
||||||
|
# -----------------------------------------------------
|
||||||
|
# 4. Push Nakama image to registry
|
||||||
|
# -----------------------------------------------------
|
||||||
|
- name: push-image
|
||||||
|
image: docker:24
|
||||||
|
volumes:
|
||||||
|
- name: dockersock
|
||||||
|
path: /var/run/docker.sock
|
||||||
|
environment:
|
||||||
|
REGISTRY_HOST:
|
||||||
|
from_secret: REGISTRY_HOST
|
||||||
|
REGISTRY_USER:
|
||||||
|
from_secret: REGISTRY_USER
|
||||||
|
REGISTRY_PASS:
|
||||||
|
from_secret: REGISTRY_PASS
|
||||||
|
commands:
|
||||||
|
- IMAGE_TAG=$(cat /drone/src/LATEST_TAG.txt | tr -d '\n')
|
||||||
|
- echo "🔑 Logging into registry..."
|
||||||
|
- echo "$REGISTRY_PASS" | docker login $REGISTRY_HOST -u "$REGISTRY_USER" --password-stdin
|
||||||
|
- echo "🏷️ Tagging images..."
|
||||||
|
- docker tag lila-games/nakama-server:$IMAGE_TAG $REGISTRY_HOST/lila-games/nakama-server:$IMAGE_TAG
|
||||||
|
- docker tag lila-games/nakama-server:$IMAGE_TAG $REGISTRY_HOST/lila-games/nakama-server:latest
|
||||||
|
- echo "📤 Pushing images..."
|
||||||
|
- docker push $REGISTRY_HOST/lila-games/nakama-server:$IMAGE_TAG
|
||||||
|
- docker push $REGISTRY_HOST/lila-games/nakama-server:latest
|
||||||
|
|
||||||
# -----------------------------------------------------
|
# -----------------------------------------------------
|
||||||
# 5. Stop old Nakama container
|
# 5. Stop old Nakama container
|
||||||
# -----------------------------------------------------
|
# -----------------------------------------------------
|
||||||
@@ -82,4 +151,4 @@ steps:
|
|||||||
# -----------------------------------------------------
|
# -----------------------------------------------------
|
||||||
trigger:
|
trigger:
|
||||||
event:
|
event:
|
||||||
- custom
|
- tag
|
||||||
|
|||||||
Reference in New Issue
Block a user