Add CI to auto-build images on changes; Fixes #1 #2
73
.gitea/workflows/docker-build.yml
Normal file
73
.gitea/workflows/docker-build.yml
Normal file
@ -0,0 +1,73 @@
|
||||
name: Build and Push Docker Images
|
||||
|
||||
on:
|
||||
push:
|
||||
paths:
|
||||
- '*/Dockerfile'
|
||||
|
||||
jobs:
|
||||
build-and-push:
|
||||
runs-on: ubuntu-latest
|
||||
container: git.hofer.link/philipp/ci-images:rust-latest
|
||||
steps:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v3
|
||||
|
||||
# Install Docker for Debian
|
||||
- name: Install Docker
|
||||
run: |
|
||||
if ! command -v docker &> /dev/null; then
|
||||
echo "Installing Docker for Debian..."
|
||||
apt-get update
|
||||
apt-get install -y apt-transport-https ca-certificates curl gnupg lsb-release
|
||||
|
||||
# Add Docker's official GPG key
|
||||
install -m 0755 -d /etc/apt/keyrings
|
||||
curl -fsSL https://download.docker.com/linux/debian/gpg | gpg --dearmor -o /etc/apt/keyrings/docker.gpg
|
||||
chmod a+r /etc/apt/keyrings/docker.gpg
|
||||
|
||||
# Add the repository to sources list
|
||||
echo \
|
||||
"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/debian \
|
||||
$(lsb_release -cs) stable" | \
|
||||
tee /etc/apt/sources.list.d/docker.list > /dev/null
|
||||
|
||||
apt-get update
|
||||
apt-get install -y docker-ce docker-ce-cli containerd.io
|
||||
else
|
||||
echo "Docker is already installed"
|
||||
fi
|
||||
|
||||
# Determine which image to build
|
||||
- name: Set image details
|
||||
id: image_details
|
||||
run: |
|
||||
# Extract the directory of the changed Dockerfile
|
||||
CHANGED_FILE="${{ github.event.commits[0].modified[0] }}"
|
||||
if [[ $CHANGED_FILE == */Dockerfile ]]; then
|
||||
IMAGE_PATH=$(dirname "$CHANGED_FILE")
|
||||
else
|
||||
IMAGE_PATH="rust-latest" # Default
|
||||
fi
|
||||
|
||||
# Set outputs
|
||||
echo "image_path=$IMAGE_PATH" >> $GITHUB_OUTPUT
|
||||
echo "image_name=$(basename $IMAGE_PATH)" >> $GITHUB_OUTPUT
|
||||
|
||||
echo "Building image from directory: $IMAGE_PATH"
|
||||
echo "Image name: $(basename $IMAGE_PATH)"
|
||||
|
||||
- name: Login to Gitea Docker Registry
|
||||
uses: docker/login-action@v2
|
||||
with:
|
||||
registry: git.hofer.link
|
||||
username: ${{ secrets.DOCKER_USERNAME }}
|
||||
password: ${{ secrets.DOCKER_PASSWORD }}
|
||||
|
||||
- name: Build and Push Docker image
|
||||
uses: docker/build-push-action@v4
|
||||
with:
|
||||
context: ./${{ steps.image_details.outputs.image_path }}
|
||||
push: true
|
||||
tags: git.hofer.link/philipp/ci-images:${{ steps.image_details.outputs.image_name }}
|
||||
|
@ -5,7 +5,7 @@
|
||||
# 2. Tag the image: `docker tag <id> git.hofer.link/philipp/ci-images:rust-latest`
|
||||
# 3. Push the image: `docker push git.hofer.link/philipp/ci-images:rust-latest`
|
||||
|
||||
FROM rust:1.86
|
||||
FROM rust:1.87
|
||||
|
||||
RUN apt-get update && apt-get install -y sqlite3
|
||||
|
||||
|
Reference in New Issue
Block a user