FROM php:8.2-cli-bullseye

MAINTAINER Markus Wagner <markus.wagner@bgm-gmbh.de>

LABEL description="Docker image for the awinta.de deployment"

ENV DEBIAN_FRONTEND=noninteractive

# Install stuff
RUN apt-get update \
	&& apt-get install -y \
		openssh-client \
		libssl-dev \
		git \
		locales \
		rsync \
		zip \
		unzip \
		gnupg \
		procps \
		wget \
		curl \
		libcurl4-openssl-dev \
		libzip-dev \
		zlib1g-dev \
		libxml2-dev \
		libfreetype6-dev \
		libjpeg62-turbo-dev \
		build-essential \
		python \
	&& rm -rf /var/lib/apt/lists/* \
	&& curl -sL https://deb.nodesource.com/setup_14.x | bash - \
	&& apt-get install -y nodejs \
	&& apt-get autoremove -y \
	&& apt-get clean \
	&& docker-php-ext-install zip \
	&& docker-php-ext-install xml \
	&& docker-php-ext-install gd \
	&& docker-php-ext-install intl \
	&& docker-php-ext-install bcmath \
	&& docker-php-ext-install curl \
    && docker-php-ext-install soap \
	&& pecl install -o -f redis && rm -rf /tmp/pear && docker-php-ext-enable redis

RUN /usr/bin/wget -O /etc/ssl/certs/cacert.pem 'http://curl.haxx.se/ca/cacert.pem' && echo 'openssl.cafile=/etc/ssl/certs/cacert.pem' > /usr/local/etc/php/conf.d/cacert.ini
RUN git config --global http.sslcainfo /etc/ssl/certs/cacert.pem

#Install composer
RUN ["/bin/bash", "-c", "php -r 'copy(\"https://getcomposer.org/installer\", \"composer-setup.php\");' && php -r 'if (hash_file(\"SHA384\", \"composer-setup.php\") === \"dac665fdc30fdd8ec78b38b9800061b4150413ff2e3b6f88543c636f7cd84f6db9189d43a81e5503cda447da73c7e5b6\") { echo \"Installer verified\"; } else { echo \"Installer corrupt\"; unlink(\"composer-setup.php\"); } echo PHP_EOL;' && php composer-setup.php --install-dir=/usr/local/bin && php -r 'unlink(\"composer-setup.php\");'"]

#Install Grunt
RUN ["/bin/bash", "-c", "npm install -g grunt-cli"]

# Prepare ssh
RUN eval $(ssh-agent -s) \
	&& mkdir -p ~/.ssh \
	&& chmod 700 ~/.ssh
COPY ./ssh-config /root/.ssh/config
RUN chmod 600 ~/.ssh/config

# Set locale and timezone
ENV TZ=Europe/Berlin
ENV LANG=en_US.UTF-8
RUN sed -i -e 's/# en_US.UTF-8 UTF-8/en_US.UTF-8 UTF-8/' /etc/locale.gen \
	&& echo 'LANG="en_US.UTF-8"'>/etc/default/locale \
	&& dpkg-reconfigure --frontend=noninteractive locales \
	&& update-locale LANG=en_US.UTF-8 \
	&& ln -snf /usr/share/zoneinfo/$TZ /etc/localtime \
	&& echo $TZ > /etc/timezone

# Set umask
COPY ./docker-entrypoint.sh /
ENTRYPOINT ["/docker-entrypoint.sh"]

# Dummy command, overwritten when calling "docker run"
CMD ["echo 'machine running...' && tail -f /dev/null"]
