diff --git a/Makefile b/Makefile index ced36a1cb621..59f82cbb4fb4 100644 --- a/Makefile +++ b/Makefile @@ -285,7 +285,7 @@ satellite-wasm: scripts/build-wasm.sh ;\ .PHONY: images -images: multinode-image satellite-image uplink-image versioncontrol-image ## Build multinode, satellite and versioncontrol Docker images +images: multinode-image satellite-image uplink-image versioncontrol-image storagenode-image## Build multinode, satellite and versioncontrol Docker images echo Built version: ${TAG} .PHONY: multinode-image @@ -310,6 +310,13 @@ uplink-image: uplink_linux_arm uplink_linux_arm64 uplink_linux_amd64 ## Build up --build-arg=GOARCH=arm64 --build-arg=DOCKER_ARCH=arm64v8 \ -f cmd/uplink/Dockerfile . +# THIS IS NOT THE PRODUCTION STORAGENODE!!! Only for testing. +# See https://github.com/storj/storagenode-docker for the prod image. +.PHONY: storagenode-image +storagenode-image: storagenode_linux_amd64 identity_linux_amd64 + ${DOCKER_BUILD} --pull=true -t img.dev.storj.io/dev/storagenode:${TAG}${CUSTOMTAG}-amd64 \ + -f cmd/storagenode/Dockerfile.dev . + .PHONY: satellite-image satellite-image: satellite_linux_arm satellite_linux_arm64 satellite_linux_amd64 ## Build satellite Docker image ${DOCKER_BUILD} --pull=true -t storjlabs/satellite:${TAG}${CUSTOMTAG}-amd64 \ @@ -439,6 +446,7 @@ push-images: ## Push Docker images to Docker Hub (jenkins) && docker manifest push --purge storjlabs/$$c:$$t \ ; done \ ; done + docker push img.dev.storj.io/dev/storagenode:${TAG}${CUSTOMTAG}-amd64 .PHONY: binaries-upload binaries-upload: ## Upload binaries to Google Storage (jenkins) @@ -475,6 +483,7 @@ clean-images: -docker rmi storjlabs/multinode:${TAG}${CUSTOMTAG} -docker rmi storjlabs/satellite:${TAG}${CUSTOMTAG} -docker rmi storjlabs/versioncontrol:${TAG}${CUSTOMTAG} + -docker rmi img.dev.storj.io/dev/storagenode:${TAG}${CUSTOMTAG}-amd64 ##@ Tooling diff --git a/cmd/storagenode/Dockerfile.dev b/cmd/storagenode/Dockerfile.dev new file mode 100644 index 000000000000..d487b9a74993 --- /dev/null +++ b/cmd/storagenode/Dockerfile.dev @@ -0,0 +1,39 @@ +ARG DOCKER_ARCH +ARG GO_VERSION=1.21 +# Storagenode UI static asset generation +FROM node:18.17.0 as ui +WORKDIR /app +COPY web/storagenode/ /app +RUN ./build.sh + +# Fetch ca-certificates file for arch independent builds below +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:$GO_VERSION AS storjup +RUN --mount=type=cache,target=/root/.cache/go-build \ + --mount=type=cache,target=/go/pkg/mod \ + CGO_ENABLED=0 go install storj.io/storj-up@latest + +# Install dlv (for local/dev runs) +FROM --platform=$TARGETPLATFORM golang:$GO_VERSION 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 PATH=$PATH:/app +WORKDIR /app +COPY --from=ui /app/static /app/static +COPY --from=ca-cert /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt +COPY release/${TAG}/storagenode_linux_${GOARCH:-amd64} /app/storagenode +COPY release/${TAG}/identity_linux_${GOARCH:-amd64} /app/identity +COPY --from=storjup /go/bin/storj-up /usr/local/bin/storj-up +COPY --from=dlv /go/bin/dlv /usr/local/bin/dlv +COPY cmd/storagenode/entrypoint /entrypoint +ENTRYPOINT ["/entrypoint"] diff --git a/cmd/storagenode/entrypoint b/cmd/storagenode/entrypoint new file mode 100755 index 000000000000..234cca7faf2c --- /dev/null +++ b/cmd/storagenode/entrypoint @@ -0,0 +1,42 @@ +#!/bin/bash +set -euo pipefail + +if [ "${STORJ_IDENTITY_DIR:-""}" ]; then + #Generate identity if missing + if [ ! -f "$STORJ_IDENTITY_DIR/identity.key" ]; then + identity --identity-dir $STORJ_IDENTITY_DIR --difficulty 0 create . + fi +fi + +if [ "${STORJ_NODE_IP:-""}" ]; then + #Initialize config, required only to have all the dirs created + : ${STORJ_CONTACT_EXTERNAL_ADDRESS:=$STORJ_NODE_IP:28967} +fi + +if [ "${STORJ_STORAGENODE_CONSOLE_STATIC_DIR:-}" ]; then +#This is a workaround to set different static dir for statellite/storagenode with env variables. + : ${STORJ_CONSOLE_STATIC_DIR:=$STORJ_STORAGENODE_CONSOLE_STATIC_DIR} +fi + +if [ "${STORJUP_ROLE:-""}" ]; then + if [ "$STORJ_WAIT_FOR_SATELLITE" ]; then + SATELLITE_ADDRESS=$(storj-up util wait-for-satellite satellite-api:7777) + fi + # storj-up uses environment variables, k8s may not have privileges to delete this + if [ -f "/var/lib/storj/.local/share/storj/storagenode/config.yaml" ]; then + rm "/var/lib/storj/.local/share/storj/storagenode/config.yaml" + fi + storagenode --identity-dir $STORJ_IDENTITY_DIR setup || true +fi + +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 + +exec "$@"