这是indexloc提供的服务,不要输入任何密码
Skip to content

Remote caching and auth with Vercel #88

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 21 commits into from
Dec 3, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
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
20 changes: 20 additions & 0 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# See here for image contents: https://github.com/microsoft/vscode-dev-containers/tree/v0.205.2/containers/go/.devcontainer/base.Dockerfile

# [Choice] Go version (use -bullseye variants on local arm64/Apple Silicon): 1, 1.16, 1.17, 1-bullseye, 1.16-bullseye, 1.17-bullseye, 1-buster, 1.16-buster, 1.17-buster
ARG VARIANT="1.17-bullseye"
FROM mcr.microsoft.com/vscode/devcontainers/go:0-${VARIANT}

# [Choice] Node.js version: none, lts/*, 16, 14, 12, 10
ARG NODE_VERSION="none"
RUN if [ "${NODE_VERSION}" != "none" ]; then su vscode -c "umask 0002 && . /usr/local/share/nvm/nvm.sh && nvm install ${NODE_VERSION} 2>&1"; fi

# [Optional] Uncomment this section to install additional OS packages.
# RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
# && apt-get -y install --no-install-recommends <your-package-list-here>

# [Optional] Uncomment the next lines to use go get to install anything else you need
# USER vscode
# RUN go get -x <your-dependency-or-tool>

# [Optional] Uncomment this line to install global node packages.
RUN su vscode -c "source /usr/local/share/nvm/nvm.sh && npm install -g vercel yarn yalc pnpm" 2>&1
49 changes: 49 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// For format details, see https://aka.ms/devcontainer.json. For config options, see the README at:
// https://github.com/microsoft/vscode-dev-containers/tree/v0.205.2/containers/go
{
"name": "turbo (go, node)",
"build": {
"dockerfile": "Dockerfile",
"args": {
// Update the VARIANT arg to pick a version of Go: 1, 1.16, 1.17
// Append -bullseye or -buster to pin to an OS version.
// Use -bullseye variants on local arm64/Apple Silicon.
"VARIANT": "1.17-bullseye",
// Options
"NODE_VERSION": "lts/*"
}
},
"runArgs": ["--cap-add=SYS_PTRACE", "--security-opt", "seccomp=unconfined"],

// Set *default* container specific settings.json values on container create.
"settings": {
"go.toolsManagement.checkForUpdates": "local",
"go.useLanguageServer": true,
"go.gopath": "/go",
"go.goroot": "/usr/local/go"
},

// Add the IDs of extensions you want installed when the container is created.
"extensions": [
"golang.Go",
"windmilleng.vscode-go-autotest",
"dbaeumer.vscode-eslint",
"bradlc.vscode-tailwindcss",
"heybourn.headwind",
"esbenp.prettier-vscode"
],

// Use 'forwardPorts' to make a list of ports inside the container available locally.
// "forwardPorts": [],

// Use 'postCreateCommand' to run commands after the container is created.
// "postCreateCommand": "go version",

// Comment out connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root.
"remoteUser": "vscode",
"features": {
"docker-in-docker": "latest",
"git": "latest",
"github-cli": "latest"
}
}
9 changes: 9 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"eslint.validate": [
"javascript",
"javascriptreact",
{ "language": "typescript", "autoFix": true },
{ "language": "typescriptreact", "autoFix": true }
],
"debug.javascript.unmapMissingSources": true
}
74 changes: 74 additions & 0 deletions CODE_OF_CONDUCT.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
## Code of Conduct

### Our Pledge

In the interest of fostering an open and welcoming environment, we as
contributors and maintainers pledge to making participation in our project and
our community a harassment-free experience for everyone, regardless of age, body
size, disability, ethnicity, gender identity and expression, level of experience,
nationality, personal appearance, race, religion, or sexual identity and
orientation.

### Our Standards

Examples of behavior that contributes to creating a positive environment
include:

- Using welcoming and inclusive language
- Being respectful of differing viewpoints and experiences
- Gracefully accepting constructive criticism
- Focusing on what is best for the community
- Showing empathy towards other community members

Examples of unacceptable behavior by participants include:

- The use of sexualized language or imagery and unwelcome sexual attention or
advances
- Trolling, insulting/derogatory comments, and personal or political attacks
- Public or private harassment
- Publishing others' private information, such as a physical or electronic
address, without explicit permission
- Other conduct which could reasonably be considered inappropriate in a
professional setting

### Our Responsibilities

Project maintainers are responsible for clarifying the standards of acceptable
behavior and are expected to take appropriate and fair corrective action in
response to any instances of unacceptable behavior.

Project maintainers have the right and responsibility to remove, edit, or
reject comments, commits, code, wiki edits, issues, and other contributions
that are not aligned to this Code of Conduct, or to ban temporarily or
permanently any contributor for other behaviors that they deem inappropriate,
threatening, offensive, or harmful.

### Scope

This Code of Conduct applies both within project spaces and in public spaces
when an individual is representing the project or its community. Examples of
representing a project or community include using an official project e-mail
address, posting via an official social media account, or acting as an appointed
representative at an online or offline event. Representation of a project may be
further defined and clarified by project maintainers.

### Enforcement

Instances of abusive, harassing, or otherwise unacceptable behavior may be
reported by contacting the project team at [coc@vercel.com](mailto:coc@vercel.com). All
complaints will be reviewed and investigated and will result in a response that
is deemed necessary and appropriate to the circumstances. The project team is
obligated to maintain confidentiality with regard to the reporter of an incident.
Further details of specific enforcement policies may be posted separately.

Project maintainers who do not follow or enforce the Code of Conduct in good
faith may face temporary or permanent repercussions as determined by other
members of the project's leadership.

### Attribution

This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
available at [http://contributor-covenant.org/version/1/4][version]

[homepage]: http://contributor-covenant.org
[version]: http://contributor-covenant.org/version/1/4/
13 changes: 0 additions & 13 deletions README.md

This file was deleted.

1 change: 1 addition & 0 deletions README.md
1 change: 1 addition & 0 deletions SECURITY.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Visit https://vercel.com/security to view the disclosure policy.
14 changes: 7 additions & 7 deletions cmd/turbo/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func main() {
ui.Error(fmt.Sprintf("%s %s", uiPkg.ERROR_PREFIX, color.RedString(err.Error())))
os.Exit(1)
}
c.HiddenCommands = []string{"graph"}
c.HiddenCommands = []string{"graph", "login", "logout", "me"}
c.Commands = map[string]cli.CommandFactory{
"run": func() (cli.Command, error) {
return &run.RunCommand{Config: cf, Ui: ui},
Expand All @@ -74,21 +74,21 @@ func main() {
"prune": func() (cli.Command, error) {
return &prune.PruneCommand{Config: cf, Ui: ui}, nil
},
"link": func() (cli.Command, error) {
return &login.LinkCommand{Config: cf, Ui: ui}, nil
},
"unlink": func() (cli.Command, error) {
return &login.UnlinkCommand{Config: cf, Ui: ui}, nil
},
"graph": func() (cli.Command, error) {
return &info.GraphCommand{Config: cf, Ui: ui}, nil
},
"login": func() (cli.Command, error) {
return &login.LoginCommand{Config: cf, Ui: ui}, nil
},
"logout": func() (cli.Command, error) {
return &login.LogoutCommand{Config: cf, Ui: ui}, nil
},
"me": func() (cli.Command, error) {
return &login.MeCommand{Config: cf, Ui: ui}, nil
},
"link": func() (cli.Command, error) {
return &login.LinkCommand{Config: cf, Ui: ui}, nil
},
}

// Capture the defer statements below so the "done" message comes last
Expand Down
5 changes: 5 additions & 0 deletions docs/next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ module.exports = withNextra({
destination: "/reference/command-line-reference",
permanent: true,
},
{
source: "/discord{/}?",
permanent: true,
destination: "https://discord.gg/d6kXWZPWkW",
},
];
},
});
6 changes: 6 additions & 0 deletions docs/pages/docs/changelog.mdx
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## v0.8.5

- Completely rewritten and revamped internal graph. Fixes long standing bug with construction. You no longer need to specify all possible tasks, turbo will figure out the transitive tasks necessary automatically.
- Anything passed after a `--` to `turbo run` will be passed through to all build tasks. This is a temporary workaround for parameterized builds. The use case is for something like `turbo` or Next.js which has OS-specific builds and cache artifacts which would otherwise have an identical hash.
- `turbo` CLI output is now color aware, which should make reading build logs on platforms like Vercel and Netlify (and any other non-interactive terminal) easier.

## v0.8.4

- `turbo` is now much more friendly to OSS. In prior versions, a CI run triggered by a pull request by an outside contributor on a turborepo with remote caching would fail because `turbo` would bail in response to the unauthorized HTTP status code from our API (because the outside contributor doesn't have access to the original repo's secrets and thus TURBO_TOKEN). From now on though, `turbo` will show this warning message and fallback to local caching in this situation. This is a win for everyone as it allows core contributors with write access to get fastest builds, while still have fairly fast external contributions. In the future, we may explore public remote caches for OSS as well as read-only tokens.
Expand Down
8 changes: 1 addition & 7 deletions docs/pages/docs/getting-started.mdx
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
# Getting Started with Turborepo

Welcome to Turborepo! Thank you so much for supporting us. We'll get you up and running in a few minutes.

If you run into any trouble, ask for help through one of the support channels.

## Adding to existing projects
## Add Turborepo to existing projects

Turborepo works with [Yarn v1](https://classic.yarnpkg.com/lang/en/), [NPM](https://npmjs.com), and [PNPM](https://pnpm.io/) workspaces. The `turbo` CLI works on the following operating systems.

Expand Down
35 changes: 8 additions & 27 deletions docs/pages/docs/reference/command-line-reference.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -151,17 +151,6 @@ turbo run lint --parallel --no-cache
turbo run dev --parallel --no-cache
```

#### `--project`

Your turborepo.com project's slug. Useful for running in non-interactive shells in combination with `--token` and `--team` flags.

```sh
turbo run build --team=my-team --project=my-project
turbo run build --team=my-team --project=my-project --token=xxxxxxxxxxxxxxxxx
```

You can also set the value of the current project by setting an environment variable named `TURBO_PROJECT`. The flag will take precendence over the environment variable if both are present.

#### `--scope`

`type: string[]`
Expand Down Expand Up @@ -199,21 +188,21 @@ turbo run build --since=origin/main

#### `--token`

A turborepo.com personal access token. Useful for running in non-interactive shells (e.g. CI/CD) in combination with `--project` and `--team` flags.
A bearer token for remote caching. Useful for running in non-interactive shells (e.g. CI/CD) in combination with `--team` flags.

```sh
turbo run build --team=my-team --project=my-project --token=xxxxxxxxxxxxxxxxx
turbo run build --team=my-team --token=xxxxxxxxxxxxxxxxx
```

You can also set the value of the current token by setting an environment variable named `TURBO_TOKEN`. The flag will take precendence over the environment variable if both are present.

#### `--team`

The slug of the turborepo.com team. Useful for running in non-interactive shells in combination with `--token` and `--team` flags.
The slug of the remote cache team. Useful for running in non-interactive shells in combination with `--token` and `--team` flags.

```sh
turbo run build --team=my-team --project=my-project
turbo run build --team=my-team --project=my-project --token=xxxxxxxxxxxxxxxxx
turbo run build --team=my-team
turbo run build --team=my-team --token=xxxxxxxxxxxxxxxxx
```

You can also set the value of the current team by setting an environment variable named `TURBO_TEAM`. The flag will take precendence over the environment variable if both are present.
Expand Down Expand Up @@ -312,16 +301,8 @@ With the `--docker` flag. The `prune` command will generate folder called `out`

## `turbo link`

Link the current directory to a new or existing turborepo.com project. A project is used to to share [cache artifacts](../caching).

## `turbo login`

Login to your turborepo.com account and activate the current machine. If you haven't done so, visit [https://beta.turborepo.com/signup](https://beta.turborepo.com/signup) to sign up before hand.

## `turbo logout`

Logout of your turborepo.com account.
Link the current directory to an existing Vercel organization or user. The selected owner (either a user or and organization) will be able to share [cache artifacts](../caching).

## `turbo me`
## `turbo unlink`

Prints info about the currently logged in user.
Unlink the current directory from a Vercel organization or user.
2 changes: 1 addition & 1 deletion internal/cache/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func newSyncCache(config *config.Config, remoteOnly bool) Cache {
if config.Cache.Dir != "" && !remoteOnly {
mplex.caches = append(mplex.caches, newFsCache(config))
}
if config.Token != "" && config.ProjectId != "" && config.TeamId != "" {
if config.Token != "" && config.TeamId != "" {
fmt.Println(ui.Dim("• Remote computation caching enabled (experimental)"))
mplex.caches = append(mplex.caches, newHTTPCache(config))
}
Expand Down
10 changes: 6 additions & 4 deletions internal/cache/cache_http.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import (
)

type httpCache struct {
cwd string
writable bool
config *config.Config
requestLimiter limiter
Expand Down Expand Up @@ -44,7 +43,7 @@ func (cache *httpCache) Put(target, hash string, files []string) error {
defer cache.requestLimiter.release()
r, w := io.Pipe()
go cache.write(w, hash, files)
return cache.config.ApiClient.PutArtifact(hash, cache.config.TeamId, cache.config.ProjectId, r)
return cache.config.ApiClient.PutArtifact(hash, cache.config.TeamId, cache.config.TeamSlug, r)
}

// write writes a series of files into the given Writer.
Expand Down Expand Up @@ -105,13 +104,16 @@ func (cache *httpCache) Fetch(target, key string, _unusedOutputGlobs []string) (
defer cache.requestLimiter.release()
m, files, err := cache.retrieve(key)
if err != nil {
return false, files, fmt.Errorf("Failed to retrieve files from HTTP cache: %w", err)
return false, files, fmt.Errorf("failed to retrieve files from HTTP cache: %w", err)
}
return m, files, err
}

func (cache *httpCache) retrieve(key string) (bool, []string, error) {
resp, err := cache.config.ApiClient.FetchArtifact(key, cache.config.TeamId, cache.config.ProjectId, nil)
resp, err := cache.config.ApiClient.FetchArtifact(key, cache.config.TeamId, cache.config.TeamSlug, nil)
if err != nil {
return false, nil, err
}
defer resp.Body.Close()
files := []string{}
if resp.StatusCode == http.StatusNotFound {
Expand Down
Loading