Demo repository using Dart lang by Google. Cherry-picks number_guesser
and number_thinker
code from Write HTTP clients & servers tutorial.
Visit the Dart language guide for CircleCI here.
- Make sure Dart is installed and configured on your system.
- Install the
webdev
Dart package globally withpub global activate webdev
.
- Clone this project.
- Run
pub get
to download dependencies. pub run bin/server.dart
to run the number thinker server. It listens at https://localhost:8080webdev serve web:8181
in another terminal at the project root to serve the basic webpage at https://localhost:8181. It's just a basic webpage with dropdown and button to send guess API requests to the server.
- Run
pub run test
to test theserver
andnumber_guesser
.
webdev build
compiles the web client (just anindex.html
).dart2native
compiles the server client to machine code and spits out an executable inbin
.
The CircleCI config does the following:
- It runs the tests on a Docker container.
- This job uses the
google/dart
Docker image (CircleCI doesn't currently have a native Dart docker convenience image). - The tests uses the junitreporter package to produce JUnit XML output for CircleCI's test metadata feature, which in turn supports things like test summary and insights data/metrics.
- This job uses the
- After tests run, it builds executables for deployment:
- One job uses Google's recommended
dart-runtime
image to build a production container. There's a section that pushes to DockerHub, but that's been commented out since we don't want to unnecessarily spam our repo with example images. It's there as an example. - The other three jobs compile native executables on macOS, Windows, and Linux VMs.
- One job uses Google's recommended
- All jobs use dependency caching. The jobs cache according to the
pubspec.lock
and thearch
of the system.~/.pub-cache
and.dart_tool
folders are cached.~/AppData/Local/Pub/Cache
if Windows.- This demo project doesn't download enough dependencies to show any signficant performance benefit, but it's shown as an example. Larger projects that download many hundreds of MB of dependencies should see greater performance and speed gains.
- For Dart projects that have it, you'll probably also want to cache the
.packages
folder in the project directory.
- If you fork this project and want to push to DockerHub, this project assumes a context called
dart-docker
with the following variables & keys:
KEY | VALUE |
---|---|
DOCKER_TAG | The tag/repository for your image |
DOCKER_LOGIN | Your Docker login |
DOCKER_PWD | Your Docker password |
See the config and modify as needed for your use case.
For more resources, see below: