Dockerfile and scripting improvements
This commit is contained in:
parent
b44d428493
commit
b768471a7d
16
.env.dist
16
.env.dist
@ -8,3 +8,19 @@ DOCKER_DATADIR=./data
|
||||
# Pleroma's mix environment.
|
||||
# You should leave this at prod unless you know what you're doing.
|
||||
MIX_ENV=prod
|
||||
|
||||
# The uid/gid used by pleroma.
|
||||
# You should probably set this to the same
|
||||
# uid/guid that cloned the pleroma-docker repo.
|
||||
# This way modding pleroma becomes a lot easier.
|
||||
DOCKER_UID=1000
|
||||
DOCKER_GID=1000
|
||||
|
||||
# The git repo where pleroma's sources are located.
|
||||
# This will be used at build-time and to resolve PLEROMA_VERSION via "git ls-remote".
|
||||
# The latter involves one connection per "pleroma.sh build" execution, even if a rebuild does not occur.
|
||||
#
|
||||
# You might want to change this if you're working on a fork,
|
||||
# or if you do not trust the admins of pleroma's Gitlab instance.
|
||||
#
|
||||
PLEROMA_GIT_REPO=https://git.pleroma.social/pleroma/pleroma.git
|
||||
|
8
.gitignore
vendored
8
.gitignore
vendored
@ -1,10 +1,10 @@
|
||||
data
|
||||
.env
|
||||
config.yml
|
||||
data/
|
||||
cache/
|
||||
custom.d/
|
||||
!custom.d/.gitkeep
|
||||
docker-compose.yml
|
||||
config.exs
|
||||
secret.exs
|
||||
.env
|
||||
|
||||
# Created by https://www.gitignore.io/api/osx,linux,windows
|
||||
|
||||
|
47
Dockerfile
47
Dockerfile
@ -10,7 +10,8 @@ RUN \
|
||||
# Set up environment
|
||||
ENV LC_ALL=C.UTF-8
|
||||
ENV LANG=C.UTF-8
|
||||
ENV MIX_ENV=prod
|
||||
ARG MIX_ENV
|
||||
ENV MIX_ENV=$MIX_ENV
|
||||
|
||||
# Prepare mounts
|
||||
VOLUME /custom.d
|
||||
@ -22,12 +23,14 @@ EXPOSE 4000
|
||||
RUN \
|
||||
apk add --no-cache --virtual .tools \
|
||||
git curl rsync postgresql-client \
|
||||
\
|
||||
&& apk add --no-cache --virtual .sdk \
|
||||
&& \
|
||||
apk add --no-cache --virtual .sdk \
|
||||
build-base \
|
||||
\
|
||||
&& apk add --no-cache --virtual .runtime \
|
||||
imagemagick erlang erlang-runtime-tools erlang-xmerl erlang-ssl erlang-eldap elixir
|
||||
&& \
|
||||
apk add --no-cache --virtual .runtime \
|
||||
imagemagick \
|
||||
elixir erlang erlang-runtime-tools \
|
||||
erlang-xmerl erlang-ssl erlang-ssh erlang-eldap
|
||||
|
||||
# Add entrypoint
|
||||
COPY ./entrypoint.sh /
|
||||
@ -35,21 +38,25 @@ RUN chmod a+x /entrypoint.sh
|
||||
ENTRYPOINT ["/entrypoint.sh"]
|
||||
|
||||
# Limit permissions
|
||||
ARG DOCKER_UID=1000
|
||||
ARG DOCKER_GID=1000
|
||||
ARG PLEROMA_UPLOADS_PATH=/uploads
|
||||
ARG DOCKER_UID
|
||||
ARG DOCKER_GID
|
||||
|
||||
RUN \
|
||||
addgroup -g ${DOCKER_GID} pleroma \
|
||||
&& adduser -S -s /bin/ash -G pleroma -u ${DOCKER_UID} pleroma \
|
||||
&& mkdir -p /custom.d $PLEROMA_UPLOADS_PATH \
|
||||
&& chown -R pleroma:pleroma /custom.d $PLEROMA_UPLOADS_PATH
|
||||
echo "#> Pleroma user will be ${DOCKER_UID}:${DOCKER_GID}" 1>&2 && \
|
||||
addgroup -g ${DOCKER_GID} pleroma && \
|
||||
adduser -S -s /bin/ash -G pleroma -u ${DOCKER_UID} pleroma && \
|
||||
mkdir -p /custom.d /uploads && \
|
||||
chown -R pleroma:pleroma /custom.d /uploads
|
||||
|
||||
USER pleroma
|
||||
WORKDIR /home/pleroma
|
||||
|
||||
# Get pleroma sources
|
||||
RUN git clone --progress https://git.pleroma.social/pleroma/pleroma.git ./pleroma
|
||||
ARG PLEROMA_GIT_REPO
|
||||
RUN \
|
||||
echo "#> Getting pleroma sources from $PLEROMA_GIT_REPO..." 1>&2 && \
|
||||
git clone --progress $PLEROMA_GIT_REPO ./pleroma
|
||||
|
||||
WORKDIR /home/pleroma/pleroma
|
||||
|
||||
# Bust the build cache (if needed)
|
||||
@ -63,12 +70,12 @@ ENV __CACHE_TAG $__CACHE_TAG
|
||||
# Fetch changes, checkout
|
||||
ARG PLEROMA_VERSION
|
||||
RUN \
|
||||
git fetch --all \
|
||||
&& git checkout $PLEROMA_VERSION \
|
||||
&& git pull --rebase --autostash
|
||||
git fetch --all && \
|
||||
git checkout $PLEROMA_VERSION && \
|
||||
git pull --rebase --autostash
|
||||
|
||||
# Precompile
|
||||
RUN \
|
||||
cp ./config/dev.exs ./config/prod.secret.exs \
|
||||
&& BUILDTIME=1 /entrypoint.sh \
|
||||
&& rm ./config/prod.secret.exs
|
||||
cp ./config/dev.exs ./config/prod.secret.exs && \
|
||||
BUILDTIME=1 /entrypoint.sh && \
|
||||
rm ./config/prod.secret.exs
|
||||
|
@ -11,8 +11,10 @@ config :pleroma, Pleroma.Repo,
|
||||
hostname: "db",
|
||||
pool_size: 10
|
||||
|
||||
# Listening to 0.0.0.0 is required in a container
|
||||
# Do not change this
|
||||
# Listening to 0.0.0.0 is required in a container since the IP is not known in advance
|
||||
# You should not change the options below this.
|
||||
# Instead, go change the mapping to your host ports in "docker-compose.yml"
|
||||
|
||||
config :pleroma, Pleroma.Web.Endpoint,
|
||||
http: [
|
||||
ip: {0, 0, 0, 0},
|
||||
@ -23,6 +25,9 @@ config :pleroma, :gopher,
|
||||
ip: {0, 0, 0, 0},
|
||||
port: 9999
|
||||
|
||||
config :esshd,
|
||||
port: 2222
|
||||
|
||||
# vvv Your awesome config options go here vvv
|
||||
|
||||
###
|
||||
|
41
docker-compose.yml
Normal file
41
docker-compose.yml
Normal file
@ -0,0 +1,41 @@
|
||||
version: "3.7"
|
||||
|
||||
services:
|
||||
db:
|
||||
image: postgres:10-alpine
|
||||
init: true
|
||||
restart: unless-stopped
|
||||
environment:
|
||||
POSTGRES_DB: pleroma
|
||||
POSTGRES_USER: pleroma
|
||||
POSTGRES_PASSWORD: pleroma
|
||||
volumes:
|
||||
- $DOCKER_DATADIR/db:/var/lib/postgresql/data
|
||||
- ./initdb.sql:/docker-entrypoint-initdb.d/pleroma.sql
|
||||
|
||||
server:
|
||||
build: .
|
||||
init: true
|
||||
restart: unless-stopped
|
||||
links:
|
||||
- db
|
||||
ports: [
|
||||
# Uncomment/Change port mappings below as needed.
|
||||
# The left side is your host machine, the right one is the pleroma container.
|
||||
# You can prefix the left side with an ip.
|
||||
|
||||
# Webserver (for reverse-proxies outside of docker)
|
||||
# If you use a dockerized proxy (see README), you can leave this commented
|
||||
# and use a container link instead.
|
||||
# "127.0.0.1:4000:4000",
|
||||
|
||||
# SSH support
|
||||
# "2222:2222",
|
||||
|
||||
# Gopher support
|
||||
# "9999:9999",
|
||||
]
|
||||
volumes:
|
||||
- ./custom.d:/custom.d:ro
|
||||
- ./config.exs:/home/pleroma/pleroma/config/prod.secret.exs:ro
|
||||
- $DOCKER_DATADIR/uploads:/uploads
|
@ -3,34 +3,38 @@
|
||||
|
||||
set -e
|
||||
|
||||
log() {
|
||||
echo -e "\n#> $@\n" 1>&2
|
||||
}
|
||||
|
||||
if [ -n "$BUILDTIME" ]; then
|
||||
echo "#> Getting rebar..."
|
||||
log "Getting rebar..."
|
||||
mix local.rebar --force
|
||||
|
||||
echo "#> Getting hex..."
|
||||
log "Getting hex..."
|
||||
mix local.hex --force
|
||||
|
||||
echo "#> Getting dependencies..."
|
||||
log "Getting dependencies..."
|
||||
mix deps.get
|
||||
|
||||
echo "#> Precompiling..."
|
||||
log "Precompiling..."
|
||||
mix compile
|
||||
exit 0
|
||||
fi
|
||||
|
||||
echo "#> Applying customizations and patches.."
|
||||
log "Syncing changes and patches..."
|
||||
rsync -av /custom.d/ /home/pleroma/pleroma/
|
||||
|
||||
echo "#> Recompiling..."
|
||||
log "Recompiling..."
|
||||
mix compile
|
||||
|
||||
echo "#> Waiting until database is ready..."
|
||||
log "Waiting for postgres..."
|
||||
while ! pg_isready -U pleroma -d postgres://db:5432/pleroma -t 1; do
|
||||
sleep 1s
|
||||
done
|
||||
|
||||
echo "#> Upgrading database..."
|
||||
log "Migrating database..."
|
||||
mix ecto.migrate
|
||||
|
||||
echo "#> Liftoff!"
|
||||
log "Liftoff o/"
|
||||
exec mix phx.server
|
||||
|
10
pleroma.sh
10
pleroma.sh
@ -77,12 +77,14 @@ request_file_content() { # $1: source
|
||||
fi
|
||||
}
|
||||
|
||||
builds_args=""
|
||||
load_env() {
|
||||
while read -r line; do
|
||||
if [[ "$line" == \#* ]] || [[ -z "$line" ]]; then
|
||||
continue;
|
||||
fi
|
||||
|
||||
builds_args="${builds_args} --build-arg ${line?}"
|
||||
export "${line?}"
|
||||
done < .env
|
||||
}
|
||||
@ -98,7 +100,7 @@ action__build() {
|
||||
if [[ -z "$cacheTag" ]] && has_command git && has_command grep && has_command awk; then
|
||||
set +o pipefail
|
||||
local resolvedHash
|
||||
resolvedHash="$(git ls-remote $GITLAB_URI/$ENDPOINT_REPO | grep "/$PLEROMA_VERSION" | awk '{ print $1 }')"
|
||||
resolvedHash="$(git ls-remote $PLEROMA_GIT_REPO | grep "/$PLEROMA_VERSION" | awk '{ print $1 }')"
|
||||
set -o pipefail
|
||||
|
||||
if [[ -n "$resolvedHash" ]]; then
|
||||
@ -169,7 +171,11 @@ action__build() {
|
||||
echo -e "#> (Re-)Building pleroma @$PLEROMA_VERSION with cache tag \`${cacheTag}\`...\n"
|
||||
sleep 1
|
||||
|
||||
docker_compose build --build-arg __VIA_SCRIPT=1 --build-arg __CACHE_TAG="$cacheTag" --build-arg PLEROMA_VERSION="$PLEROMA_VERSION" server
|
||||
docker_compose build \
|
||||
$builds_args \
|
||||
--build-arg __VIA_SCRIPT=1 \
|
||||
--build-arg __CACHE_TAG="$cacheTag" \
|
||||
server
|
||||
}
|
||||
|
||||
action__enter() {
|
||||
|
Loading…
Reference in New Issue
Block a user