Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
robsontenorio committed Apr 18, 2024
1 parent e9b94bf commit 364c0bb
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 64 deletions.
18 changes: 10 additions & 8 deletions .github/workflows/docker-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ on:
push:
branches:
- "master"
- "next"
tags:
- "*"

Expand All @@ -12,40 +13,41 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
uses: actions/checkout@v4

- name: Set up QEMU
uses: docker/setup-qemu-action@v1
uses: docker/setup-qemu-action@v3

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
uses: docker/setup-buildx-action@v3

- name: Login to DockerHub
uses: docker/login-action@v1
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Docker meta
id: meta
uses: docker/metadata-action@v3
uses: docker/metadata-action@v5
with:
images: robsontenorio/laravel
flavor: latest=false
tags: |
type=ref,event=tag
type=raw,enable=${{ github.ref == 'refs/heads/master' }},value=latest
type=raw,enable=${{ github.ref == 'refs/heads/master' }},value=latest
type=raw,enable=${{ github.ref == 'refs/heads/next' }},value=next
- name: Build and push
uses: docker/build-push-action@v2
uses: docker/build-push-action@v5
with:
context: .
platforms: linux/amd64,linux/arm64
push: true
tags: ${{ steps.meta.outputs.tags }}

- name: Docker Hub Description
uses: peter-evans/dockerhub-description@v2
uses: peter-evans/dockerhub-description@v4
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_PASSWORD }}
Expand Down
102 changes: 50 additions & 52 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,74 +11,72 @@ ENV CONTAINER_ROLE=${CONTAINER_ROLE:-APP}
WORKDIR /var/www/app

RUN apt update \
# Add PHP 8.3 repository
&& apt install -y software-properties-common && add-apt-repository ppa:ondrej/php \
# PHP extensions
&& apt install -y \
php8.3-bcmath \
php8.3-cli \
php8.3-curl \
php8.3-fpm \
php8.3-gd \
php8.3-intl \
php8.3-mbstring \
php8.3-mysql \
php8.3-redis \
php8.3-sockets \
php8.3-sqlite3 \
php8.3-pcov \
php8.3-pgsql \
php8.3-opcache \
php8.3-xml \
php8.3-zip \
# Extra
curl \
git \
htop \
nano \
nginx \
supervisor \
unzip \
zsh


# Composer
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/bin --filename=composer

# Node, NPM, Yarn
RUN curl -fsSL https://deb.nodesource.com/setup_lts.x | bash - && apt install -y nodejs && npm -g install yarn --unsafe-perm

# Create user/group with id/uid (1000/100)
# Add PHP 8.3 repository \
&& apt install -y software-properties-common && add-apt-repository ppa:ondrej/php \
# PHP extensions
&& apt install -y \
php8.3-bcmath \
php8.3-cli \
php8.3-curl \
php8.3-fpm \
php8.3-gd \
php8.3-intl \
php8.3-mbstring \
php8.3-mysql \
php8.3-redis \
php8.3-sockets \
php8.3-sqlite3 \
php8.3-pcov \
php8.3-pgsql \
php8.3-opcache \
php8.3-xml \
php8.3-zip \
# Extra
curl \
git \
htop \
nano \
nginx \
sudo \
supervisor \
unzip \
zsh


# Create `appuser` (1000/1000)
RUN groupadd -g 1000 appuser
RUN useradd -u 1000 -m -d /home/appuser -g appuser appuser
RUN useradd -p '' -u 1000 -m -d /home/appuser -g appuser appuser

# Config files
COPY --chown=appuser:appuser start.sh /usr/local/bin/start
COPY --chown=appuser:appuser config/etc /etc
COPY --chown=appuser:appuser config/etc/php/8.3/cli/conf.d/y-php.ini /etc/php/8.3/fpm/conf.d/y-php.ini

# Permissions for start script
RUN chmod a+x /usr/local/bin/start
# Permissions
RUN chmod a+x /usr/local/bin/start
RUN mkdir -p /run/php
RUN chown -R appuser:appuser /var/www/app /var/log /var/lib /run

# Required for php-fpm and nginx as non-root user
RUN mkdir -p /run/php
RUN chown -R appuser:appuser /var/www/app /var/log /var/lib /run
RUN chmod -R 777 /var/log /var/lib /run
# Composer
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer

# Switch to non-root user
USER appuser

# Laravel Installer
RUN composer global require laravel/installer && composer clear-cache
# Laravel Installer
RUN composer global require laravel/installer && composer clear-cache

# OhMyZsh (better than "bash")
RUN sh -c "$(curl -fsSL https://raw.github.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
RUN sh -c "$(curl -fsSL https://raw.github.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"

# Add composer to PATH
RUN echo 'export PATH="$PATH:$HOME/.config/composer/vendor/bin"' >> ~/.zshrc
# Node, NPM, Yarn
RUN curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash \
&& export NVM_DIR="$HOME/.nvm" && [ -s "$NVM_DIR/nvm.sh" ] && . ${HOME}/.nvm/nvm.sh && nvm install --lts \
&& echo 'export PATH="$PATH:$HOME/.nvm/versions/node/'$(node -v)'/bin"' >> ~/.zshrc \
&& corepack enable && corepack prepare yarn@stable --activate

# Nginx (8080), Node (3000/3001), Laravel Dusk (9515/9773)
EXPOSE 8080 8000 3000 3001 9515 9773
# Nginx (8080)
EXPOSE 8080

# Start services through "supervisor" based on "CONTAINER_ROLE". See "start.sh".
CMD /usr/local/bin/start
2 changes: 1 addition & 1 deletion config/etc/nginx/sites-available/default
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ server {

# PHP
location ~ \.php$ {
fastcgi_pass unix:/home/appuser/php8.3-fpm.sock;
fastcgi_pass unix:/var/run/php8.3-fpm.sock;
fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
include fastcgi_params;
}
Expand Down
2 changes: 1 addition & 1 deletion config/etc/php/8.3/fpm/pool.d/y-www.conf
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ user = appuser
group = appuser
listen.owner = appuser
listen.group = appuser
listen = /home/appuser/php8.3-fpm.sock
listen = /var/run/php8.3-fpm.sock
clear_env = no

; fpm tuning
Expand Down
2 changes: 0 additions & 2 deletions config/etc/supervisord.conf
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
nodaemon=true
logfile=/dev/null
logfile_maxbytes=0
pidfile=/home/appuser/supervisor.pid
# loglevel=debug

# It is empty. Conf will be handled by "start.sh" script
[include]
Expand Down

0 comments on commit 364c0bb

Please sign in to comment.