Add Alpine Dockerfile (#1048)

This commit is contained in:
everzone 2021-10-05 00:26:09 +09:00 committed by GitHub
parent ac4a816a99
commit 0818384172
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 74 additions and 0 deletions

42
docker/alpine/Dockerfile Normal file
View File

@ -0,0 +1,42 @@
FROM alpine:3.14
ARG USER=drogon
ARG UID=1000
ARG GID=1000
ARG USER_HOME=/drogon
ENV TZ=UTC
RUN apk update && apk --no-cache --upgrade add tzdata \
&& ln -snf /usr/share/zoneinfo/$TZ /etc/localtime \
&& echo $TZ > /etc/timezone
RUN apk --no-cache --upgrade add \
sudo curl wget cmake make pkgconfig git gcc g++ \
openssl libressl-dev jsoncpp-dev util-linux-dev zlib-dev c-ares-dev \
postgresql-dev mariadb-dev sqlite-dev hiredis-dev
RUN addgroup -S -g $GID $USER \
&& adduser -D -u $UID -G $USER -h $USER_HOME $USER \
&& mkdir -p /etc/sudoers.d \
&& echo "$USER ALL=(ALL) NOPASSWD: ALL" > /etc/sudoers.d/$USER \
&& chmod 0440 /etc/sudoers.d/$USER
USER $USER
WORKDIR $USER_HOME
ENV LANG=en_US.UTF-8 \
LANGUAGE=en_US:en \
LC_ALL=en_US.UTF-8 \
CC=gcc \
CXX=g++ \
AR=gcc-ar \
RANLIB=gcc-ranlib \
DROGON_INSTALLED_ROOT=$USER_HOME/install
RUN wget -O $USER_HOME/version.json https://api.github.com/repos/an-tao/drogon/git/refs/heads/master \
&& git clone https://github.com/an-tao/drogon $DROGON_INSTALLED_ROOT
RUN cd $DROGON_INSTALLED_ROOT \
&& sed -i 's/bash/sh/' ./build.sh \
&& ./build.sh

32
docker/alpine/README.md Normal file
View File

@ -0,0 +1,32 @@
## Build Docker Image
```shell
$ cd drogon/docker/alpine # from this repository
$ docker build --no-cache --build-arg UID=`id -u` --build-arg GID=`id -g` -t drogon-alpine . # include last dot(.)
```
## Create a Drogon Project
```shell
$ cd ~/drogon_app # example
$ docker run --rm -v="$PWD:/drogon/app" -w="/drogon/app" drogon-alpine drogon_ctl create project hello_world
```
## Build the Project
```shell
$ cd hello_world
$ docker run --rm --volume="$PWD:/drogon/app" -w="/drogon/app/build" drogon-alpine sh -c "cmake .. && make"
```
## Start Server
```shell
$ docker run --name drogon_test --rm -u 0 -v="$PWD/build:/drogon/app" -w="/drogon/app" -p 8080:80 -d drogon-alpine ./hello_world # expose port 80 to 8080
```
## Stop Server
```shell
$ docker kill drogon_test
```