Add CI pipeline for Docker image builds
Some checks failed
Build and Push Docker Image / build (push) Failing after 5s
Some checks failed
Build and Push Docker Image / build (push) Failing after 5s
This commit is contained in:
parent
e119312a9c
commit
f219effc33
@ -1,5 +1,6 @@
|
||||
.git
|
||||
.gitignore
|
||||
.gitea/
|
||||
.opencode/
|
||||
.qwen/
|
||||
.ruff_cache/
|
||||
|
||||
61
.gitea/workflows/build.yml
Normal file
61
.gitea/workflows/build.yml
Normal file
@ -0,0 +1,61 @@
|
||||
name: Build and Push Docker Image
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [main, staging]
|
||||
tags: ["v*"]
|
||||
|
||||
env:
|
||||
REGISTRY: gitea.tenhal.sa
|
||||
IMAGE_NAME: marwan/hh
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Set up Docker Buildx
|
||||
uses: docker/setup-buildx-action@v3
|
||||
|
||||
- name: Login to Gitea Container Registry
|
||||
uses: docker/login-action@v3
|
||||
with:
|
||||
registry: ${{ env.REGISTRY }}
|
||||
username: ${{ gitea.actor }}
|
||||
password: ${{ secrets.GITHUB_TOKEN }}
|
||||
|
||||
- name: Determine tags
|
||||
id: meta
|
||||
run: |
|
||||
IMAGE="${REGISTRY}/${IMAGE_NAME}"
|
||||
BRANCH="${GITHUB_REF_NAME}"
|
||||
SHA=$(echo "${GITHUB_SHA}" | cut -c1-7)
|
||||
|
||||
TAGS=""
|
||||
|
||||
if [[ "${GITHUB_REF}" == refs/tags/v* ]]; then
|
||||
VERSION="${GITHUB_REF_NAME}"
|
||||
TAGS="${IMAGE}:${VERSION}"
|
||||
echo "Building release: ${VERSION}"
|
||||
elif [[ "${BRANCH}" == "main" ]]; then
|
||||
TAGS="${IMAGE}:latest,${IMAGE}:${SHA}"
|
||||
echo "Building main: latest + ${SHA}"
|
||||
elif [[ "${BRANCH}" == "staging" ]]; then
|
||||
TAGS="${IMAGE}:staging,${IMAGE}:staging-${SHA}"
|
||||
echo "Building staging: staging + staging-${SHA}"
|
||||
fi
|
||||
|
||||
echo "tags=${TAGS}" >> "$GITHUB_OUTPUT"
|
||||
echo "Pushing tags: ${TAGS}"
|
||||
|
||||
- name: Build and push
|
||||
uses: docker/build-push-action@v6
|
||||
with:
|
||||
context: .
|
||||
file: ./Dockerfile
|
||||
push: true
|
||||
tags: ${{ steps.meta.outputs.tags }}
|
||||
cache-from: type=registry,ref=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:buildcache
|
||||
cache-to: type=registry,ref=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:buildcache,mode=max
|
||||
@ -1,47 +1,34 @@
|
||||
#!/bin/bash
|
||||
set -e
|
||||
|
||||
# Manual fallback — CI normally handles this via .gitea/workflows/build.yml
|
||||
# Usage: ./build-and-push.sh [tag]
|
||||
# ./build-and-push.sh staging
|
||||
# ./build-and-push.sh v1.0.0
|
||||
|
||||
REGISTRY="gitea.tenhal.sa/marwan/hh"
|
||||
TAG=${1:-staging}
|
||||
|
||||
echo "========================================"
|
||||
echo " PX360 Build & Push"
|
||||
echo " PX360 Manual Build & Push (fallback)"
|
||||
echo " Tag: $REGISTRY:$TAG"
|
||||
echo " $(date '+%Y-%m-%d %H:%M:%S')"
|
||||
echo "========================================"
|
||||
echo ""
|
||||
echo "NOTE: CI normally handles this. Only use if CI is unavailable."
|
||||
echo ""
|
||||
|
||||
if ! docker login "$REGISTRY" 2>/dev/null; then
|
||||
echo ""
|
||||
echo "Login required. Enter your Gitea credentials:"
|
||||
echo " Username: your Gitea username"
|
||||
echo " Password: your Gitea token (Settings > Applications > Access Tokens)"
|
||||
echo ""
|
||||
docker login "$REGISTRY"
|
||||
fi
|
||||
docker login gitea.tenhal.sa
|
||||
|
||||
echo ""
|
||||
echo "[1/3] Building image..."
|
||||
docker build -t "$REGISTRY:$TAG" .
|
||||
|
||||
SHORT_SHA=$(git rev-parse --short HEAD 2>/dev/null || echo "unknown")
|
||||
if [ "$SHORT_SHA" != "unknown" ]; then
|
||||
docker tag "$REGISTRY:$TAG" "$REGISTRY:$SHORT_SHA"
|
||||
echo " Also tagged: $REGISTRY:$SHORT_SHA"
|
||||
fi
|
||||
|
||||
echo ""
|
||||
echo "[2/3] Pushing to registry..."
|
||||
docker push "$REGISTRY:$TAG"
|
||||
if [ "$SHORT_SHA" != "unknown" ]; then
|
||||
docker push "$REGISTRY:$SHORT_SHA"
|
||||
fi
|
||||
|
||||
echo ""
|
||||
echo "[3/3] Done!"
|
||||
echo "[3/3] Done! Pushed: $REGISTRY:$TAG"
|
||||
echo ""
|
||||
echo "Images pushed:"
|
||||
echo " $REGISTRY:$TAG"
|
||||
[ "$SHORT_SHA" != "unknown" ] && echo " $REGISTRY:$SHORT_SHA"
|
||||
echo ""
|
||||
echo "Deploy to staging: ./deploy.staging.sh $TAG"
|
||||
echo "Deploy to prod: ./deploy.prod.sh $TAG"
|
||||
echo "Deploy: ./deploy.staging.sh $TAG (or ./deploy.prod.sh $TAG)"
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user