Criação de Releases com Mix Release
Crie releases autocontidos e prontos para implantação da sua aplicação Elixir usando `mix release`.
Criação de Releases com Mix Release é uma aula grátis de Elixir & Phoenix: Scalable Backend Development no CoddyKit. Esta é a aula 1 de 4. Você pode ler a aula completa abaixo gratuitamente — depois pratica ao vivo no navegador com um editor de código integrado e um tutor de IA 24/7. Faz parte do caminho de aprendizado de Elixir & Phoenix: Scalable Backend Development, e seu progresso é sincronizado entre a web e o app CoddyKit. O curso de Elixir & Phoenix: Scalable Backend Development inclui 4 aulas no total.
Partes desta aula ainda não foram traduzidas e aparecem em inglês.
Welcome to Elixir Releases
When you develop an Elixir application, you often run it with mix run --no-halt. This is great for development, but not ideal for production.
For deployment, we need a self-contained package that can run independently, without needing the Mix build tool or even Elixir's source code on the target machine. This is where releases come in!
Why `mix run` Isn't Enough
Running an application with mix run has a few drawbacks for production:
- It requires the full Mix build tool and your project's source code.
- It uses the development environment configuration by default.
- Startup can be slower as it needs to compile and load dependencies.
- It lacks proper daemonization features for background processes.
Introducing `mix release`
mix release creates an OTP release. Think of it as a complete, self-contained package of your Elixir application and its dependencies.
It includes the Erlang VM, your compiled code, and all necessary scripts to start, stop, and manage your application as a standalone service.
Benefits of Using Releases
Using releases offers several key advantages:
- Self-contained: No need for Mix or Elixir installation on the server.
- Faster Startup: Pre-compiled and optimized for production.
- Production-ready: Designed for daemonization and supervision.
- Hot Code Swapping: Supports upgrading running systems without downtime (advanced).
Generating Your First Release
To create a release, first ensure your project has a supervisor. Most Phoenix projects and projects created with mix new my_app --sup already have one.
Then, simply run the mix release command. This will compile your project and its dependencies for the production environment.
mix new my_release_app --sup
cd my_release_app
mix deps.get
mix releaseExploring the Release Structure
After running mix release, you'll find your release in _build/prod/rel/your_app_name/.
Inside, you'll see a bin directory containing a script to manage your app, lib with all compiled dependencies, and releases with version-specific files.
my_release_app/
├── _build/
│ └── prod/
│ └── rel/
│ └── my_release_app/
│ ├── bin/
│ │ └── my_release_app (start/stop script)
│ ├── lib/
│ ├── releases/
│ └── erts-...
├── config/
├── lib/
└── mix.exsRunning Your Released Application
To start your application from a release, use the generated script in the bin directory. You can start it in the foreground or as a daemon.
For a production environment, you'd typically start it in the background.
# Start in foreground (for testing)
_build/prod/rel/my_release_app/bin/my_release_app start_iex
# Start as daemon (production)
_build/prod/rel/my_release_app/bin/my_release_app start
# Stop a running daemon
_build/prod/rel/my_release_app/bin/my_release_app stopRuntime Configuration with `runtime.exs`
For production deployments, you often need to configure your application based on its environment (e.g., database credentials, API keys).
mix release uses config/runtime.exs, which is executed after the release is built and before the application starts. This is perfect for reading environment variables.
# config/runtime.exs
import Config
config :my_release_app,
database_url: System.get_env("DATABASE_URL"),
api_key: System.get_env("API_KEY")Upgrades and Downgrades (Advanced)
One of the most powerful features of OTP releases is the ability to perform hot code upgrades. This means you can update your running application with new code without stopping it, leading to zero downtime deployments.
While this is an advanced topic, `mix release` lays the groundwork for it by packaging your application in a way that allows for version management and patching.
Release Benefits Check
Which of the following are key benefits of using mix release for deploying an Elixir application?
Recap: Ready for Deployment!
You've learned that mix release is the standard way to package Elixir applications for production. It creates a self-contained, optimized bundle, independent of the Mix toolchain.
Releases offer faster startup, robust daemonization, and support for advanced features like hot code upgrades. Coupled with config/runtime.exs, they provide a powerful and flexible deployment solution.
Perguntas Frequentes
A aula “Criação de Releases com Mix Release” é grátis?
Sim — o texto completo de “Criação de Releases com Mix Release” é grátis para ler aqui na web. Para praticá-la interativamente (um editor de código integrado e um tutor de IA 24/7) e desbloquear o restante do curso de Elixir & Phoenix: Scalable Backend Development, atualize para CoddyKit PRO. O curso de Elixir & Phoenix: Scalable Backend Development inclui 4 aulas no total.
O que vou aprender em “Criação de Releases com Mix Release”?
Crie releases autocontidos e prontos para implantação da sua aplicação Elixir usando `mix release`. Você pratica Elixir & Phoenix: Scalable Backend Development com código prático que executa diretamente no navegador, e um tutor de IA 24/7 responde suas dúvidas enquanto trabalha na aula.
Preciso ter experiência prévia para começar Elixir & Phoenix: Scalable Backend Development?
Nenhuma experiência prévia é necessária. Elixir & Phoenix: Scalable Backend Development no CoddyKit é estruturado para alunos iniciantes até avançados, então você pode começar aqui ou desde o início e aprender no seu ritmo. Esta é a aula 1 de 4.
Quanto tempo leva a aula “Criação de Releases com Mix Release”?
A maioria das aulas CoddyKit leva cerca de 5–10 minutos. Cada uma é compacta e interativa, então você faz progresso constante e retoma exatamente de onde parou entre web e app.
Posso escrever e executar código nesta aula de Elixir & Phoenix: Scalable Backend Development?
Sim. Cada aula de Elixir & Phoenix: Scalable Backend Development inclui um editor de código integrado, então você escreve e executa código real direto no navegador e recebe feedback de IA instantaneamente — nenhuma configuração local necessária.
Todas as aulas deste curso
- Criação de Releases com Mix Release
- Conteinerização com Docker
- Estratégias de Implantação na Nuvem
- Implementações sem Tempo de Inatividade e Atualizações a Quente