From 081838417229260ddaf538289199da08d90cd18e Mon Sep 17 00:00:00 2001 From: everzone <59465158+everzone@users.noreply.github.com> Date: Tue, 5 Oct 2021 00:26:09 +0900 Subject: [PATCH] Add Alpine Dockerfile (#1048) --- docker/alpine/Dockerfile | 42 ++++++++++++++++++++++++++++++++++++++++ docker/alpine/README.md | 32 ++++++++++++++++++++++++++++++ 2 files changed, 74 insertions(+) create mode 100644 docker/alpine/Dockerfile create mode 100644 docker/alpine/README.md diff --git a/docker/alpine/Dockerfile b/docker/alpine/Dockerfile new file mode 100644 index 00000000..e2146999 --- /dev/null +++ b/docker/alpine/Dockerfile @@ -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 diff --git a/docker/alpine/README.md b/docker/alpine/README.md new file mode 100644 index 00000000..83c7c33d --- /dev/null +++ b/docker/alpine/README.md @@ -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 +```