Skip to content

Commit

Permalink
cmd/storagenode: development Docker images for testing
Browse files Browse the repository at this point in the history
This patch restores the Storagenode Docker image for development purposes.

This is not replacement of the Storagenode image of the end users (https://github.com/storj/storagenode-docker).

To avoid confusions, it's NOT pushed to Docker Registry, only to the development registry (img.dev.storj.io).

Image supposed to be compatible with all environments (storj-up, Kubernetes environments, ...),
but not public network (helper environment variables are intentionally missing).

Change-Id: I15d23d61c74b23bc6589351996c244d36408a699
  • Loading branch information
elek authored and Storj Robot committed Jan 2, 2024
1 parent cb6fb07 commit acf648c
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 1 deletion.
11 changes: 10 additions & 1 deletion Makefile
Expand Up @@ -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
Expand All @@ -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 \
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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

Expand Down
39 changes: 39 additions & 0 deletions 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"]
42 changes: 42 additions & 0 deletions 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 "$@"

0 comments on commit acf648c

Please sign in to comment.