switch base container from ubuntu to php-alpine (#9)
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:
19
.env.example
19
.env.example
@@ -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
|
||||
@@ -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
23
.woodpecker/build_dev.yml
Normal 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}
|
||||
40
.woodpecker/build_release.yml
Normal file
40
.woodpecker/build_release.yml
Normal 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}
|
||||
65
Dockerfile
65
Dockerfile
@@ -1,48 +1,37 @@
|
||||
FROM ubuntu:latest
|
||||
ARG BASE_VERSION
|
||||
|
||||
ARG USERNAME=laravel
|
||||
ARG USER_UID=1080
|
||||
FROM php:${BASE_VERSION}-fpm-alpine
|
||||
|
||||
# node version number like "12.22.1" or empty for the latest version
|
||||
ARG NODE_VERSION=''
|
||||
|
||||
# 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"
|
||||
# port to for the webserver
|
||||
ENV WEBSERVER_PORT=8080
|
||||
|
||||
COPY start-container.sh /usr/local/bin/start-container
|
||||
|
||||
RUN apt-get -y update
|
||||
RUN apt-get install -y curl git 7zip php php-xml php-curl php-xml php-mbstring php-mysql php-gd
|
||||
RUN apt-get clean
|
||||
RUN useradd --create-home --uid=${USER_UID} ${USERNAME}
|
||||
RUN chmod +x /usr/local/bin/start-container
|
||||
RUN echo "install composer"
|
||||
RUN curl -o composer-setup.php https://getcomposer.org/installer
|
||||
RUN curl -o composer-setup.sig https://composer.github.io/installer.sig
|
||||
RUN echo " composer-setup.php" >> composer-setup.sig
|
||||
RUN sha384sum -c composer-setup.sig
|
||||
RUN if [ -n "$COMPOSER_VERSION" ]; then COMPOSER_VERSION="--${COMPOSER_VERSION}"; fi
|
||||
RUN php composer-setup.php --install-dir=/usr/local/bin --filename=composer $COMPOSER_VERSION
|
||||
RUN rm composer-setup.php composer-setup.sig /var/www/html/*
|
||||
RUN chown $USERNAME:$USERNAME /var/www/html
|
||||
RUN apk add --no-cache \
|
||||
curl-dev \
|
||||
libxml2-dev \
|
||||
oniguruma-dev \
|
||||
libpng-dev \
|
||||
icu-dev \
|
||||
php-ctype \
|
||||
php-curl \
|
||||
php-dom \
|
||||
php-fileinfo \
|
||||
php-mbstring \
|
||||
php-session \
|
||||
php-xml \
|
||||
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
|
||||
|
||||
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"]
|
||||
@@ -1,15 +1,28 @@
|
||||
#!/usr/bin/env bash
|
||||
#!/usr/bin/env ash
|
||||
|
||||
# exit when any command fails
|
||||
set -e
|
||||
|
||||
# init nvm
|
||||
\. $NVM_DIR/nvm.sh
|
||||
# install extra packages and extensions on first boot
|
||||
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 [[ "$INSTALL_BEFORE_START" = true ]]; then
|
||||
echo "composer and npm install"
|
||||
if [[ "$BOOT_COMPOSER_INSTALL" = true ]]; then
|
||||
echo "composer install"
|
||||
composer install
|
||||
fi
|
||||
|
||||
if [[ "$BOOT_NPM_INSTALL" = true ]]; then
|
||||
echo "npm install"
|
||||
npm install
|
||||
fi
|
||||
|
||||
@@ -18,10 +31,10 @@ if [ ! -f /var/www/html/artisan ]; then
|
||||
exit
|
||||
fi
|
||||
|
||||
if [[ "$AUTO_START_NPM_DEV" = true ]]; then
|
||||
if [[ "$BOOT_NPM_DEV" = true ]]; then
|
||||
echo "Staring npm dev"
|
||||
npm run dev --prefix /var/www/html &
|
||||
fi
|
||||
|
||||
echo "Staring Laravel"
|
||||
php /var/www/html/artisan serve
|
||||
php /var/www/html/artisan serve --host=0.0.0.0 --port="$WEBSERVER_PORT"
|
||||
|
||||
@@ -1,20 +1,25 @@
|
||||
version: '3'
|
||||
services:
|
||||
app:
|
||||
build:
|
||||
context: build
|
||||
dockerfile: Dockerfile
|
||||
image: laravel
|
||||
image: vistanarvas/simple-laravel
|
||||
ports:
|
||||
- '${FORWARD_LARAVEL_PORT:-80}:8080'
|
||||
- '${FORWARD_VITE_PORT:-5173}:5173'
|
||||
- '8080:80'
|
||||
- '5173:5173'
|
||||
environment:
|
||||
LARAVEL_VERSION: '${LARAVEL_VERSION}'
|
||||
AUTO_START_NPM_DEV: '${AUTO_START_NPM_DEV:-false}'
|
||||
DB_HOST: mysql
|
||||
WEBSERVER_PORT: 80
|
||||
DB_CONNECTION: mysql
|
||||
env_file:
|
||||
.env
|
||||
DB_HOST: mysql
|
||||
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:
|
||||
- mysql
|
||||
- redis
|
||||
@@ -23,7 +28,7 @@ services:
|
||||
mysql:
|
||||
image: 'mysql/mysql-server:8.0'
|
||||
ports:
|
||||
- '${FORWARD_DB_PORT:-3306}:3306'
|
||||
- '3306:3306'
|
||||
environment:
|
||||
MYSQL_ROOT_PASSWORD: '${DB_PASSWORD}'
|
||||
MYSQL_ROOT_HOST: '%'
|
||||
@@ -37,15 +42,15 @@ services:
|
||||
redis:
|
||||
image: 'redis:alpine'
|
||||
ports:
|
||||
- '${FORWARD_REDIS_PORT:-6379}:6379'
|
||||
- '6379:6379'
|
||||
volumes:
|
||||
- 'redis:/data'
|
||||
|
||||
mailpit:
|
||||
image: 'axllent/mailpit:latest'
|
||||
ports:
|
||||
- '${FORWARD_MAILPIT_PORT:-1025}:1025'
|
||||
- '${FORWARD_MAILPIT_DASHBOARD_PORT:-8025}:8025'
|
||||
- '1025:1025'
|
||||
- '8025:8025'
|
||||
|
||||
volumes:
|
||||
mysql:
|
||||
|
||||
Reference in New Issue
Block a user