Skip to content

Jdubedition/docker-polyglot-world

Repository files navigation

docker-polyglot-world

Welcome to the repository that shares multiple implementations of Hello World web server in different programming languages, wrapped by a Docker container.

Programming languages:

  • Python
  • Go
  • JavaScript
  • TypeScript
  • Rust
  • Crystal
  • More to come...

The setup

Building and running Docker images

All at once with Docker Compose

docker compose --profile local-only up --build

Python (Starlette)

docker build -t python-docker-polyglot-world -f python/python.Dockerfile . && docker run -it -p 8080:8080 python-docker-polyglot-world

Go

docker build -t go-docker-polyglot-world -f go/go.Dockerfile . && docker run -it -p 8080:8080 go-docker-polyglot-world

Node.js (express)

docker build -t nodejs-docker-polyglot-world -f nodejs/nodejs.Dockerfile .  && docker run -it -p 8080:8080 nodejs-docker-polyglot-world

Rust (hyper)

docker build -t rust-docker-polyglot-world -f rust/rust.Dockerfile .  && docker run -it -p 8080:8080 rust-docker-polyglot-world

Deno

docker build -t deno-docker-polyglot-world -f deno/deno.Dockerfile .  && docker run -it -p 8080:8080 deno-docker-polyglot-world

Crystal

docker build -t crystal-docker-polyglot-world -f crystal/crystal.Dockerfile .  && docker run -it -p 8080:8080 crystal-docker-polyglot-world

Developing with Docker containers

Python

With OMZ and selecting name of the container

docker run -d -it --network=host -v ~/docker-polyglot-world:/docker-polyglot-world --name docker-polyglot-world-python python:3.11.0 /docker-polyglot-world/utilities/use-omz.sh

With BASH

docker run -d -it --network=host -v ~/docker-polyglot-world:/docker-polyglot-world python:3.11.0 /bin/bash

Go

With OMZ and selecting name of the container

docker run -d -it --network=host -v ~/docker-polyglot-world:/docker-polyglot-world --name docker-polyglot-world-go golang:1.19.3 /docker-polyglot-world/utilities/use-omz.sh

Node.js

With OMZ and selecting name of the container

docker run -d -it --network=host -v ~/docker-polyglot-world:/docker-polyglot-world --name docker-polyglot-world-nodejs node:19 /docker-polyglot-world/utilities/use-omz.sh

Rust

With OMZ and selecting name of the container

docker run -d -it --network=host -v ~/docker-polyglot-world:/docker-polyglot-world --name docker-polyglot-world-rust rust:1.65 /docker-polyglot-world/utilities/use-omz.sh

Deno

With OMZ and selecting name of the container

docker run -d -it --network=host -v ~/docker-polyglot-world:/docker-polyglot-world --name docker-polyglot-world-deno denoland/deno:1.28.1 /docker-polyglot-world/utilities/use-omz.sh

IMPORTANT! - After attaching to container: Open the VS Code command palette with Ctrl+Shift+P, and run the Deno: Initialize Workspace Configuration command.

Crystal

With OMZ and selecting name of the container

docker run -d -it -v ~/docker-polyglot-world:/docker-polyglot-world --name docker-polyglot-world-crystal crystallang/crystal:1.6 /docker-polyglot-world/utilities/use-omz.sh

Testing

Unit tests

Python (Pytest in Dev Container)

cd python
pip install -r requirements.txt -r requirements-local.txt
pytest

Go (Go test in Dev Container)

cd go
go test

Nodejs (Jest in Dev Container)

cd nodejs
yarn test

Rust (Rust test in Dev Container)

cd rust/hello-world
cargo test

Deno (Deno test in Dev Container)

cd deno
deno test --allow-sys

Crystal (Crystal test in Dev Container)

cd crystal
crystal spec *_spec.cr

API testing

Postman

  • Install Postman
  • Import polyglot-world.postman_collection.json
  • Run collection

Newman

  • Use Nodejs dev container
  • npm install -g newman
  • Collection: newman run polyglot-world.postman_collection.json
  • Collection with Cloudflare Tunnel: newman run polyglot-world.postman_collection.js=on --env-var hostname=<<YOUR CLOUDFLARE TUNNEL HOSTNAME>>
  • Number and specific tests: newman run polyglot-world.postman_collection.json -n 1 --folder Python

Supercharge With Cloudflare Tunnel (Optional)

  • Create Cloudflare account
  • Add your domain to Cloudflare
  • Enable Cloudflare Tunnel
    • From the Cloudflare dashboard, click on the Zero Trust menu item
    • Click on the Access menu item
    • Click on Tunnels menu item
  • Terraform Cloud
    • Create Terraform Cloud account
    • In Terraform Cloud, create a new workspace
      • Choose CLI-driven workflow
      • Name: docker-polyglot-world
    • Open Workspace settings and set Execution Mode to Local
  • Copy .env-template to .env and set the variables within
    • In Terraform Cloud, click on your user profile icon and select User Settings
    • Click on Tokens menu item
    • Click on Create an API Token button
    • Copy the token to the .env file
  • Copy secret-template.tfvars to secret.tfvars and set the variables within
  • docker compose --profile cloudflare-tunnel up --build
  • If you want to remove Cloudflare Tunnel: docker compose --profile destroy-cloudflare-tunnel up

Inspired By

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published