DEV Community

Hafsa Jabeen
Hafsa Jabeen

Posted on • Originally published at codesphere.com on

How to Deploy Gleam on Codesphere?

How to Deploy Gleam on Codesphere?

Gleam is a newly released language, claimed to be optimized for concurrency and refactoring. It is compact and easy-to-learn (as per the creators you can learn it in an afternoon). This Elm and Rust-inspired language has a compiler that serves as a programming assistant. To sum up some of the features of Gleam, we can say its small surface area gives it the simplicity of Go while also enabling you to leverage Erlang and Elixir tools. In addition, it is type-safe, and functional, as well as highly scalable.

Gleam can run on JS runtimes, which means you can run it anywhere including (but not limited to) mobile devices and browsers. Let’s create a Gleam project for a simple backend web application. Once the project is set up, we'll proceed to deploy it on Codesphere.

Creating a Gleam Project

We are going to work on a simple Gleam backend web application and deploy it on Codesphere. Let’s start by creating a gleam project.

gleam new my_web_app
Enter fullscreen mode Exit fullscreen mode

Replace “my_web_app” with the name you want to give to your project. It will create a Gleam project, you can then run this command to go to your project directory.

cd my_web_app
Enter fullscreen mode Exit fullscreen mode

Now open src/my_web_app.gleam file and write this code.

mport gleam/io
import mist
import gleam/erlang/process
import gleam/bytes_builder
import gleam/http/response.{Response}

pub fn main() {
  let assert Ok(_) =
    web_service
    |> mist.new
    |> mist.port(3000)
    |> mist.start_http
  process.sleep_forever()
}

fn web_service(_request) {
  let body = bytes_builder.from_string("Hello, Gleam!")
  Response(200, [], mist.Bytes(body))
}

Enter fullscreen mode Exit fullscreen mode

Running Gleam on Codesphere

It is pretty straightforward to run gleam on Codesphere. All you have to do is create a ci.yml file in your project directory and replace the contents with this.

prepare:
  steps:
    - command: "nix-env -iA nixpkgs.gleam"
    - command: "nix-env -iA nixpkgs.erlang"
    - command: "nix-env -iA nixpkgs.rebar3"
    - command: gleam add mist gleam_http gleam_erlang
test:
  steps: []
run:
  steps:
    - command: gleam run

Enter fullscreen mode Exit fullscreen mode

This will install Gleam and all the required dependencies like Erlang, Rebar, and Mist to run this web application. Go to CI pipeline, hit prepare and run stages and your Gleam web application will be up and running in no time.

You can access the code here from the GitHub repository.

I hope you enjoyed exploring Gleam as much as I did!

Sentry image

Hands-on debugging session: instrument, monitor, and fix

Join Lazar for a hands-on session where you’ll build it, break it, debug it, and fix it. You’ll set up Sentry, track errors, use Session Replay and Tracing, and leverage some good ol’ AI to find and fix issues fast.

RSVP here →

Top comments (0)

The Most Contextual AI Development Assistant

Pieces.app image

Our centralized storage agent works on-device, unifying various developer tools to proactively capture and enrich useful materials, streamline collaboration, and solve complex problems through a contextual understanding of your unique workflow.

👥 Ideal for solo developers, teams, and cross-company projects

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay