Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 0 additions & 52 deletions .evg.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,6 @@ functions:
set -e
wget --quiet ${go_url}
tar xvf ./go1*gz
"fetch_yarn":
- command: shell.exec
params:
shell: "bash"
script: |
set -e
curl --silent -OL ${yarn_url}
tar zvxf latest.tar.gz
mv yarn-* yarn
"fetch_baas_artifacts": &fetch_baas_artifacts
- command: shell.exec
params:
Expand Down Expand Up @@ -55,14 +46,6 @@ functions:
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
nvm install ${node_version}
nvm use ${node_version}
"setup_transpiler":
command: shell.exec
params:
shell: "bash"
script: |
set -e
mkdir -p realm-cli/etc/bin
cp baas_artifacts/transpiler realm-cli/etc/bin
"setup_project":
- command: git.get_project
params:
Expand Down Expand Up @@ -159,10 +142,8 @@ tasks:
exec_timeout_secs: 3600
commands:
- func: "fetch_go114"
- func: "fetch_yarn"
- func: "fetch_baas_artifacts"
- func: "setup_project"
- func: "setup_transpiler"
- command: shell.exec
params:
shell: "bash"
Expand Down Expand Up @@ -190,7 +171,6 @@ tasks:
exec_timeout_secs: 3600
commands:
- func: "fetch_go114"
- func: "fetch_yarn"
- func: "fetch_baas_artifacts"
- func: "setup_node"
- func: "setup_project"
Expand All @@ -205,7 +185,6 @@ tasks:
set -e
export ROOT_DIR=`pwd`
export PATH="$ROOT_DIR:$PATH"
export PATH=$PATH:$ROOT_DIR/realm-cli/etc/transpiler/bin/
export GOROOT=$ROOT_DIR/go
export PATH=$GOROOT/bin:$PATH
export BAAS_NO_SKIP_TEST=1
Expand Down Expand Up @@ -264,9 +243,6 @@ tasks:
export GOROOT=$ROOT_DIR/go
export PATH=$GOROOT/bin:$PATH

mkdir -p realm-cli/etc/transpiler/bin
cp baas_artifacts/transpiler-* realm-cli/etc/transpiler/bin

cd $ROOT_DIR/realm-cli
export VERSION="${version}"
export GOARCH=amd64
Expand Down Expand Up @@ -316,34 +292,6 @@ tasks:
bucket: realm-clis
content_type: application/octet-stream
permissions: public-read
# transpilers
- command: s3.put
params:
aws_key: ${artifacts_aws_key}
aws_secret: ${artifacts_aws_secret}
local_file: realm-cli/etc/transpiler/bin/transpiler-linux-x64
remote_file: ${build_id}/linux-amd64/transpiler
bucket: realm-clis
content_type: application/octet-stream
permissions: public-read
- command: s3.put
params:
aws_key: ${artifacts_aws_key}
aws_secret: ${artifacts_aws_secret}
local_file: realm-cli/etc/transpiler/bin/transpiler-macos-x64
remote_file: ${build_id}/macos-amd64/transpiler
bucket: realm-clis
content_type: application/octet-stream
permissions: public-read
- command: s3.put
params:
aws_key: ${artifacts_aws_key}
aws_secret: ${artifacts_aws_secret}
local_file: realm-cli/etc/transpiler/bin/transpiler-win-x64
remote_file: ${build_id}/windows-amd64/transpiler.exe
bucket: realm-clis
content_type: application/octet-stream
permissions: public-read

post:
- command: gotest.parse_files
Expand Down
27 changes: 5 additions & 22 deletions install.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,30 +8,26 @@ const basedownloadURL = `https://s3.amazonaws.com/realm-clis/${versionMetadata.b
const linuxdownloadURL = `${basedownloadURL}/linux-amd64/realm-cli`;
const macdownloadURL = `${basedownloadURL}/macos-amd64/realm-cli`;
const windowsdownloadURL = `${basedownloadURL}/windows-amd64/realm-cli.exe`;
// transpiler downloads
const linuxTranspilerdownloadURL = `${basedownloadURL}/linux-amd64/transpiler`;
const macTranspilerdownloadURL = `${basedownloadURL}/macos-amd64/transpiler`;
const windowsTranspilerdownloadURL = `${basedownloadURL}/windows-amd64/transpiler.exe`;

function getdownloadURL(cli) {
function getdownloadURL() {
const platform = process.platform;
let downloadURL;

if (platform === 'linux') {
if (process.arch === 'x64') {
downloadURL = cli ? linuxdownloadURL : linuxTranspilerdownloadURL;
downloadURL = linuxdownloadURL;
} else {
throw new Error('Only Linux 64 bits supported.');
}
} else if (platform === 'darwin' || platform === 'freebsd') {
if (process.arch === 'x64' || process.arch === 'arm64') {
downloadURL = cli ? macdownloadURL : macTranspilerdownloadURL;
downloadURL = macdownloadURL;
} else {
throw new Error('Only Mac 64 bits supported.');
}
} else if (platform === 'win32') {
if (process.arch === 'x64') {
downloadURL = cli ? windowsdownloadURL : windowsTranspilerdownloadURL;
downloadURL = windowsdownloadURL;
} else {
throw new Error('Only Windows 64 bits supported.');
}
Expand Down Expand Up @@ -96,7 +92,7 @@ function requstBinary(downloadURL, baseName) {
// Install script starts here
let downloadURL;
try {
downloadURL = getdownloadURL(true);
downloadURL = getdownloadURL();
} catch (err) {
console.error('Realm CLI installation failed:', err);
process.exit(1);
Expand All @@ -106,16 +102,3 @@ requstBinary(downloadURL, 'realm-cli').catch(err => {
console.error('failed to download Realm CLI:', err);
process.exit(1);
});

let transpilerdownloadURL;
try {
transpilerdownloadURL = getdownloadURL(false);
} catch (err) {
console.error('Realm CLI installation failed:', err);
process.exit(1);
}

requstBinary(transpilerdownloadURL, 'transpiler').catch(err => {
console.error('failed to download Realm CLI:', err);
process.exit(1);
});
1 change: 1 addition & 0 deletions internal/cloud/realm/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ type Client interface {
ImportDependencies(groupID, appID, uploadPath string) error
Diff(groupID, appID string, appData interface{}) ([]string, error)
DiffDependencies(groupID, appID, uploadPath string) (DependenciesDiff, error)
DependenciesStatus(groupID, appID string) (DependenciesStatus, error)

CreateApp(groupID, name string, meta AppMeta) (App, error)
DeleteApp(groupID, appID string) error
Expand Down
49 changes: 42 additions & 7 deletions internal/cloud/realm/dependencies.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,44 @@ const (
dependenciesPathPattern = appPathPattern + "/dependencies"
dependenciesArchivePathPattern = dependenciesPathPattern + "/archive"
dependenciesDiffPathPattern = dependenciesPathPattern + "/diff"
dependenciesStatusPathPattern = dependenciesPathPattern + "/status"

paramFile = "file"
)

// DependenciesStatus is used to get information from a dependencies status request
type DependenciesStatus struct {
State string `json:"status"`
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this may be the best way to avoid stutter but I can see how the idea of a State of Status is a bit odd.

Message string `json:"status_message"`
}

// set of known dependencies status states
const (
DependenciesStateCreated = "created"
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I updated these to make them more related to the status.State as opposed to the status itself.

DependenciesStateSuccessful = "successful"
DependenciesStateFailed = "failed"
)

func (c *client) DependenciesStatus(groupID, appID string) (DependenciesStatus, error) {
res, err := c.do(
http.MethodGet,
fmt.Sprintf(dependenciesStatusPathPattern, groupID, appID),
api.RequestOptions{},
)
if err != nil {
return DependenciesStatus{}, err
}
if res.StatusCode != http.StatusOK {
return DependenciesStatus{}, api.ErrUnexpectedStatusCode{"get dependencies status", res.StatusCode}
}
defer res.Body.Close()
var status DependenciesStatus
if err := json.NewDecoder(res.Body).Decode(&status); err != nil {
return DependenciesStatus{}, err
}
return status, nil
}

func (c *client) ImportDependencies(groupID, appID, uploadPath string) error {
file, fileErr := os.Open(uploadPath)
if fileErr != nil {
Expand All @@ -37,9 +71,9 @@ func (c *client) ImportDependencies(groupID, appID, uploadPath string) error {
body := &bytes.Buffer{}
w := multipart.NewWriter(body)

form, formErr := w.CreateFormFile(paramFile, fileInfo.Name())
if formErr != nil {
return formErr
form, err := w.CreateFormFile(paramFile, fileInfo.Name())
if err != nil {
return err
}

if _, err := io.Copy(form, file); err != nil {
Expand All @@ -49,20 +83,21 @@ func (c *client) ImportDependencies(groupID, appID, uploadPath string) error {
return err
}

res, resErr := c.do(
http.MethodPost,
res, err := c.do(
http.MethodPut,
fmt.Sprintf(dependenciesPathPattern, groupID, appID),
api.RequestOptions{
Body: body,
ContentType: w.FormDataContentType(),
},
)
if resErr != nil {
return resErr
if err != nil {
return err
}
if res.StatusCode != http.StatusNoContent {
return api.ErrUnexpectedStatusCode{"import dependencies", res.StatusCode}
}

return nil
}

Expand Down
39 changes: 36 additions & 3 deletions internal/cloud/realm/dependencies_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,32 @@ func TestRealmDependencies(t *testing.T) {
assert.Nil(t, err)

uploadPath := filepath.Join(wd, "testdata/dependencies_upload.zip")

_, err = client.DependenciesStatus(groupID, app.ID)
assert.Equal(t, realm.ServerError{Message: "dependency installation not found"}, err)

assert.Nil(t, client.ImportDependencies(groupID, app.ID, uploadPath))

startStatus, err := client.DependenciesStatus(groupID, app.ID)
assert.Nil(t, err)
assert.Equal(t, realm.DependenciesStatus{
State: realm.DependenciesStateCreated,
Message: "processing request",
}, startStatus)

// wait for dependencies to finish installation
var currentStatus realm.DependenciesStatus
for i := 0; i < 50; i++ {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in my computer it usually takes around <15 runs but I imagine with all sorts of delays and all, 50 seems to be a good balance between making sure it isn't flaky but also not running for too long; could be lowered.

var err error
currentStatus, err = client.DependenciesStatus(groupID, app.ID)
assert.Nil(t, err)
if currentStatus.State != realm.DependenciesStateCreated {
break
}
time.Sleep(time.Second)
}
assert.Equal(t, realm.DependenciesStateSuccessful, currentStatus.State)

t.Run("and wait for those dependencies to be deployed to the app", func(t *testing.T) {
deployments, err := client.Deployments(groupID, app.ID)
assert.Nil(t, err)
Expand Down Expand Up @@ -78,7 +102,8 @@ func TestRealmDependencies(t *testing.T) {
assert.Nil(t, expectedDepsErr)
defer expectedDeps.Close()

assert.Equalf(t, parseZipArchive(t, expectedDeps), parseZipArchive(t, actualDeps), "expected archives to match")
// make sure same files are present; contents may be different because of transpilation
assert.Equal(t, getZipFileNames(t, expectedDeps), getZipFileNames(t, actualDeps))
})
})

Expand All @@ -97,7 +122,7 @@ func TestRealmDependencies(t *testing.T) {
})
}

func parseZipArchive(t *testing.T, file *os.File) map[string]string {
func getZipFileNames(t *testing.T, file *os.File) map[string]struct{} {
t.Helper()

fileInfo, err := file.Stat()
Expand All @@ -106,5 +131,13 @@ func parseZipArchive(t *testing.T, file *os.File) map[string]string {
zipPkg, err := zip.NewReader(file, fileInfo.Size())
assert.Nil(t, err)

return parseZipPkg(t, zipPkg)
out := make(map[string]struct{}, len(zipPkg.File))

for _, file := range zipPkg.File {
if file.FileInfo().IsDir() {
continue
}
out[file.Name] = struct{}{}
}
return out
}
6 changes: 2 additions & 4 deletions internal/commands/app/diff.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package app

import (
"fmt"
"os"
"strings"

"github.com/10gen/realm-cli/internal/cli"
Expand Down Expand Up @@ -97,13 +96,12 @@ func (cmd *CommandDiff) Handler(profile *user.Profile, ui terminal.UI, clients c
}

if cmd.inputs.IncludeDependencies {
uploadPath, err := local.PrepareDependencies(app, ui)
appDependencies, err := local.FindAppDependencies(app.RootDir)
if err != nil {
return err
}
defer os.Remove(uploadPath) //nolint:errcheck

dependenciesDiff, err := clients.Realm.DiffDependencies(appToDiff.GroupID, appToDiff.ID, uploadPath)
dependenciesDiff, err := clients.Realm.DiffDependencies(appToDiff.GroupID, appToDiff.ID, appDependencies.ArchivePath)
if err != nil {
return err
}
Expand Down
3 changes: 1 addition & 2 deletions internal/commands/app/diff_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,7 @@ func TestAppDiffHandler(t *testing.T) {
cmd := &CommandDiff{diffInputs{LocalPath: "testdata/dependencies", IncludeDependencies: true}}
assert.Equal(t, nil, cmd.Handler(nil, ui, cli.Clients{Realm: realmClient}))

assert.Equal(t, `Transpiled dependency sources
The following reflects the proposed changes to your Realm app
assert.Equal(t, `The following reflects the proposed changes to your Realm app
diff1
diff2
Added Dependencies
Expand Down
Loading