mirror of
https://github.com/Snigdha-OS/snigdhaos-docker.git
synced 2025-12-06 12:03:52 +01:00
81 lines
3.1 KiB
YAML
81 lines
3.1 KiB
YAML
name: Snigdha OS Docker Image
|
|
|
|
on:
|
|
workflow_dispatch:
|
|
schedule:
|
|
- cron: '30 05 * * *' # Cron schedule for automatic builds (adjust as needed)
|
|
push:
|
|
branches:
|
|
- master
|
|
|
|
jobs:
|
|
docker:
|
|
runs-on: ubuntu-latest
|
|
|
|
steps:
|
|
# Checkout repository
|
|
- name: Checkout repository
|
|
uses: actions/checkout@v4
|
|
|
|
# Set up QEMU for multi-architecture builds
|
|
- name: Set up QEMU
|
|
uses: docker/setup-qemu-action@v3
|
|
|
|
# Set up Docker Buildx for advanced builds (multi-arch, caching)
|
|
- name: Set up Docker Buildx
|
|
uses: docker/setup-buildx-action@v3
|
|
|
|
# Login to Docker Hub using secrets for security
|
|
- name: Login to Docker Hub
|
|
uses: docker/login-action@v3
|
|
with:
|
|
username: ${{ secrets.DOCKERHUB_USERNAME }}
|
|
password: ${{ secrets.DOCKERHUB_TOKEN }}
|
|
|
|
# Cache Docker layers to speed up build time
|
|
- name: Cache Docker layers
|
|
uses: actions/cache@v3
|
|
with:
|
|
path: /tmp/.buildx-cache
|
|
key: ${{ runner.os }}-buildx-${{ github.sha }}
|
|
restore-keys: |
|
|
${{ runner.os }}-buildx-
|
|
|
|
# Build and push Docker image (only for amd64 platform now)
|
|
- name: Build Docker image
|
|
id: build
|
|
uses: docker/build-push-action@v4
|
|
with:
|
|
context: ./snigdhaos # Ensure the Dockerfile is inside the snigdhaos directory
|
|
push: true
|
|
tags: ${{ secrets.DOCKERHUB_USERNAME }}/snigdhaos:latest # Add your Docker Hub username here
|
|
platforms: linux/amd64 # Only build for amd64
|
|
cache-to: type=inline # Use inline caching
|
|
cache-from: type=registry,ref=${{ secrets.DOCKERHUB_USERNAME }}/snigdhaos:latest # Use cached layers from Docker Hub
|
|
|
|
# Add a check to confirm that the image was built and tagged correctly
|
|
- name: Verify Docker image exists
|
|
run: |
|
|
echo "Checking if snigdhaos:latest image exists"
|
|
docker images -q ${{ secrets.DOCKERHUB_USERNAME }}/snigdhaos:latest || echo "Image not found"
|
|
|
|
# Check if build succeeded and tag Docker image with version based on the latest Git tag
|
|
- name: Tag Docker image with version
|
|
if: success() # Only proceed if the build was successful
|
|
run: |
|
|
VERSION=$(git tag -l | tail -n 1 || echo "latest") # Get the latest tag or fallback to "latest"
|
|
|
|
# Ensure VERSION is not empty, default to "latest" if it's empty
|
|
if [ -z "$VERSION" ]; then
|
|
VERSION="latest"
|
|
fi
|
|
|
|
# Verify if the image exists before tagging
|
|
if docker image inspect ${{ secrets.DOCKERHUB_USERNAME }}/snigdhaos:latest > /dev/null 2>&1; then
|
|
echo "Image exists, tagging with version: $VERSION"
|
|
docker tag ${{ secrets.DOCKERHUB_USERNAME }}/snigdhaos:latest ${{ secrets.DOCKERHUB_USERNAME }}/snigdhaos:${VERSION}
|
|
docker push ${{ secrets.DOCKERHUB_USERNAME }}/snigdhaos:${VERSION}
|
|
else
|
|
echo "Docker image not found, skipping tag and push."
|
|
exit 1 # Fail the step if the image does not exist
|