Improve cache behaviour

This commit is contained in:
sn0w 2018-04-09 11:55:52 +02:00
parent 37c5f61633
commit f0a04f30d5
4 changed files with 44 additions and 28 deletions

View File

@ -31,7 +31,6 @@ services:
dockerfile: ./pleroma.dockerfile dockerfile: ./pleroma.dockerfile
args: args:
env(`pleroma_version') env(`pleroma_version')
env_fb(`mix_env', `prod')
restart: unless-stopped restart: unless-stopped
links: links:
- db - db

View File

@ -2,6 +2,24 @@
set -e set -e
function compile {
# Make sure that the tooling is present
mix local.hex --force
mix local.rebar --force
# Recompile
mix deps.get
mix compile
}
# Execute onbuild actions if required
if [[ "$1" == "onbuild" ]]; then
# On build we use the sources instead of the runtime
cd /pleroma
compile
exit 0
fi
# Ensure that the environment is clean # Ensure that the environment is clean
if [[ -d /pleroma-runtime ]]; then if [[ -d /pleroma-runtime ]]; then
rm -rf /pleroma-runtime rm -rf /pleroma-runtime
@ -17,13 +35,8 @@ rsync -azI /custom.d/ /pleroma-runtime/
# Go to runtime workspace # Go to runtime workspace
cd /pleroma-runtime cd /pleroma-runtime
# Make sure that the tooling is present # Build
mix local.hex --force compile
mix local.rebar --force
# Recompile
mix deps.get
mix clean && mix compile
# Prepare DB # Prepare DB
mix ecto.create mix ecto.create

17
pleroma
View File

@ -34,20 +34,6 @@ Actions:
" "
} }
function run_dockerized {
log_info "Stopping existing containers (if any)"
docker-compose down
log_info "Rebuilding images"
docker-compose build
log_info "Running action '$1'"
docker-compose run server $1
log_info "Cleaning up.."
docker-compose down
}
function action__start { function action__start {
log_info "Booting pleroma" log_info "Booting pleroma"
docker-compose up --remove-orphans -d docker-compose up --remove-orphans -d
@ -65,7 +51,8 @@ function action__logs {
} }
function action__build { function action__build {
docker-compose build docker-compose pull
docker-compose build --build-arg __BUST_CACHE="$(date)" server
} }
function action__enter { function action__enter {

View File

@ -1,25 +1,42 @@
FROM elixir:1.6-alpine FROM elixir:1.6-alpine
WORKDIR /pleroma env MIX_HOME /mix
env MIX_ARCHIVES /mix-archives
# Prepare system # Prepare system
RUN apk add --no-cache --virtual .build alpine-sdk git rsync RUN apk add --no-cache --virtual .build alpine-sdk git rsync
# Perform a clone that can be cached # Perform a clone that can be cached
RUN git clone https://git.pleroma.social/pleroma/pleroma.git . WORKDIR /pleroma
RUN git clone --progress https://git.pleroma.social/pleroma/pleroma.git .
# Prepare pleroma # Bust the cache with a build arg
ADD ./docker-config.exs /docker-config.exs # that is different on every build
ARG __BUST_CACHE
ENV __BUST_CACHE $__BUST_CACHE
# Update pleroma
ARG PLEROMA_VERSION ARG PLEROMA_VERSION
RUN \ RUN \
git checkout $PLEROMA_VERSION && \ git checkout $PLEROMA_VERSION && \
git pull --rebase --autostash && \ git pull --rebase --autostash
# Inject config
ADD ./docker-config.exs /docker-config.exs
RUN \
ln -s /docker-config.exs config/prod.secret.exs && \ ln -s /docker-config.exs config/prod.secret.exs && \
ln -s /docker-config.exs config/dev.secret.exs ln -s /docker-config.exs config/dev.secret.exs
# Correct paths
WORKDIR /
VOLUME /custom.d
# Register entrypoint # Register entrypoint
ADD ./entrypoint.ash / ADD ./entrypoint.ash /
RUN chmod +x /entrypoint.ash RUN chmod +x /entrypoint.ash
CMD ["/entrypoint.ash"] CMD ["/entrypoint.ash"]
# Call entrypoint to precompile pleroma
RUN /entrypoint.ash onbuild
EXPOSE 4000 EXPOSE 4000