Skip to content

Add Dockerfile and some cleanup #57

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 1 commit into from
Mar 7, 2019
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
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Dockerfile
26 changes: 26 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
FROM node:8.15.0

# Install VS Code's deps. These are the only two it seems we need.
RUN apt-get update
RUN apt-get install -y libxkbfile-dev libsecret-1-dev
Copy link
Contributor

Choose a reason for hiding this comment

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

Compress these two RUNs as one instruction as well.


# Ensure latest yarn.
RUN npm install -g yarn

# In the future, we can use https://github.com/yarnpkg/rfcs/pull/53 to make it use the node_modules
# directly which should be faster.
WORKDIR /src
COPY . .
RUN yarn
Copy link
Contributor

Choose a reason for hiding this comment

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

compress this as one instruction as well.

RUN yarn task build:server:binary

# We deploy with ubuntu so that devs have a familiar environemnt.
FROM ubuntu:18.10
RUN apt-get update
Copy link
Contributor

Choose a reason for hiding this comment

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

Compress these two RUNs as one instruction.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Its a small thing but I like em separate to make better use of docker's layer cache.

Copy link
Contributor

Choose a reason for hiding this comment

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

Optimizing layers no matter how small should be done.

Copy link

Choose a reason for hiding this comment

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

@nhooyr it is fine to separate them while you are getting the image done, but once it is there, it is strongly recommended (see “apt-get” section) to combine update + install + remove caches

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That is interesting. Does seem reasonable to me to bust the cache every time the package list is modified.

RUN apt-get install -y openssl
RUN apt-get install -y net-tools
WORKDIR /root/project
Copy link
Contributor

Choose a reason for hiding this comment

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

I do not recommend using root. Consider using a actual user or a pseudo-user like what we do in Theia.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I personally don't really see much value in that. Especially for a dev setup, you pretty much need sudo 100% of the time at which point it just becomes annoying and repetitive.

cc @kylecarbs

Copy link
Member

Choose a reason for hiding this comment

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

I'm not certain what purpose there'd be in limiting the user when running inside the docker container. What do you think @sr229 ?

Copy link
Contributor

Choose a reason for hiding this comment

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

@kylecarbs @nhooyr we're excercising a good practice that the user should be aware that some administrative actions might need sudo or a manual switch to the root. Not all Cloud IDE users are proficient in Linux and know the security implications.

This is also how Theia and Cloud9 does their images.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Lets get this PR in for now and discuss this in #65.

COPY --from=0 /src/packages/server/cli-linux /usr/local/bin/code-server
EXPOSE 8443
# Unfortunately `.` does not work with code-server.
CMD code-server $PWD
13 changes: 12 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@

`code-server` is [VS Code](https://github.com/Microsoft/vscode) running on a remote server, accessible through the browser.

Try it out:
```bash
docker run -p localhost:8443:8443 -v "${PWD}:/root/project" codercom/code-server code-server --allow-http --no-auth
```

- Code on your Chromebook, tablet, and laptop with a consistent dev environment.
- If you have a Windows or Mac workstation, more easily develop for Linux.
- Take advantage of large cloud servers to speed up tests, compilations, downloads, and more.
Expand All @@ -18,9 +23,15 @@

## Getting Started

### Hosted

[Try `code-server` now](https://coder.com/signup) for free at coder.com.

**OR**
### Docker

See docker oneliner mentioned above. Dockerfile is at [/Dockerfile](/Dockerfile).

### Binaries

1. [Download a binary](https://github.com/codercom/code-server/releases) (Linux and OSX supported. Windows coming soon)
2. Start the binary with the project directory as the first argument
Expand Down
21 changes: 18 additions & 3 deletions packages/runner/src/runner.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as cp from "child_process";
import { logger, Logger, field, time } from "@coder/logger";
import {field, Logger, logger, time} from "@coder/logger";

export interface CommandResult {
readonly exitCode: number;
Expand All @@ -9,7 +9,9 @@ export interface CommandResult {

const execute = (command: string, args: string[] = [], options: cp.SpawnOptions, logger: Logger): Promise<CommandResult> => {
let resolve: (result: CommandResult) => void;
const prom = new Promise<CommandResult>(res => resolve = res);
const prom = new Promise<CommandResult>((res): void => {
resolve = res;
});

const stdout: string[] = [];
const stderr: string[] = [];
Expand Down Expand Up @@ -44,6 +46,7 @@ export type TaskFunction = (runner: Runner) => void | Promise<void>;

export interface Runner {
cwd: string;

Copy link
Member

Choose a reason for hiding this comment

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

Unneeded space, but not a biggie

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Goland formatted automatically, will fix.

execute(command: string, args?: string[], env?: object): Promise<CommandResult>;
}

Expand Down Expand Up @@ -90,10 +93,22 @@ export const run = (name: string = process.argv[2]): void | Promise<void> => {
cwd = path;
},
execute(command: string, args: string[] = [], env?: object): Promise<CommandResult> {
return execute(command, args, {
const prom = execute(command, args, {
cwd,
env: env as NodeJS.ProcessEnv,
}, log);

return prom.then((result: CommandResult) => {
if (result.exitCode != 0) {
log.error("failed",
field("exitCode", result.exitCode),
field("stdout", result.stdout),
field("stderr", result.stderr)
);
}

return result;
});
},
});

Expand Down
1 change: 0 additions & 1 deletion scripts/build.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/bin/bash
set -e

npm install -g cross-env
yarn task build:server:binary