mirror of
https://github.com/DRYTRIX/TimeTracker.git
synced 2026-05-03 19:00:13 -05:00
102 lines
2.8 KiB
YAML
102 lines
2.8 KiB
YAML
name: Build and Publish TimeTracker Docker Image
|
|
|
|
on:
|
|
push:
|
|
branches: [ main ]
|
|
tags: [ 'v*' ]
|
|
pull_request:
|
|
branches: [ main ]
|
|
release:
|
|
types: [ published ]
|
|
workflow_dispatch:
|
|
|
|
env:
|
|
REGISTRY: ghcr.io
|
|
IMAGE_NAME: drytrix/timetracker
|
|
|
|
jobs:
|
|
build:
|
|
runs-on: ubuntu-latest
|
|
permissions:
|
|
contents: read
|
|
packages: write
|
|
|
|
strategy:
|
|
matrix:
|
|
include:
|
|
- name: amd64
|
|
platform: linux/amd64
|
|
|
|
steps:
|
|
- name: Checkout repository
|
|
uses: actions/checkout@v4
|
|
|
|
- name: Set up Docker Buildx
|
|
uses: docker/setup-buildx-action@v3
|
|
|
|
- name: Log in to Container Registry
|
|
if: github.event_name != 'pull_request'
|
|
uses: docker/login-action@v3
|
|
with:
|
|
registry: ${{ env.REGISTRY }}
|
|
username: ${{ github.actor }}
|
|
password: ${{ secrets.GITHUB_TOKEN }}
|
|
|
|
- name: Create simple Dockerfile
|
|
run: |
|
|
cat > Dockerfile.simple << 'EOF'
|
|
FROM python:3.11-slim
|
|
WORKDIR /app
|
|
COPY requirements.txt .
|
|
RUN pip install --no-cache-dir -r requirements.txt
|
|
COPY . .
|
|
EXPOSE 8080
|
|
CMD ["python", "app.py"]
|
|
EOF
|
|
|
|
echo "--- Created Dockerfile.simple ---"
|
|
cat Dockerfile.simple
|
|
|
|
echo "--- Checking available files ---"
|
|
pwd
|
|
ls -la
|
|
echo "--- Checking if requirements.txt exists ---"
|
|
if [ -f requirements.txt ]; then
|
|
echo "requirements.txt found:"
|
|
cat requirements.txt
|
|
else
|
|
echo "requirements.txt NOT found!"
|
|
echo "Available .txt files:"
|
|
find . -name "*.txt" -type f
|
|
fi
|
|
|
|
- name: Build and push Docker image
|
|
run: |
|
|
IMAGE_ID=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
|
|
|
|
# Strip "refs/tags/" prefix if it's a tag event
|
|
VERSION=${GITHUB_REF#refs/tags/}
|
|
|
|
# Fallback: if it's not a tag, use branch name
|
|
if [ -z "$VERSION" ]; then
|
|
VERSION=${GITHUB_REF#refs/heads/}
|
|
fi
|
|
|
|
echo "Image ID: $IMAGE_ID"
|
|
echo "Version: $VERSION"
|
|
|
|
# Build the Docker image
|
|
docker build -f Dockerfile.simple -t $IMAGE_ID:$VERSION .
|
|
|
|
# Always push versioned tag on releases/tags
|
|
if [ "${{ github.event_name }}" != "pull_request" ]; then
|
|
echo ${{ secrets.GITHUB_TOKEN }} | docker login ${{ env.REGISTRY }} -u ${{ github.actor }} --password-stdin
|
|
docker push $IMAGE_ID:$VERSION
|
|
|
|
# If this is a release, also push as latest
|
|
if [ "${{ github.event_name }}" == "release" ]; then
|
|
docker tag $IMAGE_ID:$VERSION $IMAGE_ID:latest
|
|
docker push $IMAGE_ID:latest
|
|
fi
|
|
fi
|