{"id":13289017,"url":"https://github.com/dbroeglin/azure-rails-starter","last_synced_at":"2025-08-24T13:40:30.548Z","repository":{"id":230460957,"uuid":"779432591","full_name":"dbroeglin/azure-rails-starter","owner":"dbroeglin","description":"Sample Ruby on Rails app deployed (Bicep) on Azure Container App with PostgreSQL","archived":false,"fork":false,"pushed_at":"2024-11-16T17:07:29.000Z","size":237,"stargazers_count":5,"open_issues_count":1,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-11-16T17:18:01.281Z","etag":null,"topics":["azd-templates","azure","azure-devops","azure-postgres","devcontainer","github","rails","ruby","ruby-on-rails"],"latest_commit_sha":null,"homepage":"","language":"Bicep","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/dbroeglin.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-03-29T20:35:01.000Z","updated_at":"2024-11-16T17:07:33.000Z","dependencies_parsed_at":"2024-10-23T09:30:58.925Z","dependency_job_id":"f64cd4a3-039c-466f-8b65-9857ff1a01d9","html_url":"https://github.com/dbroeglin/azure-rails-starter","commit_stats":null,"previous_names":["dbroeglin/azure-rails-demo","dbroeglin/azure-rails-starter"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dbroeglin%2Fazure-rails-starter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dbroeglin%2Fazure-rails-starter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dbroeglin%2Fazure-rails-starter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dbroeglin%2Fazure-rails-starter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dbroeglin","download_url":"https://codeload.github.com/dbroeglin/azure-rails-starter/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":227750185,"owners_count":17814129,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["azd-templates","azure","azure-devops","azure-postgres","devcontainer","github","rails","ruby","ruby-on-rails"],"created_at":"2024-07-29T17:00:18.055Z","updated_at":"2024-12-02T15:16:24.457Z","avatar_url":"https://github.com/dbroeglin.png","language":"Bicep","funding_links":[],"categories":[],"sub_categories":[],"readme":"---\nname: Azure Rails Starter\ndescription: Sample Rails application deployed through Azure Developer CLI (azd) on Azure Container App and Azure Database for PostgreSQL\nlanguages:\n- ruby\n- bicep\n- azdeveloper\nproducts:\n- azure-container-apps\n- azure-database-postgresql\n- azure-key-vault\n- azure\npage_type: sample\nurlFragment: azure-rails-starter\n---\n\n# Deploy a Rails (Ruby) web app with PostgreSQL In Azure Container Apps \n\n\n[![Open in GitHub Codespaces](https://github.com/codespaces/badge.svg)](https://codespaces.new/dbroeglin/azure-rails-starter?quickstart=1)\n\nThis is a starter blueprint for getting your Rails application up and running on Azure using [Azure Developer CLI](https://learn.microsoft.com/en-us/azure/developer/azure-developer-cli/overview) (azd). The Rails application is deployed in an Azure Container App and uses an Azure Postgresql database. The starter uses Infrastructure as Code assets in [Bicep](https://aka.ms/bicep) to get your application up and running quickly.\n\n![Azure Rails Starter Overview](assets/Azure%20Rails%20Starter%20Overview.png)\n\nThe following assets have been provided:\n\n- Infrastructure-as-code (IaC) Bicep files under the `infra` folder that demonstrate how to provision resources and setup resource tagging for azd.\n- A [dev container](https://containers.dev) configuration file under the `.devcontainer` directory that installs infrastructure tooling by default. This can be readily used to create cloud-hosted developer environments such as [GitHub Codespaces](https://aka.ms/codespaces).\n  - Ruby 3.3.0 \n  - GitHub Copilot\n  - Postgresql running in a container (for development)\n  - Redis running in a container (for development)\n- Continuous deployment workflows for CI providers such as GitHub Actions under the `.github` directory, and Azure Pipelines under the `.azdo` directory that work for most use-cases.\n- A freshly created Rails 7.1.3 application under directory `src`.\n\n\n### Getting the Rails app up and running in Azure\n\nJust run `azd up` to run the end-to-end infrastructure provisioning (`azd provision`) and deployment (`azd deploy`) flow. Visit the service endpoint listed to see your application up-and-running!\n\nQuick start:\n\n```bash\nSECRET_KEY_BASE=\"$(src/bin/rails secret)\" \\\nRAILS_MASTER_KEY=\"$(cat src/config/master.key)\" \\\nazd up\n```\n\n## Additional Details\n\nThe following section examines different concepts that help tie in application and infrastructure.\n\n### Application settings\n\nIt is recommended to have application settings managed in Azure, separating configuration from code. Typically, the service host allows for application settings to be defined.\n\n- Application settings should be defined on the Bicep resource for the Azure Container App. See [main.bicep](./infra/rails.bicep#L43) for an example setting environment variables and using secrets stored in Azure Key Vault.\n- Environment variables for your developer environment (Dev Containers or Codespaces) can be defined in [.decontainer/Dockerfile](.devcontainer/Dockerfile).\n\n### Managed identities\n\n[Managed identities](https://learn.microsoft.com/en-us/azure/active-directory/managed-identities-azure-resources/overview) allows you to secure communication between services. This is done without having the need for you to manage any credentials. It is used between Azure Container Apps and Azure Key Vault to automatically retrieve secrets.s\n\n### Azure Key Vault\n\n[Azure Key Vault](https://learn.microsoft.com/en-us/azure/key-vault/general/overview) allows you to store secrets securely. Your application can access these secrets securely through the use of managed identities.\n\n## Getting started with Rails development\n\n### Provisioning \u0026 deploying with Azure Developer CLI\n\nWhen changes are made, use azd to validate and apply your changes in Azure, to ensure that they are working as expected:\n\n- Run `azd up` to validate both infrastructure and application code changes.\n- Run `azd deploy` to validate application code changes only.\n\n### Running Rails commands\n\nMove to the `src` directory:\n\n```bash\ncd src\n```\n\nRun the Rails server:\n\n```bash\nbin/rails server\n```\n\nRun the Rails console:\n\n```bash\nbin/rails console \n```\n\nRun the Rails migration command:\n\n```bash\nbin/rails db:migrate\n```\n\n### Connecting to the Postgresql database\n\n```bash\npsql $DATABASE_URL\n```\n\n### Re-creating the Rails application\n\nThe rails application has been created by running the following command:\n\n```bash\nrails new --database=postgresql --name=azure-rails-starter src\nrm -rf src/.git\ncd src\nsed -i '' 's/# root.*$/root \"home#index\"/' config/routes.rb\nsed -i '' '/azure_rails_starter_production$/,/DATABASE_PASSWORD/c\\\n    url: \u003c%= ENV[\"DATABASE_URL\"] %\u003e\n' config/database.yml\ncat \u003e app/controllers/home_controller.rb \u003c\u003cEOF\nclass HomeController \u003c ApplicationController\n  def index\n    render plain: 'Hello World!'\n  end\nend\nEOF\n```\n\n### Obtain a shell in the Azure Container App \n\n```bash\n. ./.env\naz containerapp exec --name $SERVICE_RAILS_NAME --resource-group $AZURE_RESOURCE_GROUP_NAME\n```\n\nThis can be useful to apply `bin/rails db:migrate` commands or access the Rails console through `bin/rails console`. Note that the default `bin/docker-entrypoint` already runs `bin/rails db:prepare`.\n\n### Clean up resources\n\n```bash\n    azd down\n```\n\nIf you want to make sure you can recreate the same environment, KeyVault needs to be purged:\n\n```bash\n    azd down --purge\n```\n\n## Security consideration\n\nIn this repository `src/config/master.key` has been committed to simplify deployment of the sample application. If you plan on building from the sample app please delete `config/master.key` and `config/credentials.yml.enc`. Commit the changes. Then run `bin/rails credentials:edit`. \n\n## Getting help\n\nSometimes deployment fails because the PostgreSQL resource is still busy and extensions cannot yet be applied. In a case like that just re-run the deployment.\n\nIf you're working with this project and running into issues, please post an Issue by clicking on the link above.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdbroeglin%2Fazure-rails-starter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdbroeglin%2Fazure-rails-starter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdbroeglin%2Fazure-rails-starter/lists"}