Skip to content

Commit

Permalink
storjscan.Dockerfile: Add storjscan dockerfile for remote builds
Browse files Browse the repository at this point in the history
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
  • Loading branch information
dlamarmorgan committed Sep 24, 2022
1 parent bb54824 commit ad9e370
Show file tree
Hide file tree
Showing 7 changed files with 89 additions and 25 deletions.
5 changes: 5 additions & 0 deletions cmd/files/docker/embedded.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
27 changes: 27 additions & 0 deletions cmd/files/docker/storjscan.Dockerfile
Original file line number Diff line number Diff line change
@@ -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
7 changes: 7 additions & 0 deletions cmd/files/templates/docker-compose.template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 4 additions & 11 deletions cmd/remote.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
5 changes: 3 additions & 2 deletions pkg/common/key_string.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion pkg/common/presets.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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{
Expand All @@ -89,6 +91,7 @@ var serviceNameHelper = map[string]string{
"appbaseubuntu": "app-base-ubuntu",
"appedge": "app-edge",
"appstorj": "app-storj",
"appstorjscan": "app-storjscan",
}

const (
Expand All @@ -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).
Expand All @@ -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<<service) != 0 {
result = append(result, serviceNameHelper[service.String()])
}
Expand Down
49 changes: 38 additions & 11 deletions pkg/common/servicefiles.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,44 +9,56 @@ import (
"os"
"path/filepath"

dockefiles "storj.io/storj-up/cmd/files/docker"
"storj.io/storj-up/cmd/files/templates"
)

// ConfigFiles is a type with an embedded FS and a folder.
// ConfigFiles is a type with an embedded FS and a folder for directories,
// and a file and filename for single embedded files.
type ConfigFiles struct {
fs embed.FS
folder string
file []byte
filename string
fs embed.FS
folder string
}

// AddFiles extract the config files associated with the provided service.
func AddFiles(service string) error {
configFS := ResolveEmbeds(service)
for _, configDir := range configFS {
err := recurseFileExtract(configDir)
if err != nil {
return err
if configDir.fs != (embed.FS{}) {
err := recurseFileExtract(configDir.fs, configDir.folder)
if err != nil {
return err
}
}
if configDir.file != nil {
err := ExtractFile("", configDir.filename, configDir.file)
if err != nil {
return err
}
}
}
return nil
}

func recurseFileExtract(configFiles ConfigFiles) error {
entries, err := configFiles.fs.ReadDir(configFiles.folder)
func recurseFileExtract(fs embed.FS, folder string) error {
entries, err := fs.ReadDir(folder)
if err != nil {
return err
}
for _, entry := range entries {
if entry.IsDir() {
err = recurseFileExtract(ConfigFiles{configFiles.fs, configFiles.folder + "/" + entry.Name()})
err = recurseFileExtract(fs, folder+"/"+entry.Name())
if err != nil {
return err
}
} else {
fileContent, err := configFiles.fs.ReadFile(configFiles.folder + "/" + entry.Name())
fileContent, err := fs.ReadFile(folder + "/" + entry.Name())
if err != nil {
return err
}
err = ExtractFile(configFiles.folder, entry.Name(), fileContent)
err = ExtractFile(folder, entry.Name(), fileContent)
if err != nil {
return err
}
Expand Down Expand Up @@ -87,6 +99,21 @@ func ResolveEmbeds(service string) []ConfigFiles {
fs: templates.PrometheusYaml,
folder: "prometheus",
}}
case "app-edge":
return []ConfigFiles{{
file: dockefiles.EdgeDocker,
filename: "edge.Dockerfile",
}}
case "app-storj":
return []ConfigFiles{{
file: dockefiles.StorjDocker,
filename: "storj.Dockerfile",
}}
case "app-storjscan":
return []ConfigFiles{{
file: dockefiles.StorjscanDocker,
filename: "storjscan.Dockerfile",
}}
default:
return nil
}
Expand Down

0 comments on commit ad9e370

Please sign in to comment.