Skip to content

Commit

Permalink
Merge pull request #91 from pondersource/reva-docker-image
Browse files Browse the repository at this point in the history
[OCM][Test Suite][CI] Smaller Reva Image
  • Loading branch information
MahdiBaghbani authored Mar 20, 2024
2 parents 2e04606 + 1673dab commit 31f4ea7
Show file tree
Hide file tree
Showing 9 changed files with 70 additions and 75 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

bin/
ocm
reva/
.reva/
core
temp
server
Expand Down
13 changes: 7 additions & 6 deletions dev/ocm-test-suite.sh
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,9 @@ function createReva() {
redirect_to_null_cmd echo "creating reva for ${platform} ${number}"

# make sure scripts are executable.
chmod +x "${ENV_ROOT}/docker/scripts/reva-run.sh" >/dev/null 2>&1
chmod +x "${ENV_ROOT}/docker/scripts/reva-kill.sh" >/dev/null 2>&1
chmod +x "${ENV_ROOT}/docker/scripts/reva-entrypoint.sh" >/dev/null 2>&1
chmod +x "${ENV_ROOT}/temp/reva/run.sh" >/dev/null 2>&1
chmod +x "${ENV_ROOT}/temp/reva/kill.sh" >/dev/null 2>&1
chmod +x "${ENV_ROOT}/temp/reva/entrypoint.sh" >/dev/null 2>&1

if [ "${SCRIPT_MODE}" = "dev" ]; then
waitForCollabora
Expand All @@ -136,9 +136,9 @@ function createReva() {
-v "${ENV_ROOT}/docker/tls/certificates:/certificates" \
-v "${ENV_ROOT}/docker/tls/certificate-authority:/certificate-authority" \
-v "${ENV_ROOT}/temp/revad:/configs/revad" \
-v "${ENV_ROOT}/docker/scripts/reva-run.sh:/usr/bin/reva-run.sh" \
-v "${ENV_ROOT}/docker/scripts/reva-kill.sh:/usr/bin/reva-kill.sh" \
-v "${ENV_ROOT}/docker/scripts/reva-entrypoint.sh:/entrypoint.sh" \
-v "${ENV_ROOT}/temp/reva/run.sh:/usr/bin/run.sh" \
-v "${ENV_ROOT}/temp/reva/kill.sh:/usr/bin/kill.sh" \
-v "${ENV_ROOT}/temp/reva/entrypoint.sh:/usr/bin/entrypoint.sh" \
pondersource/dev-stock-revad \
>/dev/null 2>&1
}
Expand All @@ -161,6 +161,7 @@ function sciencemeshInsertIntoDB() {
rm -rf "${ENV_ROOT}/temp" && mkdir --parents "${ENV_ROOT}/temp"

# copy init files.
cp -fr "${ENV_ROOT}/docker/scripts/reva" "${ENV_ROOT}/temp/"
cp -fr "${ENV_ROOT}/docker/configs/revad" "${ENV_ROOT}/temp/"
cp -f "${ENV_ROOT}/docker/scripts/ocmstub/index.js" "${ENV_ROOT}/temp/index.js"
cp -f "${ENV_ROOT}/docker/scripts/init-owncloud-sm-ocm.sh" "${ENV_ROOT}/temp/owncloud.sh"
Expand Down
13 changes: 7 additions & 6 deletions dev/sciencemesh.sh
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,9 @@ function createReva() {
echo "creating reva for ${platform} ${number}"

# make sure scripts are executable.
chmod +x "${ENV_ROOT}/docker/scripts/reva-run.sh" >/dev/null 2>&1
chmod +x "${ENV_ROOT}/docker/scripts/reva-kill.sh" >/dev/null 2>&1
chmod +x "${ENV_ROOT}/docker/scripts/reva-entrypoint.sh" >/dev/null 2>&1
chmod +x "${ENV_ROOT}/temp/reva/run.sh" >/dev/null 2>&1
chmod +x "${ENV_ROOT}/temp/reva/kill.sh" >/dev/null 2>&1
chmod +x "${ENV_ROOT}/temp/reva/entrypoint.sh" >/dev/null 2>&1

waitForCollabora

Expand All @@ -119,9 +119,9 @@ function createReva() {
-v "${ENV_ROOT}/docker/tls/certificates:/certificates" \
-v "${ENV_ROOT}/docker/tls/certificate-authority:/certificate-authority" \
-v "${ENV_ROOT}/temp/revad:/configs/revad" \
-v "${ENV_ROOT}/docker/scripts/reva-run.sh:/usr/bin/reva-run.sh" \
-v "${ENV_ROOT}/docker/scripts/reva-kill.sh:/usr/bin/reva-kill.sh" \
-v "${ENV_ROOT}/docker/scripts/reva-entrypoint.sh:/entrypoint.sh" \
-v "${ENV_ROOT}/temp/reva/run.sh:/usr/bin/run.sh" \
-v "${ENV_ROOT}/temp/reva/kill.sh:/usr/bin/kill.sh" \
-v "${ENV_ROOT}/temp/reva/entrypoint.sh:/usr/bin/entrypoint.sh" \
pondersource/dev-stock-revad \
>/dev/null 2>&1
}
Expand All @@ -144,6 +144,7 @@ function sciencemeshInsertIntoDB() {
rm -rf "${ENV_ROOT}/temp" && mkdir --parents "${ENV_ROOT}/temp"

# copy init files.
cp -fr "${ENV_ROOT}/docker/scripts/reva" "${ENV_ROOT}/temp/"
cp -fr "${ENV_ROOT}/docker/configs/revad" "${ENV_ROOT}/temp/"
cp -f "${ENV_ROOT}/docker/scripts/ocmstub/index.js" "${ENV_ROOT}/temp/index.js"
cp -f "${ENV_ROOT}/docker/scripts/init-owncloud-sciencemesh.sh" "${ENV_ROOT}/temp/owncloud.sh"
Expand Down
77 changes: 35 additions & 42 deletions docker/dockerfiles/revad.Dockerfile
Original file line number Diff line number Diff line change
@@ -1,29 +1,8 @@
FROM golang:1.22.1-bookworm
# stage 1: build stage
FROM golang:1.22.1-alpine AS build

# keys for oci taken from:
# https://github.com/opencontainers/image-spec/blob/main/annotations.md#pre-defined-annotation-keys
LABEL org.opencontainers.image.licenses=MIT
LABEL org.opencontainers.image.title="Pondersource Revad Image"
LABEL org.opencontainers.image.source="https://github.com/pondersource/dev-stock"
LABEL org.opencontainers.image.authors="Mohammad Mahdi Baghbani Pourvahid"

# set timezone.
ENV TZ=UTC
RUN ln --symbolic --no-dereference --force /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone

ENV DEBIAN_FRONTEND noninteractive

RUN apt update --yes

# install dependencies.
RUN apt install --yes \
git \
vim \
curl \
wget \
openssl \
build-essential \
ca-certificates
# install build dependencies.
RUN apk --no-cache add git make bash

# go to root directory.
WORKDIR /
Expand All @@ -41,38 +20,52 @@ RUN git clone \
${REPO_REVA} \
reva-git

# change directory to reva
# change directory to reva git.
WORKDIR /reva-git

# build revad from source.
RUN go mod vendor
# copy and download dependencies.
RUN go mod download

# only build revad, leave out reva and test and lint and docs.
RUN make revad

COPY ./configs/revad /configs/revad
WORKDIR /configs/revad
# stage 2: app image.
FROM alpine:3.19.1

# keys for oci taken from:
# https://github.com/opencontainers/image-spec/blob/main/annotations.md#pre-defined-annotation-keys
LABEL org.opencontainers.image.licenses=MIT
LABEL org.opencontainers.image.title="Pondersource Revad Image"
LABEL org.opencontainers.image.source="https://github.com/pondersource/dev-stock"
LABEL org.opencontainers.image.authors="Mohammad Mahdi Baghbani Pourvahid"

# set the timezone and install CA certificates.
RUN apk --no-cache add bash ca-certificates tzdata

ENV TZ=Etc/UTC

# copy the binary from the build stage.
COPY --from=build /reva-git/cmd /reva-git/cmd

# copy the reva config files from host.
COPY ./configs/revad /configs/revad

# trust all the certificates:
COPY ./tls/certificates/* /tls/
COPY ./tls/certificates/reva* /tls/
COPY ./tls/certificate-authority/* /tls/
RUN ln --symbolic --force /tls/*.crt /usr/local/share/ca-certificates
RUN ln -sf /tls/*.crt /usr/local/share/ca-certificates
RUN update-ca-certificates

RUN mkdir -p /var/tmp/reva/

# update path to include revad bin directory.
ENV PATH="${PATH}:/reva/cmd/revad"

COPY ./scripts/reva-run.sh /usr/bin/reva-run.sh
RUN chmod +x /usr/bin/reva-run.sh

COPY ./scripts/reva-kill.sh /usr/bin/reva-kill.sh
RUN chmod +x /usr/bin/reva-kill.sh
COPY ./scripts/reva/* /usr/bin/

COPY ./scripts/reva-entrypoint.sh /entrypoint.sh
RUN chmod +x /entrypoint.sh
RUN chmod +x /usr/bin/run.sh && chmod +x /usr/bin/kill.sh && chmod +x /usr/bin/entrypoint.sh

ENTRYPOINT ["/entrypoint.sh"]
ENTRYPOINT ["/usr/bin/entrypoint.sh"]

# Keep Docker Container Running for Debugging.
CMD tail --follow /var/log/revad.log
# keep Docker Container Running for Debugging.
CMD tail -F /var/log/revad.log
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env bash

# @michielbdejong halt on error in docker init scripts
# @michielbdejong halt on error in docker init scripts.
set -e

# see https://github.com/golang/go/issues/22846#issuecomment-380809416
Expand All @@ -11,7 +11,7 @@ echo "127.0.0.1 ${HOST}.docker" >> /etc/hosts
touch /var/log/revad.log

# run revad.
reva-run.sh
run.sh

# This will exec the CMD from your Dockerfile, i.e. "npm start"
exec "$@"
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env bash

# @michielbdejong halt on error in docker init scripts
# @michielbdejong halt on error in docker init scripts.
set -e

# kill running revad.
Expand Down
26 changes: 13 additions & 13 deletions docker/scripts/reva-run.sh → docker/scripts/reva/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ fi
if [ -n "$(find /reva -prune -empty -type d 2>/dev/null)" ]; then
echo "/reva is an empty directory, populating it with reva binaries."
# populate /reva with Reva binaries.
cp --archive --recursive --no-clobber /reva-git/cmd /reva
cp -ar /reva-git/cmd /reva
else
ls -l --all --size /reva
ls -lsa /reva
echo "/reva contains files, doing noting."
fi

Expand All @@ -40,21 +40,21 @@ sed -i "s/debug/trace/"
# update OS certificate store.
mkdir -p /tls

[ -d "/certificates" ] && \
cp -f /certificates/*.crt /tls/ \
&& \
cp -f /certificates/*.key /tls/
[ -d "/certificates" ] && \
cp -f /certificates/*.crt /tls/ \
&& \
cp -f /certificates/*.key /tls/

[ -d "/certificate-authority" ] && \
cp -f /certificate-authority/*.crt /tls/ \
&& \
cp -f /certificate-authority/*.key /tls/
[ -d "/certificate-authority" ] && \
cp -f /certificate-authority/*.crt /tls/ \
&& \
cp -f /certificate-authority/*.key /tls/

cp -f /tls/*.crt /usr/local/share/ca-certificates/ || true
cp -f /tls/*.crt /usr/local/share/ca-certificates/ || true
update-ca-certificates

ln --symbolic --force "/tls/${HOST}.crt" /tls/server.crt
ln --symbolic --force "/tls/${HOST}.key" /tls/server.key
ln -sf "/tls/${HOST}.crt" /tls/server.crt
ln -sf "/tls/${HOST}.key" /tls/server.key

# run revad.
revad --dev-dir "/etc/revad" &
4 changes: 2 additions & 2 deletions init/ocm-test-suite.sh
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ if [ "${SCRIPT_MODE}" = "dev" ]; then
docker run --rm \
-v "$(pwd)/reva:/reva-build" \
--workdir /reva-build \
golang:1.22.1-bookworm \
bash -c "git config --global --add safe.directory /reva-build && go mod vendor && make revad"
golang:1.22.1-alpine \
sh -c "apk --no-cache add git make bash && git config --global --add safe.directory /reva-build && go mod download && make revad"
else
[ ! -d "nextcloud/apps" ] && \
mkdir -p nextcloud/apps
Expand Down
4 changes: 2 additions & 2 deletions init/sciencemesh.sh
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,8 @@ BRANCH_REVA=v1.28.0
docker run -it --rm \
-v "$(pwd)/reva:/reva-build" \
--workdir /reva-build \
golang:1.22.1-bookworm \
bash -c "git config --global --add safe.directory /reva-build && go mod vendor && make revad"
golang:1.22.1-alpine \
sh -c "apk --no-cache add git make bash && git config --global --add safe.directory /reva-build && go mod download && make revad"

docker network inspect testnet >/dev/null 2>&1 || docker network create testnet

Expand Down

0 comments on commit 31f4ea7

Please sign in to comment.