Skip to content

Commit 41cd7c2

Browse files
authored
watchrsync job to push binaries to a test machine (#1158)
* ignore some more stuff * watchrsync make command like kurl project * document watchrsync * the actual watchrsync script * dont need these for npm dependencies * Revert "dont need these for npm dependencies" This reverts commit bdb4e62. * install gaze-run-interrupt with make * watchrsync instructions
1 parent 2b8e3fb commit 41cd7c2

File tree

4 files changed

+97
-0
lines changed

4 files changed

+97
-0
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
*.dylib
88
bin
99
.DS_Store
10+
node_modules/
1011

1112
# Test binary, build with `go test -c`
1213
*.test
@@ -26,6 +27,8 @@ vendor
2627
*.swp
2728
*.swo
2829
*~
30+
.envrc
31+
2932

3033
dist
3134
try.sh

CONTRIBUTING.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,28 @@ To get started we recommend:
3232
3333
6. Install [golangci-lint] linter and run `make lint` to execute additional code linters.
3434

35+
### Syncing to a test cluster with `watchrsync`
36+
37+
1. Install `npm`
38+
2. Export `REMOTES=<user>@<ip>` so that `watchrsync` knows where to sync.
39+
3. Maybe run `export GOOS=linux` and `export GOARCH=amd64` so that you build Linux binaries.
40+
4. run `make watchrsync` to build and sync binaries automatically on saving.
41+
42+
```
43+
ssh-add --apple-use-keychain ~/.ssh/google_compute_engine
44+
45+
export GOOS=linux
46+
export GOARCH=amd64
47+
make watchrsync
48+
# bin/watchrsync.js
49+
# make support-bundle
50+
# go build -tags "netgo containers_image_ostree_stub exclude_graphdriver_devicemapper exclude_graphdriver_btrfs containers_image_openpgp" -installsuffix netgo -ldflags " -s -w -X github.com/replicatedhq/troubleshoot/pkg/version.version=`git describe --tags --dirty` -X github.com/replicatedhq/troubleshoot/pkg/version.gitSHA=`git rev-parse HEAD` -X github.com/replicatedhq/troubleshoot/pkg/version.buildTime=`date -u +"%Y-%m-%dT%H:%M:%SZ"` " -o bin/support-bundle github.com/replicatedhq/troubleshoot/cmd/troubleshoot
51+
# rsync bin/support-bundle [email protected]:
52+
# date
53+
# Tue May 16 14:14:13 EDT 2023
54+
# synced
55+
```
56+
3557
### Testing
3658

3759
To run the tests locally run the following:
@@ -54,11 +76,13 @@ A running Kubernetes cluster as well as `jq` are required to run e2e tests.
5476
You are able to collect CPU & memory runtime properties and store the data for analysis in a file. To do so, pass in the file paths using `--cpuprofile` and `--memprofile` flags in the CLI. Once you have your data collected, you can analyse it using [pprof visualization tool](https://github.com/google/pprof/blob/main/doc/README.md). Here is how
5577

5678
Run support bundle and with CPU & memory profile flags
79+
5780
```sh
5881
./bin/support-bundle examples/support-bundle/sample-supportbundle.yaml --cpuprofile=cpu.prof --memprofile=mem.prof
5982
```
6083

6184
Visualize using [pprof](https://github.com/google/pprof/blob/main/doc/README.md)
85+
6286
```sh
6387
go tool pprof -http=":8000" cpu.prof
6488

@@ -76,16 +100,19 @@ This is a rough outline of how to prepare a contribution:
76100
- Make commits of logical units.
77101
- When your changes are ready to merge, squash your history to 1 commit.
78102
- For example, if you want to squash your last 3 commits and write a new commit message:
103+
79104
```
80105
git reset --soft HEAD~3 &&
81106
git commit
82107
```
83108
84109
- If you want to keep the previous commit messages and concatenate them all into a new commit, you can do something like this instead:
110+
85111
```
86112
git reset --soft HEAD~3 &&
87113
git commit --edit -m"$(git log --format=%B --reverse HEAD..HEAD@{1})"
88114
```
115+
89116
- Push your changes to a topic branch in your fork of the repository.
90117
- Submit a pull request to the original repository. It will be reviewed in a timely manner.
91118

Makefile

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,3 +220,13 @@ lint: fmt vet
220220
.PHONY: lint-and-fix
221221
lint-and-fix: fmt vet
222222
golangci-lint run --new --fix -c .golangci.yaml ${BUILDPATHS}
223+
224+
## Syncronize the code with a remote server. More info: CONTRIBUTING.md
225+
.PHONY: watchrsync
226+
watchrsync: npm-install
227+
bin/watchrsync.js
228+
229+
.PHONY: npm-install
230+
npm-install:
231+
npm --version 2>&1 >/dev/null || ( echo "npm not installed; install npm to set up watchrsync" && exit 1 )
232+
npm list gaze-run-interrupt || npm install install gaze-run-interrupt@~2.0.0

bin/watchrsync.js

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
#!/usr/bin/env node
2+
3+
const gri = require('gaze-run-interrupt');
4+
5+
if (!process.env.REMOTES) {
6+
console.log("Usage: `REMOTES='[email protected],[email protected]' ./watchrsync.js`");
7+
process.exit(1);
8+
}
9+
10+
process.env.GOOS = 'linux';
11+
process.env.GOARCH = 'amd64';
12+
13+
const binList = [
14+
// 'bin/analyze',
15+
// 'bin/preflight',
16+
'bin/support-bundle',
17+
// 'bin/collect'
18+
]
19+
const makeList = [
20+
// 'analyze',
21+
// 'preflight',
22+
'support-bundle',
23+
// 'collect'
24+
]
25+
26+
const commands = [
27+
// {
28+
// command: 'rm',
29+
// args: binList,
30+
// },
31+
{
32+
command: 'make',
33+
args: makeList,
34+
},
35+
];
36+
37+
process.env.REMOTES.split(",").forEach(function (remote) {
38+
commands.push({
39+
command: 'rsync',
40+
args: binList.concat(`${remote}:`),
41+
});
42+
});
43+
44+
commands.push({
45+
command: "date",
46+
args: [],
47+
});
48+
49+
commands.push({
50+
command: "echo",
51+
args: ["synced"],
52+
});
53+
54+
gri([
55+
'cmd/**/*.go',
56+
'pkg/**/*.go',
57+
], commands);

0 commit comments

Comments
 (0)