From 04aff9f84f09cf26b14ebfc0ac0d2f85210a21f3 Mon Sep 17 00:00:00 2001 From: Daniel Dolezal Date: Sat, 18 Oct 2025 17:39:48 +0200 Subject: [PATCH] add build workflow and add versioning and change to the php base image --- .gitea/workflows/prod-docker-images.yml | 55 +++++++++++++++++++++++++ Dockerfile | 25 +++++------ src/index.php | 5 +++ 3 files changed, 70 insertions(+), 15 deletions(-) create mode 100644 .gitea/workflows/prod-docker-images.yml create mode 100644 src/index.php diff --git a/.gitea/workflows/prod-docker-images.yml b/.gitea/workflows/prod-docker-images.yml new file mode 100644 index 0000000..2f3959b --- /dev/null +++ b/.gitea/workflows/prod-docker-images.yml @@ -0,0 +1,55 @@ +name: Build and Push Docker Container +on: + push: + branches: + - main + workflow_dispatch: + +jobs: + build-and-push: + runs-on: ubuntu-latest + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + # --- Extract Version Tag or Commit SHA --- + - name: Determine version tag + id: version + run: | + TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "") + echo "VERSION_TAG=$TAG" >> $GITHUB_ENV + echo "Using version tag: $TAG" + + # --- Login to Gitea Registry --- + - name: Login to Gitea Registry + uses: docker/login-action@v3 + with: + registry: ${{ vars.DOCKER_REGISTRY_URL }} + username: ${{ secrets.DOCKER_REGISTRY_USERNAME }} + password: ${{ secrets.ACTION_ACCESS_TOKEN }} + + # --- Login to Docker Hub --- + - name: Login to Docker Hub + uses: docker/login-action@v3 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + + - name: Convert repository owner to lowercase + run: echo "REPO_OWNER_LC=$(echo '${{ gitea.repository_owner }}' | tr '[:upper:]' '[:lower:]')" >> $GITHUB_ENV + + # --- Build and Push to Both Registries --- + - name: Build and push Docker image + uses: docker/build-push-action@v6 + with: + context: . + push: true + platforms: linux/amd64 + tags: | + ${{ vars.GITEA_REGISTRY_URL }}/${{ env.REPO_OWNER_LC }}/apache-php:latest + ${{ secrets.DOCKERHUB_USERNAME }}/apache-php:latest + ${{ secrets.DOCKERHUB_USERNAME }}/apache-php:${{ env.VERSION_TAG }} diff --git a/Dockerfile b/Dockerfile index 94985f6..1f86c6d 100755 --- a/Dockerfile +++ b/Dockerfile @@ -1,23 +1,18 @@ -FROM ubuntu:latest +FROM php:8.4-apache ENV TZ=Europe/Vienna RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone -RUN apt-get update && apt-get update -y && apt-get install -y software-properties-common && apt-add-repository universe && add-apt-repository ppa:ondrej/php -RUN apt-get update && apt-get install -y apache2 php libapache2-mod-php php-mysql php-common php-mbstring apt-utils tzdata nano && apt-get clean +RUN docker-php-ext-install mysqli pdo pdo_mysql -ENV APACHE_RUN_USER=www-data -ENV APACHE_RUN_GROUP=www-data -ENV APACHE_LOG_DIR=/var/log/apache2 -ENV APACHE_PID_FILE=/var/run/apache2/apache2.pid -ENV APACHE_RUN_DIR=/var/run/apache2 -ENV APACHE_LOCK_DIR=/var/lock/apache2 -ENV APACHE_LOG_DIR=/var/log/apache2 +# Install Composer from the official image +COPY --from=composer:2 /usr/bin/composer /usr/bin/composer -RUN mkdir -p $APACHE_RUN_DIR -RUN mkdir -p $APACHE_LOCK_DIR -RUN mkdir -p $APACHE_LOG_DIR +# Set the working directory inside the container +WORKDIR /var/www/html +COPY ./src /var/www/html/ + +RUN chown -R www-data:www-data /var/www/html EXPOSE 80 - -CMD ["/usr/sbin/apache2", "-D", "FOREGROUND"] +CMD ["apache2-foreground"] diff --git a/src/index.php b/src/index.php new file mode 100644 index 0000000..554a22c --- /dev/null +++ b/src/index.php @@ -0,0 +1,5 @@ +