diff --git a/.circleci/config.yml b/.circleci/config.yml index 841e50007..6e7def2d5 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -57,10 +57,15 @@ jobs: command: | ./bin/watch_boot0 background: true + - run: + name: Watch neco-updater logs + command: | + ./bin/watch_service neco-updater + background: true - run: name: Watch neco-worker logs command: | - ./bin/watch_neco_worker + ./bin/watch_service neco-worker background: true - run: command: | @@ -120,11 +125,17 @@ jobs: if [ ! -f .diff ]; then exit 0; fi ./bin/watch_boot0 background: true + - run: + name: Watch neco-updater logs + command: | + if [ ! -f .diff ]; then exit 0; fi + ./bin/watch_service neco-updater + background: true - run: name: Watch neco-worker logs command: | if [ ! -f .diff ]; then exit 0; fi - ./bin/watch_neco_worker + ./bin/watch_service neco-worker background: true - run: command: | diff --git a/bin/watch_neco_worker b/bin/watch_service similarity index 52% rename from bin/watch_neco_worker rename to bin/watch_service index 7b22b2037..c8e1c76b2 100755 --- a/bin/watch_neco_worker +++ b/bin/watch_service @@ -2,18 +2,21 @@ . $(dirname $0)/env -tail_neco_worker_once() { +test $# -eq 1 +service="$1" + +tail_once() { host="$1" $GCLOUD 2>/dev/null compute ssh --zone=${ZONE} cybozu@${INSTANCE_NAME} -- \ sudo nsenter -n -t '$(sudo pmctl pod show operation | jq .pid)' ssh -F ssh_config \ - ${host} journalctl -f -u neco-worker.service + ${host} journalctl -f -u ${service}.service } -tail_neco_worker() { +tail_forever() { host="$1" while true; do - tail_neco_worker_once $host || continue + tail_once $host || continue sleep 3 done } @@ -23,9 +26,9 @@ while ! $GCLOUD 2>/dev/null compute scp --zone=${ZONE} ./dctest/dctest_key ./dct sleep 1 done -tail_neco_worker boot-0 | sed -e s/^/$(tput -Txterm setaf 1)/ & -tail_neco_worker boot-1 | sed -e s/^/$(tput -Txterm setaf 2)/ & -tail_neco_worker boot-2 | sed -e s/^/$(tput -Txterm setaf 3)/ & -tail_neco_worker boot-3 | sed -e s/^/$(tput -Txterm setaf 4)/ & +tail_forever boot-0 | sed -e s/^/$(tput -Txterm setaf 1)/ & +tail_forever boot-1 | sed -e s/^/$(tput -Txterm setaf 2)/ & +tail_forever boot-2 | sed -e s/^/$(tput -Txterm setaf 3)/ & +tail_forever boot-3 | sed -e s/^/$(tput -Txterm setaf 4)/ & wait diff --git a/docs/neco.md b/docs/neco.md index 8558470cf..2aef69971 100644 --- a/docs/neco.md +++ b/docs/neco.md @@ -125,11 +125,13 @@ These configurations are stored in etcd database. ### `env` -Specify the cluster environment. The default is `staging`. +Specify the cluster environment. Possible values are: `staging` and `prod`. `staging` environment will be updated with pre-releases of `neco` package. +Update never happens until this config is set. + ### `slack` Specify [Slack WebHook](https://api.slack.com/incoming-webhooks) URL. diff --git a/docs/update.md b/docs/update.md index 1d0919b99..16f4c105a 100644 --- a/docs/update.md +++ b/docs/update.md @@ -58,7 +58,7 @@ use the version number `2018.11.07-1` on a comparison of the tags. must select the environment by `neco config set env ENV` sub-command. If `production` is set, `neco-updater` downloads latest release excluding pre-release version. Otherwise if `staging` is set, `neco-updater` downloads -latest pre-release version. +latest version from among releases and pre-releases. Implementation of update process -------------------------------- diff --git a/pkg/neco/cmd/config_set.go b/pkg/neco/cmd/config_set.go index 9922235b0..8b5a47a02 100644 --- a/pkg/neco/cmd/config_set.go +++ b/pkg/neco/cmd/config_set.go @@ -22,7 +22,7 @@ var configSetCmd = &cobra.Command{ Long: `Store a configuration value to etcd. Possible keys are: - env - "staging" or "prod". Default is "staging". + env - "staging" or "prod". slack - Slack WebHook URL. proxy - HTTP proxy server URL to access Internet. quay-username - Username to authenticate to quay.io from QUAY_USER. This does not take VALUE. diff --git a/storage/config.go b/storage/config.go index d413c7429..f48e26b8a 100644 --- a/storage/config.go +++ b/storage/config.go @@ -23,7 +23,7 @@ func (s Storage) PutEnvConfig(ctx context.Context, env string) error { func (s Storage) GetEnvConfig(ctx context.Context) (string, error) { env, err := s.get(ctx, KeyEnv) if err == ErrNotFound { - return neco.StagingEnv, nil + return neco.NoneEnv, nil } return env, err } diff --git a/storage/config_test.go b/storage/config_test.go index 30099b361..944420296 100644 --- a/storage/config_test.go +++ b/storage/config_test.go @@ -21,21 +21,21 @@ func testEnvConfig(t *testing.T) { if err != nil { t.Fatal(err) } - if env != neco.StagingEnv { - t.Error(`env != neco.StagingEnv`, env) + if env != neco.NoneEnv { + t.Error(`env != neco.NoneEnv`, env) } - err = st.PutEnvConfig(ctx, "http://squid.example.com:3128") + err = st.PutEnvConfig(ctx, neco.StagingEnv) if err != nil { t.Fatal(err) } - proxy, err := st.GetEnvConfig(ctx) + env, err = st.GetEnvConfig(ctx) if err != nil { t.Fatal(err) } - if proxy != "http://squid.example.com:3128" { - t.Error(`proxy != "http://squid.example.com:3128"`, proxy) + if env != neco.StagingEnv { + t.Error(`env != neco.StagingEnv"`, env) } } diff --git a/update.go b/update.go index 7a78a7f63..52eee27e5 100644 --- a/update.go +++ b/update.go @@ -4,6 +4,7 @@ import "time" // Environments to use release or pre-release neco const ( + NoneEnv = "none" TestEnv = "test" StagingEnv = "staging" ProdEnv = "prod" diff --git a/updater/github.go b/updater/github.go index a41f6bd68..ee5406e5b 100644 --- a/updater/github.go +++ b/updater/github.go @@ -20,7 +20,7 @@ type ReleaseClient struct { http *http.Client } -// GetLatestReleaseTag returns latest tag in GitHub Releases of neco repository +// GetLatestReleaseTag returns latest published release tag in GitHub Releases of neco repository func (c ReleaseClient) GetLatestReleaseTag(ctx context.Context) (string, error) { client := neco.NewGitHubClient(c.http) release, resp, err := client.Repositories.GetLatestRelease(ctx, c.owner, c.repo) @@ -46,8 +46,8 @@ func (c ReleaseClient) GetLatestReleaseTag(ctx context.Context) (string, error) return *release.TagName, nil } -// GetLatestPreReleaseTag returns latest pre-released tag in GitHub Releases of neco repository -func (c ReleaseClient) GetLatestPreReleaseTag(ctx context.Context) (string, error) { +// GetLatestPublishedTag returns latest published release/pre-release tag in GitHub Releases of neco repository +func (c ReleaseClient) GetLatestPublishedTag(ctx context.Context) (string, error) { client := neco.NewGitHubClient(c.http) opt := &github.ListOptions{ @@ -68,7 +68,7 @@ func (c ReleaseClient) GetLatestPreReleaseTag(ctx context.Context) (string, erro } versions := make([]*version.Version, 0, len(releases)) for _, r := range releases { - if r.TagName == nil || !r.GetPrerelease() { + if r.TagName == nil || r.GetDraft() { continue } s := *r.TagName diff --git a/updater/github_test.go b/updater/github_test.go index 196fc3649..b956f8688 100644 --- a/updater/github_test.go +++ b/updater/github_test.go @@ -16,11 +16,11 @@ func testGetLatestReleaseTag(t *testing.T) { t.Logf("version = %s", ver) } -func testGetLatestPreReleaseTag(t *testing.T) { +func testGetLatestPublishedTag(t *testing.T) { t.Skip() c := ReleaseClient{owner: "kubernetes", repo: "kubernetes"} - ver, err := c.GetLatestPreReleaseTag(context.Background()) + ver, err := c.GetLatestPublishedTag(context.Background()) if err != nil { t.Fatal(err) } @@ -32,5 +32,5 @@ func testGetLatestPreReleaseTag(t *testing.T) { func TestGitHub(t *testing.T) { t.Run("GetLatestReleaseTag", testGetLatestReleaseTag) - t.Run("GetLatestPreReleaseTag", testGetLatestPreReleaseTag) + t.Run("GetLatestPublishedTag", testGetLatestPublishedTag) } diff --git a/updater/release_checker.go b/updater/release_checker.go index b3de12e32..59b149ebf 100644 --- a/updater/release_checker.go +++ b/updater/release_checker.go @@ -42,12 +42,16 @@ func (c *ReleaseChecker) Run(ctx context.Context) error { } switch env { + case neco.NoneEnv: + c.check = func(ctx context.Context) (string, error) { + return "", ErrNoReleases + } case neco.TestEnv: c.check = func(ctx context.Context) (string, error) { return "0.0.2", nil } case neco.StagingEnv: - c.check = github.GetLatestPreReleaseTag + c.check = github.GetLatestPublishedTag case neco.ProdEnv: c.check = github.GetLatestReleaseTag default: