Erlang OTP: Distributed & Fault-Tolerant Systems Programming · บทเรียน

การสร้างรีลีส Erlang

ใช้เครื่องมืออย่าง rebar3 และ relx เพื่อรวมแอปพลิเคชัน Erlang สิ่งที่ต้องพึ่งพา และรันไทม์ Erlang เป็นรีลีสที่ทำงานได้ในตัว

บทเรียน 1 จาก 411 ขั้นตอน

การสร้างรีลีส Erlang เป็นบทเรียน Erlang OTP: Distributed & Fault-Tolerant Systems Programming ฟรีบน CoddyKit นี่คือบทเรียนที่ 1 จากทั้งหมด 4 บทเรียน คุณสามารถอ่านบทเรียนทั้งหมดด้านล่างฟรี — จากนั้นลองปฏิบัติด้วยตัวคุณเองในเบราว์เซอร์พร้อมตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7 บทเรียนนี้เป็นส่วนหนึ่งของเส้นทางการเรียน Erlang OTP: Distributed & Fault-Tolerant Systems Programming และความก้าวหน้าของคุณจะซิงค์ข้ามเว็บและแอป CoddyKit คอร์ส Erlang OTP: Distributed & Fault-Tolerant Systems Programming มีบทเรียนทั้งหมด 4 บทเรียน

บางส่วนของบทเรียนนี้ยังไม่ได้รับการแปล และแสดงเป็นภาษาอังกฤษ

What are Erlang Releases?

When you develop an Erlang application, it's a collection of modules and configuration files. To deploy it, you need to package it all up.

An Erlang Release is a self-contained, deployable package of your application, its dependencies, and optionally, a specific version of the Erlang Runtime System (ERTS).

  • It's like a standalone executable for your Erlang system.
  • It simplifies deployment by bundling everything needed to run.

Benefits of a Release

Why go through the effort of creating a release? Releases offer significant advantages for production systems:

  • Self-contained: Includes all necessary Erlang libraries and even the Erlang VM itself.
  • Simplified Deployment: Just copy the release folder to a server and start it.
  • Version Management: Each release has a clear version number, making upgrades and rollbacks easier.
  • Foundation for Live Upgrades: Releases are essential for Erlang's famous 'hot code loading' feature (covered in a later lesson!).

Meet rebar3

Building Erlang applications and releases manually can be complex. Fortunately, we have rebar3!

rebar3 is the standard build tool for Erlang. It handles:

  • Project creation and management
  • Dependency resolution
  • Compilation
  • Testing
  • And, crucially for this lesson, creating releases.

It streamlines the entire development and deployment workflow.

Your Erlang Application Code

Let's start with a very simple Erlang module. In a real application, this would be part of your overall system logic.

For demonstration, we'll create a module with a main/0 function, which can be run directly. This module will be included in our release.

-module(my_release_app).
-export([main/0]).

main() ->
    io:format("Hello from my Erlang release application!~n").

The Application Resource File

Every Erlang application has an application resource file (.app or .app.src). This file defines metadata about your application, such as its version, description, and which modules it depends on.

rebar3 uses the .app.src file to generate the final .app file during the build process.

{application, my_release_app,
 [{description, "My simple release app"},
  {vsn, "0.1.0"},
  {registered, []},
  {applications, [
    kernel,
    stdlib
  ]},
  {mod, {my_release_app, []}},
  {env, []}
 ]}.

Configuring the Release

To tell rebar3 how to build your release, you add a relx section to your rebar.config file. This configuration specifies:

  • The name and version of your release.
  • Which applications to include.
  • If the Erlang Runtime System (ERTS) should be bundled.

For development, we often don't include ERTS to save space.

{apps, [my_release_app]}.

{relx, [{release, {my_release_app, "0.1.0"}, [my_release_app]},
        {dev_mode, true},
        {include_erts, false},
        {extended_start_script, true}]}.

Building Your Release Bundle

With your application code, .app.src, and rebar.config in place, building the release is straightforward. rebar3 will compile your code, fetch dependencies, and package everything into a single directory.

This command does all the heavy lifting:

rebar3 release

Inside the Release Package

After running rebar3 release, you'll find your release in _build/default/rel/my_release_app/. The structure typically includes:

  • bin/: Contains the start script for your application.
  • lib/: All your application's compiled code and dependencies.
  • releases/: Release definitions and version information.
  • erts/: (Optional) The Erlang Runtime System if include_erts was true.

This organized structure makes deployment predictable and reliable.

Running Your Packaged App

Once built, you can start your Erlang application by executing the generated start script. This script handles starting the Erlang VM and loading your application.

Navigate to the release directory and use the bin/<release_name> script.

For our example, you would run (in a shell, not runnable in this environment):

_build/default/rel/my_release_app/bin/my_release_app start

Release Benefits Check

Creating an Erlang release is a crucial step for deployment. Which of the following are primary benefits of packaging an Erlang application as a release?

Recap: Erlang Releases

You've taken a big step towards deploying Erlang applications!

  • Erlang Releases package your app, its dependencies, and optionally ERTS.
  • rebar3 is the essential tool for building and managing releases.
  • The .app.src and rebar.config files define your application and release.
  • Releases simplify deployment, versioning, and enable powerful features like live upgrades.

Next, we'll dive into the fascinating world of hot code loading and how to perform live upgrades on running systems!

เริ่มต้นได้ฟรี

เรียนรู้ Erlang ด้วย AI tutor — ฟรี

เขียนและเรียกใช้โค้ดจริงในเบราว์เซอร์ของคุณ รับความช่วยเหลือทันทีจาก AI tutor 24/7 และเรียนรู้ต่อจากที่คุณหยุดบนเว็บหรือในแอป

คอร์ส
12
บทเรียน
48

คำถามที่พบบ่อย

บทเรียน “การสร้างรีลีส Erlang” ฟรีหรือไม่

ใช่ — ข้อความเต็มของ “การสร้างรีลีส Erlang” ฟรีให้อ่านที่นี่บนเว็บ เพื่อปฏิบัติแบบโต้ตอบ (ตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7) และปลดล็อคส่วนที่เหลือของคอร์ส Erlang OTP: Distributed & Fault-Tolerant Systems Programming ให้อัปเกรดเป็น CoddyKit PRO คอร์ส Erlang OTP: Distributed & Fault-Tolerant Systems Programming มีบทเรียนทั้งหมด 4 บทเรียน

คุณจะเรียนรู้อะไรในบทเรียน “การสร้างรีลีส Erlang”

ใช้เครื่องมืออย่าง rebar3 และ relx เพื่อรวมแอปพลิเคชัน Erlang สิ่งที่ต้องพึ่งพา และรันไทม์ Erlang เป็นรีลีสที่ทำงานได้ในตัว คุณปฏิบัติ Erlang OTP: Distributed & Fault-Tolerant Systems Programming ด้วยโค้ดที่ใช้งานได้จริงที่คุณเรียกใช้โดยตรงในเบราว์เซอร์ และติวเตอร์ AI ตลอด 24/7 ตอบคำถามของคุณขณะที่คุณไปผ่านบทเรียน

คุณต้องมีประสบการณ์ก่อนที่จะเริ่มเรียน Erlang OTP: Distributed & Fault-Tolerant Systems Programming หรือไม่

ไม่จำเป็นต้องมีประสบการณ์มาก่อน Erlang OTP: Distributed & Fault-Tolerant Systems Programming บน CoddyKit ออกแบบมาสำหรับผู้เริ่มต้นไปจนถึงผู้เรียนขั้นสูง คุณสามารถเริ่มต้นที่นี่หรือเริ่มจากตัวแรกและเรียนด้วยความเร็วของคุณเอง นี่คือบทเรียนที่ 1 จากทั้งหมด 4 บทเรียน

บทเรียน “การสร้างรีลีส Erlang” ใช้เวลานานแค่ไหน

บทเรียน CoddyKit ส่วนใหญ่ใช้เวลาประมาณ 5–10 นาที แต่ละบทเรียนจึงสั้นและเป็นแบบโต้ตอบ คุณสามารถก้าวหน้าอย่างต่อเนื่องและกลับมาเรียนต่อจากตรงที่เพิ่งหยุดบนเว็บและแอปได้เลย

ฉันเขียนและรันโค้ดในบทเรียน Erlang OTP: Distributed & Fault-Tolerant Systems Programming นี้ได้ไหม

ได้ บทเรียน Erlang OTP: Distributed & Fault-Tolerant Systems Programming ทุกบทมีตัวแก้ไขโค้ดในตัว คุณจึงเขียนและรันโค้ดจริงได้เลยในเบราว์เซอร์ และได้รับข้อเสนอแนะจาก AI ในทันที — ไม่ต้องติดตั้งในเครื่องของคุณ

บทเรียนทั้งหมดในหลักสูตรนี้

  1. การสร้างรีลีส Erlang
  2. การโหลดและอัปเกรดโค้ดขณะทำงาน
  3. การกำหนดเวอร์ชันรีลีสและการนำไปใช้งาน
  4. การกำหนดค่ารุ่นเผยแพร่และสคริปต์เริ่มระบบ
← กลับไปที่ Erlang OTP: Distributed & Fault-Tolerant Systems Programming