├── .gitignore ├── AUTHORS ├── LICENSE ├── README.md ├── base-custom └── Dockerfile ├── base ├── .gitignore ├── Dockerfile.template └── README.md ├── build_custom.sh ├── build_push.sh ├── hello ├── .gitignore ├── Dockerfile.template ├── README.md ├── analysis_options.yaml ├── bin │ └── server.dart ├── pubspec.yaml └── web │ ├── index.css │ └── index.html ├── runtime-base ├── .gitignore ├── Dockerfile.template ├── README.md └── dart_run.sh └── runtime ├── .gitignore ├── Dockerfile.template └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | packages 2 | .packages 3 | -------------------------------------------------------------------------------- /AUTHORS: -------------------------------------------------------------------------------- 1 | # Below is a list of people and organizations that have contributed 2 | # to the Dart project. Names should be added to the list like so: 3 | # 4 | # Name/Organization 5 | 6 | Google Inc. 7 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright 2014, the Dart project authors. 2 | 3 | Redistribution and use in source and binary forms, with or without 4 | modification, are permitted provided that the following conditions are 5 | met: 6 | 7 | * Redistributions of source code must retain the above copyright 8 | notice, this list of conditions and the following disclaimer. 9 | * Redistributions in binary form must reproduce the above 10 | copyright notice, this list of conditions and the following 11 | disclaimer in the documentation and/or other materials provided 12 | with the distribution. 13 | * Neither the name of Google LLC nor the names of its 14 | contributors may be used to endorse or promote products derived 15 | from this software without specific prior written permission. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 18 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 19 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 20 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 21 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # dart_docker (discontinued) 2 | =========== 3 | 4 | ## **NOTE**: These images are discontinued. 5 | 6 | Please consider using the new Docker Official Images for Dart: 7 | https://hub.docker.com/_/dart 8 | 9 | --- 10 | 11 | This repository contains the sources for the following 12 | [docker](https://docker.io) base images: 13 | 14 | - [`google/dart`][base] 15 | - [`google/dart-runtime-base`][runtime-base] 16 | - [`google/dart-runtime`][runtime] 17 | - [`google/dart-hello`][hello] 18 | 19 | 20 | [base]: https://registry.hub.docker.com/r/google/dart/ 21 | [runtime-base]: https://registry.hub.docker.com/r/google/dart-runtime-base/ 22 | [runtime]: https://registry.hub.docker.com/r/google/dart-runtime/ 23 | [hello]: https://registry.hub.docker.com/r/google/dart-hello/ 24 | [1]: https://dart.dev/get-dart#install-a-debian-package 25 | -------------------------------------------------------------------------------- /base-custom/Dockerfile: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file 2 | # for details. All rights reserved. Use of this source code is governed by a 3 | # BSD-style license that can be found in the LICENSE file. 4 | FROM gcr.io/google-appengine/debian10 5 | 6 | RUN apt-get -q update && apt-get install --no-install-recommends -y -q curl git ca-certificates apt-transport-https && rm -rf /var/lib/apt/lists/* 7 | ADD dart.deb . 8 | RUN dpkg -i dart.deb && rm dart.deb 9 | 10 | ENV DART_SDK /usr/lib/dart 11 | ENV PATH $DART_SDK/bin:/root/.pub-cache/bin:$PATH 12 | -------------------------------------------------------------------------------- /base/.gitignore: -------------------------------------------------------------------------------- 1 | Dockerfile 2 | -------------------------------------------------------------------------------- /base/Dockerfile.template: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file 2 | # for details. All rights reserved. Use of this source code is governed by a 3 | # BSD-style license that can be found in the LICENSE file. 4 | FROM gcr.io/google-appengine/debian10 5 | 6 | ENV DART_VERSION {{VERSION}} 7 | 8 | # gnupg2: https://stackoverflow.com/questions/50757647 9 | RUN \ 10 | apt-get -q update && apt-get install --no-install-recommends -y -q gnupg2 curl git ca-certificates apt-transport-https openssh-client && \ 11 | curl https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add - && \ 12 | curl https://storage.googleapis.com/download.dartlang.org/linux/debian/dart_stable.list > /etc/apt/sources.list.d/dart_stable.list && \ 13 | curl https://storage.googleapis.com/download.dartlang.org/linux/debian/dart_testing.list > /etc/apt/sources.list.d/dart_testing.list && \ 14 | curl https://storage.googleapis.com/download.dartlang.org/linux/debian/dart_unstable.list > /etc/apt/sources.list.d/dart_unstable.list && \ 15 | apt-get update && \ 16 | apt-get install dart=$DART_VERSION-1 && \ 17 | rm -rf /var/lib/apt/lists/* 18 | 19 | ENV DART_SDK /usr/lib/dart 20 | ENV PATH $DART_SDK/bin:/root/.pub-cache/bin:$PATH 21 | -------------------------------------------------------------------------------- /base/README.md: -------------------------------------------------------------------------------- 1 | # google/dart 2 | 3 | [`google/dart`](https://hub.docker.com/r/google/dart) is a 4 | [docker](https://docker.com) base image that bundles the latest version 5 | of the [Dart SDK](https://dart.dev) installed from 6 | [dart.dev](https://dart.dev/get-dart). 7 | 8 | It serves as a base for the 9 | [`google/dart-runtime`](https://hub.docker.com/r/google/dart-runtime) image. 10 | 11 | ## Usage 12 | 13 | To configure Docker not to copy across `pub` generated files into the Docker 14 | file system, create a `.dockerignore` with the following contents. 15 | 16 | # Files and directories created by pub 17 | .dart_tool/ 18 | .packages 19 | .pub/ 20 | build/ 21 | 22 | If you have an application directory with a `pubspec.yaml` file and the 23 | main application entry point in `main.dart` you can create a `Dockerfile` 24 | in the application directory with the following content: 25 | 26 | FROM google/dart 27 | 28 | WORKDIR /app 29 | 30 | ADD pubspec.* /app/ 31 | RUN pub get 32 | ADD . /app 33 | 34 | ENTRYPOINT ["/usr/bin/dart", "main.dart"] 35 | 36 | To build a docker image tagged with `my/app` run: 37 | 38 | docker build -t my/app . 39 | 40 | To run this image in a container: 41 | 42 | docker run -i -t my/app 43 | 44 | However, if you application directory has a layout like this and potentially is 45 | exposing a server at port 8080 you should consider using the base image 46 | `google/dart-runtime` instead. 47 | -------------------------------------------------------------------------------- /build_custom.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # Build a Docker image with Dart using a specific .deb file. 3 | # 4 | # This is only used for testing with a custom build of Dart where 5 | # an already built Dart .deb file is used. 6 | # 7 | # To build a .deb file for Dart please use the tools from the 8 | # Dart repository 9 | # 10 | # tools/create_tarball.py 11 | # tools/create_debian_packages.py 12 | # 13 | # Depending on the Linux version used as the base image, you 14 | # might also need to compile inside a chroot environment, depending 15 | # on the Linux version of where the .deb file is build. The 16 | # Dart repository also have a script for setting up a chroot 17 | # environment for building Dart. 18 | # 19 | # tools/create_debian_chroot.sh 20 | 21 | REPO_ROOT=$(dirname "${BASH_SOURCE[0]}") 22 | REPOSITORY_PREFIX=google_test 23 | 24 | function usage { 25 | echo "Usage: $0 " 26 | exit 1 27 | } 28 | 29 | if [ $# -lt 1 ] || [ $# -gt 1 ] 30 | then 31 | usage 32 | fi 33 | 34 | echo 'Building base-custom' 35 | cp $1 $REPO_ROOT/base-custom/dart.deb 36 | docker build -t $REPOSITORY_PREFIX/dart $REPO_ROOT/base-custom 37 | docker tag $REPOSITORY_PREFIX/dart $REPOSITORY_PREFIX/dart-custom 38 | rm $REPO_ROOT/base-custom/dart.deb 39 | -------------------------------------------------------------------------------- /build_push.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file 3 | # for details. All rights reserved. Use of this source code is governed by a 4 | # BSD-style license that can be found in the LICENSE file. 5 | # 6 | # Build and push the Docker images for Dart. 7 | # 8 | # This script will build and push the Dart docker images. 9 | # 10 | # To push a new version update the VERSION variable below and the 11 | # script will build and push images based on that version of Dart 12 | # installed from the Debian repository. 13 | # 14 | # For dev and beta versions the 'dev' or 'beta' tag will be pushed instead of 15 | # the 'latest' tag. 16 | # 17 | # To test without pushing to the official google namespace change the 18 | # NAMESPACE variable below to some other namespace on hub.docker.com. 19 | 20 | set -e 21 | 22 | REPO_ROOT=$(dirname "${BASH_SOURCE[0]}") 23 | 24 | function usage { 25 | echo "Usage: $0 [tag_version] 26 | 27 | is the docker namespace (for production this should 28 | be 'google'). 29 | 30 | is the release channel for the dart version (stable, beta, or dev) 31 | 32 | is the dart version that should be built into the 33 | docker container. 34 | 35 | [tag_version] is optional and will be used instead of the dart version 36 | to tag the images. 37 | 38 | This script will build 4 different docker images 39 | 40 | /dart 41 | /dart-runtime-base 42 | /dart-runtime 43 | /dart-hello 44 | 45 | Each with two tags 'latest' and the actual version. 46 | 47 | When the images have been build they are pushed to hub.docker.com. For 48 | dev and beta versions (versions which contain '-dev') the 'dev' or 49 | 'beta' tag will be pushed instead of the 'latest' tag." 50 | 51 | exit 1 52 | } 53 | 54 | # Find the name of the base image in the Dockerfile in $1. 55 | function base_image { 56 | awk '/^FROM[ \t\r\n\v\f]/ { print /:/ ? $2 : $2":latest" }' $1 57 | } 58 | 59 | # Check whether $1 is contained in $2. 60 | function string_contains { 61 | [[ $2 == *$1* ]] 62 | } 63 | 64 | # Check whether the version is a stable version. 65 | function is_stable_version { 66 | [[ $CHANNEL == 'stable' ]] 67 | } 68 | 69 | # Adds the tags to the IMAGE_TAGS array. 70 | # 71 | # By default the image will be tagged as the version specified as well as the 72 | # major.minor. For stable it will also tag as major. For beta or dev it will also 73 | # be tagged as beta or dev respectively. 74 | function get_tags { 75 | IMAGE_TAGS=( 76 | $NAMESPACE/$IMAGE:$VERSION 77 | ) 78 | 79 | if is_stable_version; 80 | then 81 | IMAGE_TAGS+=( 82 | $NAMESPACE/$IMAGE:$MAJOR_VERSION 83 | $NAMESPACE/$IMAGE:$MAJOR_VERSION.$MINOR_VERSION 84 | ) 85 | else 86 | IMAGE_TAGS+=( 87 | $NAMESPACE/$IMAGE:$CHANNEL 88 | $NAMESPACE/$IMAGE:$MAJOR_VERSION.$MINOR_VERSION-$CHANNEL 89 | ) 90 | fi 91 | } 92 | 93 | # Validate that the Dart VM in the image has the expected version. 94 | function validate_version { 95 | IMAGE=$1 96 | 97 | VM_VERSION=$(docker run --entrypoint=/usr/bin/dart \ 98 | $NAMESPACE/$IMAGE --version 2>&1) 99 | if string_contains $DART_VERSION "$VM_VERSION"; 100 | then 101 | echo "Validated $DART_VERSION in $NAMESPACE/$IMAGE" 102 | else 103 | echo "Did not find version $DART_VERSION in $IMAGE (found $VM_VERSION)" 104 | exit -1 105 | fi 106 | } 107 | 108 | # Build from directory $1 and tag with $2. 109 | function build_and_tag { 110 | DIRECTORY=$1 111 | IMAGE=$2 112 | get_tags $IMAGE 113 | 114 | echo "Building $DIRECTORY with tags $NAMESPACE/$IMAGE" \ 115 | " and $NAMESPACE/$IMAGE:$VERSION" 116 | # Create Dockerfile from template. 117 | sed -e s/{{VERSION}}/$DART_VERSION/ \ 118 | -e s/{{NAMESPACE}}/${NAMESPACE//\//\\/}/ \ 119 | $REPO_ROOT/$DIRECTORY/Dockerfile.template > \ 120 | $REPO_ROOT/$DIRECTORY/Dockerfile 121 | 122 | # Build and tag. 123 | docker build -t $NAMESPACE/$IMAGE $REPO_ROOT/$DIRECTORY 124 | 125 | for i in "${IMAGE_TAGS[@]}" 126 | do 127 | docker tag $NAMESPACE/$IMAGE $i 128 | done 129 | 130 | # Check the Dart version in the image. 131 | validate_version $IMAGE 132 | validate_version "$IMAGE:$VERSION" 133 | } 134 | 135 | function push_image { 136 | IMAGE=$1 137 | get_tags $IMAGE 138 | 139 | # Add the latest tag to the push 140 | if is_stable_version; 141 | then 142 | IMAGE_TAGS+=($NAMESPACE/$IMAGE:latest) 143 | fi 144 | 145 | for i in "${IMAGE_TAGS[@]}" 146 | do 147 | echo "Pushing $i" 148 | docker push $i 149 | done 150 | } 151 | 152 | # Expect three or four arguments, namespace channel dart_version [tag_version] 153 | if ! ([ $# -eq 3 ] || [ $# -eq 4 ]); 154 | then 155 | usage 156 | fi 157 | 158 | NAMESPACE=$1 159 | CHANNEL=$2 160 | DART_VERSION=$3 161 | VERSION=${4:-$DART_VERSION} 162 | 163 | # Read the version string. Patch version is not used 164 | IFS='.' read MAJOR_VERSION MINOR_VERSION PATCH_VERSION <<<"$VERSION" 165 | 166 | # Make sure the latest version of the base image is present. 167 | BASE_IMAGE=$(base_image $REPO_ROOT/base/Dockerfile.template) 168 | echo 'Pulling latest version of base image '$BASE_IMAGE 169 | # TODO: Change this to use the --pull option to docker build when that is 170 | # released. 171 | docker pull $BASE_IMAGE 172 | echo 'Building...' 173 | build_and_tag base dart 174 | build_and_tag runtime-base dart-runtime-base 175 | build_and_tag runtime dart-runtime 176 | build_and_tag hello dart-hello 177 | 178 | echo 'Pushing...' 179 | push_image dart 180 | push_image dart-runtime-base 181 | push_image dart-runtime 182 | push_image dart-hello 183 | echo 'Done!' 184 | -------------------------------------------------------------------------------- /hello/.gitignore: -------------------------------------------------------------------------------- 1 | .dart_tool 2 | pubspec.lock 3 | Dockerfile 4 | -------------------------------------------------------------------------------- /hello/Dockerfile.template: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file 2 | # for details. All rights reserved. Use of this source code is governed by a 3 | # BSD-style license that can be found in the LICENSE file. 4 | # 5 | # Dockerfile for google/dart-hello 6 | 7 | FROM {{NAMESPACE}}/dart-runtime 8 | -------------------------------------------------------------------------------- /hello/README.md: -------------------------------------------------------------------------------- 1 | # google/dart-hello 2 | 3 | [`google/dart-hello`](https://hub.docker.com/r/google/dart-hello) is a 4 | [docker](https://docker.io) image for a simple Dart HTTP server. 5 | 6 | It is based on 7 | [`google/dart-runtime`](https://hub.docker.com/r/google/dart-runtime) 8 | base image and listen on port `8080`. 9 | 10 | ## Run the Dart HTTP server in the docker container 11 | 12 | Run the following command to start the server application: 13 | 14 | docker run -d -p 8080:8080 google/dart-hello 15 | 16 | ## Access the server 17 | 18 | If you are using boot2docker you need to access the server on the 19 | doot2docker host network. The command `boot2docker ip` will give the 20 | hosts address on that network. 21 | 22 | curl http://`boot2docker ip 2> /dev/null`:8080/version 23 | 24 | If you are running the docker daemon directly on a Linux host, you can 25 | access the server on `localhost` 26 | 27 | curl http://localhost:8080/version 28 | 29 | ## Access the Observatory 30 | 31 | If you want to access the Observatory as well as the server 32 | application also map port 8181 to the host. 33 | 34 | docker run -d -p 8080:8080 -p 8181:8181 google/dart-hello 35 | 36 | If you are using boot2docker the following command will give the URL of 37 | the Observatory: 38 | 39 | echo http://$(boot2docker ip 2> /dev/null):8181/ 40 | 41 | If you are running the docker daemon directly on a Linux host, the 42 | URL of the Observatory is: 43 | 44 | http://localhost:8181/ 45 | 46 | ## Running on Google Compute Engine 47 | 48 | The Google Compute Engine has support for 49 | [Container-optimized Google Compute Engine images][1], 50 | which is Google Compute Engine extending its support for Docker containers. 51 | 52 | If you are using a Google Cloud project you can deploy to a container VM 53 | using the [`gcloud`][3] tool. First create a 54 | container manifest file called `container.yaml` with the following content: 55 | 56 | version: v1beta2 57 | containers: 58 | - name: dart-hello 59 | image: google/dart-hello 60 | ports: 61 | - name: dart-hello 62 | hostPort: 80 63 | containerPort: 8080 64 | 65 | Then create and start a Compute Engine VM with the configuration 66 | specified in `container.yaml` by running the following command: 67 | 68 | $ gcloud compute instances create dart-hello \ 69 | --image container-vm-v20141016 \ 70 | --image-project google-containers \ 71 | --machine-type f1-micro 72 | --metadata-from-file google-container-manifest=container.yaml 73 | --tag http-server 74 | 75 | When the command completes, the external IP address of the new server is 76 | displayed. Navigate you browser to http:///. It might take a few 77 | minutes for the VM to pull the image and start the container. 78 | 79 | ## Running on Google Container Engine 80 | 81 | The Google Cloud Platform has an Alpha release of [Google Container Engine][2], 82 | which can also be used to run Docker containers. See the documentation for 83 | more information on the capabilities of Container Engine. 84 | 85 | If you are using a Google Cloud project you can create a Container Engine 86 | cluster and deploy to it using the [`gcloud`][3] 87 | tool. 88 | 89 | $ gcloud preview container clusters create dart-hello \ 90 | --num-nodes 1 91 | $ gcloud preview container pods create dart-hello \ 92 | --image=google/dart-hello \ 93 | --port=8080 94 | $ gcloud compute firewall-rules create hello-dart-node-8080 \ 95 | --allow tcp:8080 \ 96 | --target-tags k8s-hello-dart-node 97 | 98 | The first command creates a cluster with just one node. The second creates 99 | a "pod" (which is a group of containers) inside that cluster 100 | running the Docker image `google/dart-hello`. The last command will open 101 | the firewall for traffic on port `8080` providing public access to the 102 | Dart server. 103 | 104 | To discover the public IP address of the Dart server, run this command: 105 | 106 | $ gcloud preview container pods describe dart-hello 107 | 108 | The IP address is displayed as part of the `Host` column in the output. 109 | Navigate you browser to http://:8080/. It might take a few 110 | minutes for the VM to pull the image and start the "pod". 111 | 112 | [1]: https://cloud.google.com/compute/docs/containers/container_vms 113 | [2]: https://cloud.google.com/container-engine/docs/ 114 | [3]: https://cloud.google.com/sdk/ 115 | -------------------------------------------------------------------------------- /hello/analysis_options.yaml: -------------------------------------------------------------------------------- 1 | include: package:pedantic/analysis_options.yaml -------------------------------------------------------------------------------- /hello/bin/server.dart: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file 2 | // for details. All rights reserved. Use of this source code is governed by a 3 | // BSD-style license that can be found in the LICENSE file. 4 | import 'dart:async'; 5 | import 'dart:io'; 6 | 7 | import 'package:http_server/http_server.dart'; 8 | 9 | void main() { 10 | final port = int.tryParse(Platform.environment['PORT'] ?? '8080'); 11 | final webFiles = new VirtualDirectory('web'); 12 | 13 | runZonedGuarded(() { 14 | HttpServer.bind('0.0.0.0', port).then((server) { 15 | server.listen((request) { 16 | if (request.uri.path == '/') { 17 | request.response.redirect(request.uri.resolve('/index.html')); 18 | } else if (request.uri.path == '/version') { 19 | request.response.headers..contentType = ContentType.text; 20 | request.response 21 | ..writeln('Dart version: ${Platform.version}') 22 | ..writeln('Dart executable: ${Platform.executable}') 23 | ..writeln('Dart executable arguments: ' 24 | '${Platform.executableArguments}') 25 | ..close(); 26 | } else { 27 | webFiles.serveRequest(request); 28 | } 29 | }); 30 | }); 31 | }, (e, stackTrace) { 32 | print('Error processing request $e\n$stackTrace'); 33 | }); 34 | } 35 | -------------------------------------------------------------------------------- /hello/pubspec.yaml: -------------------------------------------------------------------------------- 1 | name: hello 2 | description: Hello 3 | dependencies: 4 | http_server: any 5 | pedantic: any 6 | environment: 7 | sdk: '>=2.10.0 <3.0.0' 8 | -------------------------------------------------------------------------------- /hello/web/index.css: -------------------------------------------------------------------------------- 1 | body { 2 | background-color: #F8F8F8; 3 | font-family: 'Open Sans', sans-serif; 4 | font-size: 14px; 5 | font-weight: normal; 6 | line-height: 1.2em; 7 | margin: 15px; 8 | } 9 | 10 | h1, p { 11 | color: #333; 12 | } 13 | -------------------------------------------------------------------------------- /hello/web/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 |

Hello from Dart server

8 |

Server version

9 | 10 | 11 | -------------------------------------------------------------------------------- /runtime-base/.gitignore: -------------------------------------------------------------------------------- 1 | Dockerfile 2 | -------------------------------------------------------------------------------- /runtime-base/Dockerfile.template: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file 2 | # for details. All rights reserved. Use of this source code is governed by a 3 | # BSD-style license that can be found in the LICENSE file. 4 | # 5 | # Dockerfile for google/dart-runtime-base 6 | 7 | FROM {{NAMESPACE}}/dart 8 | 9 | ADD dart_run.sh /dart_runtime/ 10 | RUN chmod 755 /dart_runtime/dart_run.sh && \ 11 | chown root:root /dart_runtime/dart_run.sh 12 | 13 | ENV PORT 8080 14 | 15 | # Expose ports for debugger (5858), application traffic ($PORT) 16 | # and the observatory (8181) 17 | EXPOSE $PORT 8181 5858 18 | 19 | CMD [] 20 | ENTRYPOINT ["/dart_runtime/dart_run.sh"] 21 | -------------------------------------------------------------------------------- /runtime-base/README.md: -------------------------------------------------------------------------------- 1 | # google/dart-runtime-base 2 | 3 | [`google/dart-runtime-base`][2] is a [docker](https://docker.io) base image that 4 | makes it easy to dockerize a standard [Dart](https://dart.dev) application 5 | which is using local packages. 6 | 7 | If you have a Dart application which does not require local packages you 8 | might be able to use the base image [`google/dart-runtime`][3] which is 9 | simpler. 10 | 11 | Using this image requires that a predefined directory layout is used together 12 | with a `Dockerfile` following a predefined template. 13 | 14 | It is based on the [`google/dart`][1] base image. 15 | 16 | If the directory layout described below does not work for your setup a 17 | `Dockerfile` based on the [`google/dart`][1] base image is probably the way 18 | to go. 19 | 20 | ## Usage 21 | 22 | The following directory layout is used: 23 | 24 | project 25 | Dockerfile 26 | app 27 | bin 28 | server.dart 29 | pubspec.yaml 30 | pkg 31 | my-package-1 32 | my-package-2 33 | 34 | The top-level directory `project` contains the `Dockerfile` and the two 35 | directories `app` and `pkg`. The `app` directory contains a Dart application 36 | with the main entrypoint in `bin/server.dart`. The packages referred from 37 | `app/pubspec.yaml` must be either packages on [pub.dev](https://pub.dev) or 38 | packages in the `pkg` directory referred to using a relative `path` dependency, 39 | like this: 40 | 41 | name: dart_app 42 | version: 0.1.0 43 | description: Dart application. 44 | dependencies: 45 | my-package-1: 46 | path: ../pkg/my-package-1 47 | my-package-2: 48 | path: ../pkg/my-package-2 49 | 50 | You can also use `dependency_overrides` like this: 51 | 52 | name: dart_app 53 | version: 0.1.0 54 | description: Dart application. 55 | dependencies: 56 | some-package: any 57 | dependency_overrides: 58 | my-package-1: 59 | path: ../pkg/my-package-1 60 | my-package-2: 61 | path: ../pkg/my-package-2 62 | 63 | Then create a `Dockerfile` in your Dart application directory with the 64 | following content: 65 | 66 | FROM google/dart-runtime-base 67 | 68 | WORKDIR /project/app 69 | 70 | # Add the pubspec.yaml files for each local package. 71 | ADD pkg/my-package-1/pubspec.yaml /project/pkg/my-package-1/ 72 | ADD pkg/my-package-2/pubspec.yaml /project/pkg/my-package-2/ 73 | 74 | # Template for adding the application and local packages. 75 | ADD app/pubspec.* /project/app/ 76 | RUN pub get 77 | ADD . /project 78 | RUN pub get --offline 79 | 80 | Depending on your local packages you need to change the `ADD` commands in the 81 | section after the comment _Add the pubspec.yaml files for each local package_. 82 | Add an `ADD` command for each of your local packages. Be careful with adding 83 | the terminating `/` for the `ADD` commands. The rest of the `Dockerfile` 84 | should just be copied. 85 | 86 | To build a docker image tagged with `my/app` run: 87 | 88 | docker build -t my/app . 89 | 90 | To run this image in a container (assuming it is a server application 91 | listening on port 8080): 92 | 93 | docker run -d -p 8080:8080 my/app 94 | 95 | ## Accessing the Observatory 96 | 97 | The `dart-runtime-base` image enables the 98 | [Observatory](https://dart-lang.github.io/observatory/) for the Dart VM running 99 | in the container. The Observatory is listening on the default port 8181. Just 100 | map that port to the host when running the app: 101 | 102 | docker run -d -p 8080:8080 -p 8181:8181 my-app 103 | 104 | If using boot2docker you can access the Observatory using the docker 105 | host network on http://192.168.59.103:8181/ (replacing 192.168.59.103 106 | with what you 'boot2docker ip' says). 107 | 108 | ## Passing VM flags 109 | 110 | The `dart-runtime-base` image can receive options for the Dart VM through 111 | the environment variable `DART_VM_OPTIONS`. 112 | 113 | docker run -d -p 8080:8080 \ 114 | --env DART_VM_OPTIONS='--old_gen_heap_size=2048 --verbose-gc' \ 115 | my/app 116 | 117 | ## Using this image with App Engine Managed VMs 118 | 119 | If you are using this image with App Engine Managed VMs, the `app.yaml` 120 | file must be alongside the `Dockerfile` in the project directory. 121 | 122 | You can set up Observatory access by adding the following to the 123 | `app.yaml` file: 124 | 125 | network: 126 | forwarded_ports: ["8181"] 127 | 128 | You can pass VM flags by adding the following to the `app.yaml` file: 129 | 130 | env_variables: 131 | DART_VM_OPTIONS: --old_gen_heap_size=2048 --verbose-gc 132 | 133 | 134 | [1]: https://hub.docker.com/r/google/dart 135 | [2]: https://hub.docker.com/r/google/dart-runtime-base 136 | [3]: https://hub.docker.com/r/google/dart-runtime 137 | [4]: https://hub.docker.com/r/google/dart-hello 138 | -------------------------------------------------------------------------------- /runtime-base/dart_run.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # 3 | # Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file 4 | # for details. All rights reserved. Use of this source code is governed by a 5 | # BSD-style license that can be found in the LICENSE file. 6 | 7 | DBG_OPTION= 8 | # Only enable Dart debugger if DBG_ENABLE is set. 9 | if [ -n "$DBG_ENABLE" ] && [ "$GAE_PARTITION" = "dev" ]; then 10 | echo "Enabling Dart debugger" 11 | DBG_OPTION="--debug:${DBG_PORT:-5858}/0.0.0.0" 12 | echo "Starting Dart with additional options $DBG_OPTION" 13 | fi 14 | 15 | if [ -n "$DART_VM_OPTIONS" ]; then 16 | echo "Starting Dart with additional options $DART_VM_OPTIONS" 17 | fi 18 | 19 | exec /usr/bin/dart \ 20 | ${DBG_OPTION} \ 21 | --enable-vm-service:8181/0.0.0.0 \ 22 | ${DART_VM_OPTIONS} \ 23 | bin/server.dart 24 | -------------------------------------------------------------------------------- /runtime/.gitignore: -------------------------------------------------------------------------------- 1 | Dockerfile 2 | -------------------------------------------------------------------------------- /runtime/Dockerfile.template: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file 2 | # for details. All rights reserved. Use of this source code is governed by a 3 | # BSD-style license that can be found in the LICENSE file. 4 | # 5 | # Dockerfile for google/dart-runtime 6 | 7 | FROM {{NAMESPACE}}/dart-runtime-base 8 | 9 | WORKDIR /app 10 | 11 | # In docker each step creates an image layer that is cached. We add the 12 | # pubspec.* before "pub get", then we add the rest of /app/ and run 13 | # "pub get --offline". Thus, rebuilding without touching pubspec.* files won't 14 | # download all dependencies again (facilitating faster image rebuilds). 15 | ONBUILD ADD pubspec.* /app/ 16 | ONBUILD RUN pub get 17 | ONBUILD ADD . /app/ 18 | ONBUILD RUN pub get --offline 19 | -------------------------------------------------------------------------------- /runtime/README.md: -------------------------------------------------------------------------------- 1 | # google/dart-runtime 2 | 3 | [`google/dart-runtime`][3] is a [docker](https://docker.io) base image that 4 | makes it easy to dockerize a standard [Dart](https://dart.dev) application. 5 | 6 | It can automatically bundle a Dart application and its dependencies with 7 | a single line Dockerfile. 8 | 9 | It is based on the [`google/dart-runtime-base`][2] base image. 10 | 11 | ## Usage 12 | 13 | Create a `Dockerfile` in your Dart application directory with the following 14 | content: 15 | 16 | FROM google/dart-runtime 17 | 18 | To build a docker image tagged with `my/app` run: 19 | 20 | docker build -t my/app . 21 | 22 | To run this image in a container (assuming it is a server application 23 | listening on port 8080): 24 | 25 | docker run -d -p 8080:8080 my/app 26 | 27 | ## Sample 28 | 29 | See the [sources](/hello) for [`google/dart-hello`][4] based on this image. 30 | 31 | ## Notes 32 | 33 | The image assumes that your application: 34 | 35 | - has the `pubspec.yaml` file listing its dependencies. 36 | - has a file named `bin/server.dart` as the entrypoint script. 37 | - listens on port `8080` 38 | - all dependent packages can be retrieved when building the container 39 | 40 | If you have package dependencies which do not meet the last requirement 41 | take a look at using either the base image [`google/dart-runtime-base`][2] 42 | or [`google/dart`][1]. 43 | 44 | ### Example directory laoyout: 45 | 46 | bin 47 | server.dart 48 | packages 49 | ... 50 | pubspec.yaml 51 | 52 | When building your application docker image, `ONBUILD` triggers fetch the 53 | dependencies listed in the `pubspec.yaml` file and cache them appropriatly. 54 | 55 | ## Accessing the Observatory 56 | 57 | The `dart-runtime` image enables the 58 | [Observatory](https://dart-lang.github.io/observatory/) for the Dart 59 | VM running in the container. The Observatory is listening on the default 60 | port 8181. Just map that port to the host when running the app: 61 | 62 | docker run -d -p 8080:8080 -p 8181:8181 my-app 63 | 64 | If using boot2docker you can access the Observatory using the docker 65 | host network on http://192.168.59.103:8181/ (replacing 192.168.59.103 66 | with what you 'boot2docker ip' says). 67 | 68 | ## Passing VM flags 69 | 70 | The `dart-runtime` image can receive options for the Dart VM through 71 | the environment variable `DART_VM_OPTIONS`. 72 | 73 | docker run -d -p 8080:8080 \ 74 | --env DART_VM_OPTIONS='--old_gen_heap_size=2048 --verbose-gc' \ 75 | my/app 76 | 77 | ## Using this image with App Engine Managed VMs 78 | 79 | If you are using this image with App Engine Managed VMs, the `app.yaml` 80 | file must be alongside the `Dockerfile` in the project directory. 81 | 82 | You can set up Observatory access by adding the following to the 83 | `app.yaml` file: 84 | 85 | network: 86 | forwarded_ports: ["8181"] 87 | 88 | You can pass VM flags by adding the following to the `app.yaml` file: 89 | 90 | env_variables: 91 | DART_VM_OPTIONS: --old_gen_heap_size=2048 --verbose-gc 92 | 93 | 94 | [1]: https://hub.docker.com/r/google/dart 95 | [2]: https://hub.docker.com/r/google/dart-runtime-base 96 | [3]: https://hub.docker.com/r/google/dart-runtime 97 | [4]: https://hub.docker.com/r/google/dart-hello 98 | --------------------------------------------------------------------------------