diff --git a/cmd/satellite/Dockerfile b/cmd/satellite/Dockerfile index e8db83052..a450c45de 100644 --- a/cmd/satellite/Dockerfile +++ b/cmd/satellite/Dockerfile @@ -12,13 +12,27 @@ FROM debian:buster-slim as ca-cert RUN apt-get update && apt-get install -y --no-install-recommends ca-certificates RUN update-ca-certificates +# Install storj-up helper (for local/dev runs) +FROM --platform=$TARGETPLATFORM golang:1.19 AS storjup +RUN --mount=type=cache,target=/root/.cache/go-build \ + --mount=type=cache,target=/go/pkg/mod \ + go install storj.io/storj-up@latest + +# Install dlv (for local/dev runs) +FROM --platform=$TARGETPLATFORM golang:1.19 AS dlv +RUN --mount=type=cache,target=/root/.cache/go-build \ + --mount=type=cache,target=/go/pkg/mod \ + go install github.com/go-delve/delve/cmd/dlv@latest + FROM ${DOCKER_ARCH:-amd64}/debian:buster-slim ARG TAG ARG GOARCH ENV GOARCH ${GOARCH} ENV CONF_PATH=/root/.local/share/storj/satellite \ STORJ_CONSOLE_STATIC_DIR=/app \ + STORJ_MAIL_TEMPLATE_PATH=/app/static/emails \ STORJ_CONSOLE_ADDRESS=0.0.0.0:10100 +ENV PATH=$PATH:/app EXPOSE 7777 EXPOSE 10100 WORKDIR /app @@ -30,5 +44,9 @@ COPY release/${TAG}/wasm/wasm_exec.js /app/static/wasm/ COPY release/${TAG}/wasm/access.wasm.br /app/static/wasm/ COPY release/${TAG}/wasm/wasm_exec.js.br /app/static/wasm/ COPY release/${TAG}/satellite_linux_${GOARCH:-amd64} /app/satellite +COPY --from=storjup /go/bin/storj-up /usr/local/bin/storj-up +COPY --from=dlv /go/bin/dlv /usr/local/bin/dlv +# test identities for quick-start +COPY --from=img.dev.storj.io/storjup/base:20230607-1 /var/lib/storj/identities /var/lib/storj/identities COPY cmd/satellite/entrypoint /entrypoint ENTRYPOINT ["/entrypoint"] diff --git a/cmd/satellite/entrypoint b/cmd/satellite/entrypoint index f9af188da..141537880 100755 --- a/cmd/satellite/entrypoint +++ b/cmd/satellite/entrypoint @@ -1,6 +1,7 @@ #!/bin/bash set -euo pipefail +## production helpers SETUP_PARAMS="" if [ -n "${IDENTITY_ADDR:-}" ]; then @@ -21,6 +22,10 @@ if [ "${SATELLITE_API:-}" = "true" ]; then exec ./satellite run api $RUN_PARAMS "$@" fi +if [ "${SATELLITE_UI:-}" = "true" ]; then + exec ./satellite run ui $RUN_PARAMS "$@" +fi + if [ "${SATELLITE_GC:-}" = "true" ]; then exec ./satellite run garbage-collection $RUN_PARAMS "$@" fi @@ -37,4 +42,63 @@ if [ "${SATELLITE_AUDITOR:-}" = "true" ]; then exec ./satellite run auditor $RUN_PARAMS "$@" fi -exec ./satellite run $RUN_PARAMS "$@" +## storj-up helpers +if [ "${STORJUP_ROLE:-""}" ]; then + + if [ "${STORJ_IDENTITY_DIR:-""}" ]; then + #Generate identity if missing + if [ ! -f "$STORJ_IDENTITY_DIR/identity.key" ]; then + if [ "$STORJ_USE_PREDEFINED_IDENTITY" ]; then + # use predictable, pre-generated identity + mkdir -p $(dirname $STORJ_IDENTITY_DIR) + cp -r /var/lib/storj/identities/$STORJ_USE_PREDEFINED_IDENTITY $STORJ_IDENTITY_DIR + else + identity --identity-dir $STORJ_IDENTITY_DIR --difficulty 8 create . + fi + fi + fi + + if [ "${STORJ_WAIT_FOR_DB:-""}" ]; then + storj-up util wait-for-port cockroach:26257 + storj-up util wait-for-port redis:6379 + fi + + if [ "${STORJUP_ROLE:-""}" == "satellite-api" ]; then + mkdir -p /var/lib/storj/.local + + #only migrate first time + if [ ! -f "/var/lib/storj/.local/migrated" ]; then + satellite run migration --identity-dir $STORJ_IDENTITY_DIR + touch /var/lib/storj/.local/migrated + fi + fi + + # default config generated without arguments is misleading + rm /root/.local/share/storj/satellite/config.yaml + + mkdir -p /var/lib/storj/.local/share/storj/satellite || true + + if [ "${GO_DLV:-""}" ]; then + echo "Starting with go dlv" + + #absolute file path is required + CMD=$(which $1) + shift + /usr/local/bin/dlv --listen=:2345 --headless=true --api-version=2 --accept-multiclient exec --check-go-version=false -- $CMD "$@" + exit $? + fi +fi + +# for backward compatibility reason, we use argument as command, only if it's an executable (and use it as satellite flags oterwise) +set +e +which "$1" > /dev/null +VALID_EXECUTABLE=$? +set -e + +if [ $VALID_EXECUTABLE -eq 0 ]; then + # this is a full command (what storj-up uses) + exec "$@" +else + # legacy, run-only parameters + exec ./satellite run $RUN_PARAMS "$@" +fi