FROM alpine:3.15

ADD https://php.hernandev.com/key/php-alpine.rsa.pub /etc/apk/keys/php-alpine.rsa.pub

RUN apk add ca-certificates \
    && echo -e '\
https://mirrors.ustc.edu.cn/alpine/latest-stable/main\n\
https://mirrors.ustc.edu.cn/alpine/latest-stable/community\n\
https://php.hernandev.com/v3.15/php-8.1\
' > /etc/apk/repositories \
    && apk update \
    && apk add \
    tzdata \
    php \
    php-pgsql \
    # event扩展运行时需要
    php-sockets \
    # 以下两件为workerman运行时需要
    # https://github.com/walkor/workerman/issues/8
    php-posix \
    php-pcntl \
    # 安装event扩展需要pecl
    php-pear \
    # 提供phpize
    php-dev \
    # 编译event扩展需要
    autoconf \
    # 以下两件足以在alpine里提供一般C编译环境
    # g++则会提供gcc、musl-dev、libc-dev和g++，有点冗余
    gcc \
    musl-dev \
    libevent-dev \
    make \
    composer \
    && cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime \
    && echo "Asia/Shanghai" >  /etc/timezone \
    && ln -s /usr/bin/php8 /usr/bin/php

RUN printf "\n\n\n\n\nno\nyes\n\n" | pecl install event \
    && echo "extension=event.so" > /etc/php8/conf.d/02_event.ini

COPY . /EdgeManager

WORKDIR /EdgeManager

RUN composer config -g repo.packagist composer https://mirrors.aliyun.com/composer/ \
    && composer u --no-cache

RUN apk del \
    tzdata \
    composer \
    ca-certificates \
    php-pear \
    php-dev \
    autoconf \
    gcc \
    musl-dev \
    make \
    && rm -rf /var/cache/apk/* \
    /etc/apk/keys/php-alpine.rsa.pub \
    /tmp/*
