From ad9e3706ece62bea3a482c9852f86ed319e565f4 Mon Sep 17 00:00:00 2001 From: dlamarmorgan Date: Fri, 23 Sep 2022 14:14:33 -0700 Subject: [PATCH] storjscan.Dockerfile: Add storjscan dockerfile for remote builds Add the required dockerfile to allow for remote builds of the storjscan service via github and/or gerrit. Also some slight updates to the remote command to use the addfiles function to grab the appropriate dockerfile for the service to build instead of always extracting all dockerfiles. Change-Id: I2543a57abb095a289c4d9de28d74016d9cf6db14 --- cmd/files/docker/embedded.go | 5 ++ cmd/files/docker/storjscan.Dockerfile | 27 ++++++++++ .../templates/docker-compose.template.yaml | 7 +++ cmd/remote.go | 15 ++---- pkg/common/key_string.go | 5 +- pkg/common/presets.go | 6 ++- pkg/common/servicefiles.go | 49 ++++++++++++++----- 7 files changed, 89 insertions(+), 25 deletions(-) create mode 100644 cmd/files/docker/storjscan.Dockerfile diff --git a/cmd/files/docker/embedded.go b/cmd/files/docker/embedded.go index d44d23f..8658f33 100644 --- a/cmd/files/docker/embedded.go +++ b/cmd/files/docker/embedded.go @@ -14,3 +14,8 @@ var StorjDocker []byte // //go:embed edge.Dockerfile var EdgeDocker []byte + +// StorjscanDocker is a Dockerfile for the storjscan service. +// +//go:embed storjscan.Dockerfile +var StorjscanDocker []byte diff --git a/cmd/files/docker/storjscan.Dockerfile b/cmd/files/docker/storjscan.Dockerfile new file mode 100644 index 0000000..7ae1e76 --- /dev/null +++ b/cmd/files/docker/storjscan.Dockerfile @@ -0,0 +1,27 @@ +# syntax=docker/dockerfile:1.3 +ARG TYPE +FROM --platform=$TARGETPLATFORM img.dev.storj.io/storjup/build:20220803-2 AS base + +FROM base AS github +ARG BRANCH +RUN git clone --depth=1 https://github.com/storj/storjscan.git --branch ${BRANCH} +WORKDIR storjscan + +FROM base AS gerrit +ARG REF +RUN git clone https://github.com/storj/storjscan.git +WORKDIR storjscan +RUN git fetch https://review.dev.storj.io/storj/storjscan ${REF} && git checkout FETCH_HEAD + +FROM --platform=$TARGETPLATFORM ${TYPE} AS binaries +RUN --mount=type=cache,target=/var/lib/storj/go/pkg/mod,mode=777,uid=1000 \ + --mount=type=cache,target=/var/lib/storj/.cache/go-build,mode=777,uid=1000 \ + go install ./cmd/... + +FROM img.dev.storj.io/storjup/base:20220901-3 AS final + +COPY --from=binaries /var/lib/storj/go/bin /var/lib/storj/go/bin +COPY --from=binaries --chown=storj /var/lib/storj/entrypoint.sh /var/lib/storj/entrypoint.sh + +ENTRYPOINT ["/var/lib/storj/entrypoint.sh"] +ENV PATH=$PATH:/var/lib/storj/go/bin \ No newline at end of file diff --git a/cmd/files/templates/docker-compose.template.yaml b/cmd/files/templates/docker-compose.template.yaml index 7ad3856..80fe157 100644 --- a/cmd/files/templates/docker-compose.template.yaml +++ b/cmd/files/templates/docker-compose.template.yaml @@ -14,6 +14,13 @@ services: image: storj networks: default: null + app-storjscan: + build: + context: . + dockerfile: storjscan.Dockerfile + image: storjscan + networks: + default: null authservice: command: - authservice diff --git a/cmd/remote.go b/cmd/remote.go index 3ceb6ab..3943da6 100644 --- a/cmd/remote.go +++ b/cmd/remote.go @@ -9,7 +9,6 @@ import ( "github.com/spf13/cobra" "github.com/zeebo/errs/v2" - "storj.io/storj-up/cmd/files/docker" "storj.io/storj-up/cmd/files/templates" "storj.io/storj-up/pkg/common" ) @@ -81,16 +80,6 @@ func init() { } func updateCompose(services []string, remoteType string) error { - err := common.ExtractFile("", "storj.Dockerfile", dockerfiles.StorjDocker) - if err != nil { - return err - } - - err = common.ExtractFile("", "edge.Dockerfile", dockerfiles.EdgeDocker) - if err != nil { - return err - } - composeProject, err := common.LoadComposeFromFile(common.ComposeFileName) if err != nil { return err @@ -148,6 +137,10 @@ func updateCompose(services []string, remoteType string) error { return errs.Wrap(err) } } + err = common.AddFiles(service) + if err != nil { + return errs.Wrap(err) + } } } return common.WriteComposeFile(composeProject) diff --git a/pkg/common/key_string.go b/pkg/common/key_string.go index ee2e854..fff5b7f 100644 --- a/pkg/common/key_string.go +++ b/pkg/common/key_string.go @@ -27,11 +27,12 @@ func _() { _ = x[appbaseubuntu-16] _ = x[appedge-17] _ = x[appstorj-18] + _ = x[appstorjscan-19] } -const _Key_name = "authservicecockroachgatewaymtlinksharingredissatelliteadminsatelliteapisatellitecorestoragenodeuplinkversioncontrolstorjscangethprometheusgrafanaappbasedevappbaseubuntuappedgeappstorj" +const _Key_name = "authservicecockroachgatewaymtlinksharingredissatelliteadminsatelliteapisatellitecorestoragenodeuplinkversioncontrolstorjscangethprometheusgrafanaappbasedevappbaseubuntuappedgeappstorjappstorjscan" -var _Key_index = [...]uint8{0, 11, 20, 29, 40, 45, 59, 71, 84, 95, 101, 115, 124, 128, 138, 145, 155, 168, 175, 183} +var _Key_index = [...]uint8{0, 11, 20, 29, 40, 45, 59, 71, 84, 95, 101, 115, 124, 128, 138, 145, 155, 168, 175, 183, 195} func (i Key) String() string { if i >= Key(len(_Key_index)-1) { diff --git a/pkg/common/presets.go b/pkg/common/presets.go index fe5eb0d..754f31f 100644 --- a/pkg/common/presets.go +++ b/pkg/common/presets.go @@ -33,6 +33,7 @@ var ServiceDict = map[string]uint{ "app-base-ubuntu": 65536, "app-edge": 131072, "app-storj": 262144, + "app-storjscan": 524288, "minimal": 64 + 256, "edge": 1 + 4 + 8, "db": 2 + 16, @@ -67,6 +68,7 @@ var BuildDict = map[string]string{ "storagenode": "app-storj", "uplink": "app-storj", "versioncontrol": "app-storj", + "storjscan": "app-storjscan", } var serviceNameHelper = map[string]string{ @@ -89,6 +91,7 @@ var serviceNameHelper = map[string]string{ "appbaseubuntu": "app-base-ubuntu", "appedge": "app-edge", "appstorj": "app-storj", + "appstorjscan": "app-storjscan", } const ( @@ -111,6 +114,7 @@ const ( appbaseubuntu // 65536 appedge // 131072 appstorj // 262144 + appstorjscan // 524288 ) // ResolveBuilds returns with the required docker images to build (as keys in the maps). @@ -137,7 +141,7 @@ func ResolveServices(services []string) ([]string, error) { } key |= value } - for service := authservice; service <= appstorj; service++ { + for service := authservice; service <= appstorjscan; service++ { if key&(1<