switch base container from ubuntu to php-alpine (#9)
Some checks failed
ci/woodpecker/manual/build_release/1 Pipeline failed
ci/woodpecker/manual/build_release/2 Pipeline failed
ci/woodpecker/manual/build_release/3 Pipeline failed
ci/woodpecker/manual/build_release/4 Pipeline failed

Co-authored-by: Ruben Momoa <ruben.lobbes@lobbes.nl>
Reviewed-on: #9
This commit was merged in pull request #9.
This commit is contained in:
2024-08-23 15:54:47 +02:00
parent 6f648c4ebd
commit cbd06482f4
7 changed files with 131 additions and 126 deletions

View File

@@ -1,19 +0,0 @@
# the laravel version to install (empty for latest)
LARAVEL_VERSION=
# weather to run "npm dev run" at boot
AUTO_START_NPM_DEV=true
# external ports
FORWARD_LARAVEL_PORT=80
FORWARD_VITE_PORT=5173
FORWARD_DB_PORT=3306
FORWARD_REDIS_PORT=6379
FORWARD_MAILPIT_PORT=1025
FORWARD_MAILPIT_DASHBOARD_PORT=8025
# DB settings (this will overwrite the defaults in the laravel project)
DB_PORT=3306
DB_DATABASE=laravel
DB_USERNAME=laravel
DB_PASSWORD=password

View File

@@ -1,46 +0,0 @@
when:
branch: master
steps:
release_build_and_publish:
image: woodpeckerci/plugin-docker-buildx
settings:
username: vistanarvas
password:
from_secret: DOCKERHUB_TOKEN
context: ./build
repo: vistanarvas/${CI_REPO_NAME}
auto_tag: true
when:
event: release
cron_build_and_publish:
image: woodpeckerci/plugin-docker-buildx
settings:
username: vistanarvas
password:
from_secret: DOCKERHUB_TOKEN
context: ./build
repo: vistanarvas/${CI_REPO_NAME}
tag: nightly
when:
path:
include: [ '.woodpecker/build.yml', 'build/*', 'Dockerfile' ]
cron: nightly
event: [ cron ]
dev_build_and_publish:
image: woodpeckerci/plugin-docker-buildx
settings:
username: vistanarvas
password:
from_secret: DOCKERHUB_TOKEN
context: ./build
repo: vistanarvas/${CI_REPO_NAME}
tag: ${CI_COMMIT_BRANCH}
when:
branch:
exclude: [ main, master ]
path:
include: [ '.woodpecker/build.yml', 'build/*', 'Dockerfile' ]
event: [ push, manual ]

23
.woodpecker/build_dev.yml Normal file
View File

@@ -0,0 +1,23 @@
matrix:
PHP_VERSION:
- 8
when:
branch:
exclude: [ main, master ]
path:
include: [ '.woodpecker/build_dev.yml', 'build/*', 'Dockerfile' ]
event: [ push, manual ]
steps:
dev_alpine_build_and_publish:
image: woodpeckerci/plugin-docker-buildx
settings:
username: vistanarvas
password:
from_secret: DOCKERHUB_TOKEN
context: ./build
repo: vistanarvas/${CI_REPO_NAME}
tag: test-${CI_COMMIT_BRANCH}-php-${PHP_VERSION}
build_args:
- BASE_VERSION=${PHP_VERSION}

View File

@@ -0,0 +1,40 @@
matrix:
PHP_VERSION:
- 8
- 8.3
- 8.2
- 8.1
when:
branch:
include: [ master ]
cron: nightly
event: [ cron, release, manual ]
steps:
cron_pre_check:
image: docker
commands:
- docker pull php:${PHP_VERSION}-fpm-alpine
- docker pull vistanarvas/simple-laravel:${PHP_VERSION}-fpm-alpine
- BASE_IMG=$(docker inspect php:${PHP_VERSION}-fpm-alpine --format='{{.Created}}' | cut -d '.' -f 1)
- PREV_IMG=$(docker inspect vistanarvas/simple-laravel:php-${PHP_VERSION} --format='{{.Created}}' | cut -d '.' -f 1)
- BASE_DATE=$(date -D "%Y-%m-%dT%H:%M:%S" -d "$BASE_IMG" +%s)
- PREV_DATE=$(date -D "%Y-%m-%dT%H:%M:%S" -d "$PREV_IMG" +%s)
- if [ "$PREV_DATE" -gt "$BASE_DATE" ]; then echo "no rebuild needed"; exit 1; fi
volumes:
- /var/run/docker.sock:/var/run/docker.sock
when:
cron: nightly
event: [ cron ]
release_alpine_build_and_publish:
image: woodpeckerci/plugin-docker-buildx
settings:
username: vistanarvas
password:
from_secret: DOCKERHUB_TOKEN
context: ./build
repo: vistanarvas/${CI_REPO_NAME}
auto_tag: true
auto_tag_suffix: -php-${PHP_VERSION}

View File

@@ -1,48 +1,37 @@
FROM ubuntu:latest ARG BASE_VERSION
ARG USERNAME=laravel FROM php:${BASE_VERSION}-fpm-alpine
ARG USER_UID=1080
# node version number like "12.22.1" or empty for the latest version # port to for the webserver
ARG NODE_VERSION='' ENV WEBSERVER_PORT=8080
# composer version number like "2.1" or empty for the latest version
ARG COMPOSER_VERSION=''
# disables asking for input
ARG DEBIAN_FRONTEND="noninteractive"
ENV NVM_DIR="/home/$USERNAME/.nvm"
COPY start-container.sh /usr/local/bin/start-container COPY start-container.sh /usr/local/bin/start-container
RUN apt-get -y update RUN apk add --no-cache \
RUN apt-get install -y curl git 7zip php php-xml php-curl php-xml php-mbstring php-mysql php-gd curl-dev \
RUN apt-get clean libxml2-dev \
RUN useradd --create-home --uid=${USER_UID} ${USERNAME} oniguruma-dev \
RUN chmod +x /usr/local/bin/start-container libpng-dev \
RUN echo "install composer" icu-dev \
RUN curl -o composer-setup.php https://getcomposer.org/installer php-ctype \
RUN curl -o composer-setup.sig https://composer.github.io/installer.sig php-curl \
RUN echo " composer-setup.php" >> composer-setup.sig php-dom \
RUN sha384sum -c composer-setup.sig php-fileinfo \
RUN if [ -n "$COMPOSER_VERSION" ]; then COMPOSER_VERSION="--${COMPOSER_VERSION}"; fi php-mbstring \
RUN php composer-setup.php --install-dir=/usr/local/bin --filename=composer $COMPOSER_VERSION php-session \
RUN rm composer-setup.php composer-setup.sig /var/www/html/* php-xml \
RUN chown $USERNAME:$USERNAME /var/www/html php-intl \
php-bcmath \
php-exif \
php-xmlwriter \
php-tokenizer \
composer \
npm \
&& docker-php-ext-install filter pdo_mysql \
&& chmod +x /usr/local/bin/start-container
EXPOSE 8080 EXPOSE ${WEBSERVER_PORT}
WORKDIR /var/www/html WORKDIR /var/www/html
USER $USERNAME
RUN echo "install nvm and node" \
&& curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.3/install.sh | bash \
&& if [ -z "$NODE_VERSION" ]; then NODE_VERSION="node"; fi \
&& echo "source $NVM_DIR/nvm.sh" >> /home/$USERNAME/.bashrc \
&& [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" \
&& nvm install $NODE_VERSION \
&& nvm alias default $NODE_VERSION
ENTRYPOINT ["start-container"] ENTRYPOINT ["start-container"]

View File

@@ -1,15 +1,28 @@
#!/usr/bin/env bash #!/usr/bin/env ash
# exit when any command fails # exit when any command fails
set -e set -e
# init nvm # install extra packages and extensions on first boot
\. $NVM_DIR/nvm.sh if [[ ! -f /etc/first_boot ]]; then
if [[ -n "${EXTRA_APK_PACKAGES// /}" ]]; then
# shellcheck disable=SC2086
apk add --no-cache $EXTRA_APK_PACKAGES
fi
if [[ -n "${EXTRA_PHP_EXTENSIONS// /}" ]]; then
# shellcheck disable=SC2086
docker-php-ext-install $EXTRA_PHP_EXTENSIONS
fi
touch /etc/first_boot
fi
if [[ "$BOOT_COMPOSER_INSTALL" = true ]]; then
if [[ "$INSTALL_BEFORE_START" = true ]]; then echo "composer install"
echo "composer and npm install"
composer install composer install
fi
if [[ "$BOOT_NPM_INSTALL" = true ]]; then
echo "npm install"
npm install npm install
fi fi
@@ -18,10 +31,10 @@ if [ ! -f /var/www/html/artisan ]; then
exit exit
fi fi
if [[ "$AUTO_START_NPM_DEV" = true ]]; then if [[ "$BOOT_NPM_DEV" = true ]]; then
echo "Staring npm dev" echo "Staring npm dev"
npm run dev --prefix /var/www/html & npm run dev --prefix /var/www/html &
fi fi
echo "Staring Laravel" echo "Staring Laravel"
php /var/www/html/artisan serve php /var/www/html/artisan serve --host=0.0.0.0 --port="$WEBSERVER_PORT"

View File

@@ -1,20 +1,25 @@
version: '3' version: '3'
services: services:
app: app:
build: image: vistanarvas/simple-laravel
context: build
dockerfile: Dockerfile
image: laravel
ports: ports:
- '${FORWARD_LARAVEL_PORT:-80}:8080' - '8080:80'
- '${FORWARD_VITE_PORT:-5173}:5173' - '5173:5173'
environment: environment:
LARAVEL_VERSION: '${LARAVEL_VERSION}' WEBSERVER_PORT: 80
AUTO_START_NPM_DEV: '${AUTO_START_NPM_DEV:-false}'
DB_HOST: mysql
DB_CONNECTION: mysql DB_CONNECTION: mysql
env_file: DB_HOST: mysql
.env DB_PORT: 3306
DB_DATABASE: laravel
DB_USERNAME: laravel
DB_PASSWORD: password
BOOT_NPM_DEV: true # also starts `npm dev`
BOOT_NPM_INSTALL: true # runs `npm install` on boot
BOOT_COMPOSER_INSTALL: true # runs `composer install` on boot
# Extra packages and php extensions to install on first boot
# EXTRA_APK_PACKAGES: # example: libpng-dev icu-dev
# EXTRA_PHP_EXTENSIONS: # example: exif intl bcmath gd pdo_mysql
depends_on: depends_on:
- mysql - mysql
- redis - redis
@@ -23,7 +28,7 @@ services:
mysql: mysql:
image: 'mysql/mysql-server:8.0' image: 'mysql/mysql-server:8.0'
ports: ports:
- '${FORWARD_DB_PORT:-3306}:3306' - '3306:3306'
environment: environment:
MYSQL_ROOT_PASSWORD: '${DB_PASSWORD}' MYSQL_ROOT_PASSWORD: '${DB_PASSWORD}'
MYSQL_ROOT_HOST: '%' MYSQL_ROOT_HOST: '%'
@@ -37,15 +42,15 @@ services:
redis: redis:
image: 'redis:alpine' image: 'redis:alpine'
ports: ports:
- '${FORWARD_REDIS_PORT:-6379}:6379' - '6379:6379'
volumes: volumes:
- 'redis:/data' - 'redis:/data'
mailpit: mailpit:
image: 'axllent/mailpit:latest' image: 'axllent/mailpit:latest'
ports: ports:
- '${FORWARD_MAILPIT_PORT:-1025}:1025' - '1025:1025'
- '${FORWARD_MAILPIT_DASHBOARD_PORT:-8025}:8025' - '8025:8025'
volumes: volumes:
mysql: mysql: