Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add asdf to base image and use it to install Node.js #24

Merged
merged 1 commit into from
Mar 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: ✨ lint
name: ✨ Lint

on:
pull_request:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/push.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: 🚀 push
name: 🚀 Push

on:
workflow_dispatch:
Expand Down
142 changes: 76 additions & 66 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,93 +1,103 @@
FROM ubuntu:22.04

LABEL maintainer="GBH DevOps Team <devops@gbh.com.do>"
LABEL maintainer="GBH DevOps Team <devops@gbh.tech>"

SHELL ["/bin/bash", "-o", "pipefail", "-c"]
SHELL ["/bin/bash", "-leo", "pipefail", "-c"]

ARG PHP_VERSION=8.1
ARG ASDF_VERSION=0.14.0
ARG NODEJS_VERSION=20

ENV DEBIAN_FRONTEND noninteractive
ENV NODE_VERSION 20.x

ENV LANG en_US.UTF-8
ENV LANGUAGE en_US.UTF-8
ENV LC_ALL en_US.UTF-8

# We accept the risk of installing system dependencies with
# apt without specifying their versions.
# hadolint ignore=DL3008
RUN apt-get update -yq && \
apt-get install --no-install-recommends -yq \
apt-utils \
curl \
software-properties-common \
ca-certificates \
lsb-release \
apt-transport-https \
gnupg2 \
ca-certificates \
lsb-release \
build-essential \
git \
locales \
ubuntu-keyring && \
mkdir -p /etc/apt/keyrings && \
curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg && \
echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_$NODE_VERSION nodistro main" | tee /etc/apt/sources.list.d/nodesource.list && \
add-apt-repository ppa:ondrej/php && \
curl https://nginx.org/keys/nginx_signing.key | gpg --dearmor | \
tee /usr/share/keyrings/nginx-archive-keyring.gpg >/dev/null && \
echo "deb [signed-by=/usr/share/keyrings/nginx-archive-keyring.gpg] \
http://nginx.org/packages/ubuntu $(lsb_release -cs) nginx" | \
tee /etc/apt/sources.list.d/nginx.list && \
echo -e "Package: *\nPin: origin nginx.org\nPin: release o=nginx\nPin-Priority: 900\n" | \
tee /etc/apt/preferences.d/99nginx && \
apt-get update -yq && \
apt-get install --no-install-recommends -yq \
php${PHP_VERSION}-cli \
php${PHP_VERSION}-curl \
php${PHP_VERSION}-dev \
php${PHP_VERSION}-fpm \
php${PHP_VERSION}-gd \
php${PHP_VERSION}-mbstring \
php${PHP_VERSION}-mysql \
php${PHP_VERSION}-pgsql \
php${PHP_VERSION}-readline \
php${PHP_VERSION}-xml \
php${PHP_VERSION}-zip \
supervisor \
unzip \
vim \
nodejs \
nginx && \
locale-gen en_US.UTF-8 && \
dpkg-reconfigure locales && \
mkdir -p /run/php && \
update-alternatives --set php /usr/bin/php${PHP_VERSION} && \
update-alternatives --set php-config /usr/bin/php-config${PHP_VERSION} && \
update-alternatives --set phpize /usr/bin/phpize${PHP_VERSION} && \
sed -i "s/error_reporting = .*/error_reporting = E_ALL/" /etc/php/${PHP_VERSION}/fpm/php.ini && \
sed -i "s/display_errors = .*/display_errors = On/" /etc/php/${PHP_VERSION}/fpm/php.ini && \
sed -i "s/;cgi.fix_pathinfo=1/cgi.fix_pathinfo=0/" /etc/php/${PHP_VERSION}/fpm/php.ini && \
sed -i "s/memory_limit = .*/memory_limit = 512M/" /etc/php/${PHP_VERSION}/fpm/php.ini && \
sed -i "s/upload_max_filesize = .*/upload_max_filesize = 100M/" /etc/php/${PHP_VERSION}/fpm/php.ini && \
sed -i "s/post_max_size = .*/post_max_size = 100M/" /etc/php/${PHP_VERSION}/fpm/php.ini && \
sed -i "s/;date.timezone.*/date.timezone = UTC/" /etc/php/${PHP_VERSION}/fpm/php.ini && \
apt-get clean && rm -rf /var/lib/apt/lists/*
# hadolint ignore=DL3008,SC1091
RUN apt-get update -yq \
&& apt-get install --no-install-recommends -yq \
apt-utils \
curl \
software-properties-common \
ca-certificates \
lsb-release \
apt-transport-https \
gnupg2 \
ca-certificates \
lsb-release \
build-essential \
git \
locales \
ubuntu-keyring \
&& mkdir -p /etc/apt/keyrings \
&& curl https://nginx.org/keys/nginx_signing.key | gpg --dearmor | \
tee /usr/share/keyrings/nginx-archive-keyring.gpg >/dev/null \
# Install PHP repository
&& add-apt-repository ppa:ondrej/php \
# Install Nginx repository
&& echo "deb [signed-by=/usr/share/keyrings/nginx-archive-keyring.gpg] \
http://nginx.org/packages/ubuntu $(lsb_release -cs) nginx" | \
tee /etc/apt/sources.list.d/nginx.list \
&& echo -e "Package: *\nPin: origin nginx.org\nPin: release o=nginx\nPin-Priority: 900\n" | \
tee /etc/apt/preferences.d/99nginx \
# Install asdf
&& git clone https://github.com/asdf-vm/asdf.git ~/.asdf --branch v${ASDF_VERSION} \
&& echo ". $HOME/.asdf/asdf.sh" >> ~/.bashrc \
&& . "$HOME/.asdf/asdf.sh" \
# Install Node.js with asdf
&& asdf plugin add nodejs \
&& asdf install nodejs latest:${NODEJS_VERSION} \
&& asdf global nodejs latest:${NODEJS_VERSION} \
# Install PHP packages
&& apt-get update -yq \
&& apt-get install --no-install-recommends -yq \
php${PHP_VERSION}-cli \
php${PHP_VERSION}-curl \
php${PHP_VERSION}-dev \
php${PHP_VERSION}-fpm \
php${PHP_VERSION}-gd \
php${PHP_VERSION}-mbstring \
php${PHP_VERSION}-mysql \
php${PHP_VERSION}-pgsql \
php${PHP_VERSION}-readline \
php${PHP_VERSION}-xml \
php${PHP_VERSION}-zip \
supervisor \
unzip \
vim \
nginx \
&& locale-gen en_US.UTF-8 \
&& dpkg-reconfigure locales \
&& mkdir -p /run/php \
&& update-alternatives --set php /usr/bin/php${PHP_VERSION} \
&& update-alternatives --set php-config /usr/bin/php-config${PHP_VERSION} \
&& update-alternatives --set phpize /usr/bin/phpize${PHP_VERSION} \
# Update php.ini for FPM
&& sed -i "s/error_reporting = .*/error_reporting = E_ALL/" /etc/php/${PHP_VERSION}/fpm/php.ini \
&& sed -i "s/display_errors = .*/display_errors = On/" /etc/php/${PHP_VERSION}/fpm/php.ini \
&& sed -i "s/;cgi.fix_pathinfo=1/cgi.fix_pathinfo=0/" /etc/php/${PHP_VERSION}/fpm/php.ini \
&& sed -i "s/memory_limit = .*/memory_limit = 512M/" /etc/php/${PHP_VERSION}/fpm/php.ini \
&& sed -i "s/upload_max_filesize = .*/upload_max_filesize = 100M/" /etc/php/${PHP_VERSION}/fpm/php.ini \
&& sed -i "s/post_max_size = .*/post_max_size = 100M/" /etc/php/${PHP_VERSION}/fpm/php.ini \
&& sed -i "s/;date.timezone.*/date.timezone = UTC/" /etc/php/${PHP_VERSION}/fpm/php.ini \
&& apt-get clean && rm -rf /var/lib/apt/lists/*

# hadolint ignore=DL3022
COPY --from=composer:2.6.5 /usr/bin/composer /usr/bin/composer

COPY nginx/site.conf /etc/nginx/conf.d/site.conf
COPY supervisor /etc/supervisor/conf.d

# PHP_VERSION is an ARG, even if 7.4 is the default we want
# PHP_VERSION is an ARG, even if 8.0 is the default we want
angelmadames marked this conversation as resolved.
Show resolved Hide resolved
# to make sure we use the specified version here.
RUN sed -i "s/7.4/${PHP_VERSION}/" /etc/nginx/conf.d/site.conf \
&& sed -i "s/7.4/${PHP_VERSION}/g" /etc/supervisor/conf.d/php-fpm.conf
RUN sed -i "s/8.0/${PHP_VERSION}/" /etc/nginx/conf.d/site.conf \
&& sed -i "s/8.0/${PHP_VERSION}/g" /etc/supervisor/conf.d/php-fpm.conf

# Fix www-data user in nginx.conf file
RUN sed -i "s/user\s*nginx;/user www-data;/g" /etc/nginx/nginx.conf

WORKDIR /usr/app

EXPOSE 80
Expand Down
52 changes: 33 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,25 +1,36 @@
<!-- omit in toc -->
# Docker images - LEP
# gbh.tech - Linux, Nginx PHP (LEP) Docker Image

- [:page\_facing\_up: Description](#page_facing_up-description)
- [:card\_file\_box: Included dependencies](#card_file_box-included-dependencies)
- [:bookmark\_tabs: Relevant considerations](#bookmark_tabs-relevant-considerations)
- [:dart: How To Use](#dart-how-to-use)
- [:whale2: Build your image](#whale2-build-your-image)
- [:rocket: Run your app](#rocket-run-your-app)
[![🧪 Tests](https://github.com/gbh-tech/lep-docker/actions/workflows/test.yml/badge.svg)](https://github.com/gbh-tech/lep-docker/actions/workflows/test.yml)
[![🚀 Push](https://github.com/gbh-tech/lep-docker/actions/workflows/push.yml/badge.svg)](https://github.com/gbh-tech/lep-docker/actions/workflows/push.yml)
[![✨ Lint](https://github.com/gbh-tech/lep-docker/actions/workflows/lint.yml/badge.svg)](https://github.com/gbh-tech/lep-docker/actions/workflows/lint.yml)

## :page_facing_up: Description
<!-- omit in toc -->
## Content

- [📄 Description](#-description)
- [🗃️ Included dependencies](#️-included-dependencies)
- [🔖 Relevant considerations](#-relevant-considerations)
- [🎯 How To Use](#-how-to-use)
- [🐳 Build your image](#-build-your-image)
- [🚀 Run your app](#-run-your-app)

## 📄 Description

LEP comes from the original `LAMP` stack which was based on **L**inux, **A**pache, **M**ySQL and **P**HP. LEP is a docker-oriented alternative that uses Nginx in favor Apache and separates the MySQL dependency since it can be configured as a service using docker compose.
LEP comes from the original `LAMP` stack which was based on **L**inux,
**A**pache, **M**ySQL and **P**HP. LEP is a docker-oriented alternative
that uses Nginx in favor Apache and separates the MySQL dependency since it
can be configured as a service using docker compose.

> **Note**: This image is **not meant for production** use. It was designed to serve as an auxiliary image for development and testing environments.
> **Note**: This image is **not meant for production** use. It was designed
> to serve as an auxiliary image for development and testing environments.

## :card_file_box: Included dependencies
## 🗃️ Included dependencies

- Ubuntu Jammy
- Node.js 20.x
- git
- nginx
- Git
- Nginx
- PHP (7.4, 8.0, 8.1)
- php-cli
- php-curl
Expand All @@ -34,13 +45,16 @@ LEP comes from the original `LAMP` stack which was based on **L**inux, **A**pach
- php-xml
- php-zip

## :bookmark_tabs: Relevant considerations
## 🔖 Relevant considerations

- The default user for your web files should be `www-data`. If the permissions of your files are not properly set, you might end up with HTTP 403 errors from the web server.
- The default user for your web files should be `www-data`.
If the permissions of your files are not properly set, you might end up
with HTTP 403 errors from the web server.

## :dart: How To Use
## 🎯 How To Use

To use this image, you should set it as your base image using the `FROM` instruction:
To use this image, you should set it as your base image using the
`FROM` instruction:

```docker
FROM solucionesgbh/lep:${PHP_VERSION}
Expand All @@ -65,15 +79,15 @@ COPY --chown=www-data:www-data .
CMD ["/usr/bin/supervisord", "--nodaemon", "-c", "/etc/supervisor/supervisord.conf"]
```

## :whale2: Build your image
## 🐳 Build your image

To build your custom image, on your terminal execute the following `docker build` command:

```shell
docker build . -t myapp:myversion
```

## :rocket: Run your app
## 🚀 Run your app

To run your custom container, on your terminal execute the following `docker run` command:

Expand Down
2 changes: 1 addition & 1 deletion nginx/site.conf
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
upstream php {
server unix:/run/php/php7.4-fpm.sock;
server unix:/run/php/php8.0-fpm.sock;
}

server {
Expand Down
2 changes: 1 addition & 1 deletion supervisor/php-fpm.conf
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[program:php-fpm]
command=/usr/sbin/php-fpm7.4 --nodaemonize --fpm-config=/etc/php/7.4/fpm/php-fpm.conf
command=/usr/sbin/php-fpm8.0 --nodaemonize --fpm-config=/etc/php/8.0/fpm/php-fpm.conf
autostart=true
autorestart=true
priority=5
Expand Down
Loading