Skip to content

Commit

Permalink
Merge pull request #3760 from platformsh/upsun-migrate-languages
Browse files Browse the repository at this point in the history
[Upsun migration] languages section
  • Loading branch information
chadwcarlson committed Feb 14, 2024
2 parents 8a98119 + f04ad3f commit 128b316
Show file tree
Hide file tree
Showing 50 changed files with 5,363 additions and 2,190 deletions.
4 changes: 2 additions & 2 deletions sites/friday/config/_default/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,8 @@ module:
# - "integrations/*"
- "integrations/activity/reference.md"

# - "languages/*"
- "languages/java/frameworks.md"
- "languages/*"
#- "languages/java/frameworks.md"

- "learn/*"

Expand Down
5 changes: 5 additions & 0 deletions sites/friday/src/languages/_index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
title: "Languages"
weight: -90
description: We sure do support a lot of runtimes.
---
120 changes: 120 additions & 0 deletions sites/friday/src/languages/dotnet.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
---
title: "C#/.NET Core"
description: |
{{% vendor/name %}} supports deploying .NET applications by allowing developers to define a build process and pass its variables to the .NET Core build environment.
---

{{% description %}}

## Supported versions

{{% major-minor-versions-note configMinor="true" %}}

{{< image-versions image="dotnet" status="supported" environment="grid" >}}

{{% language-specification type="dotnet" display_name=".Net Core" %}}

```yaml {configFile="app"}
applications:
# The app's name, which must be unique within the project.
<APP_NAME>:
type: 'dotnet:<VERSION_NUMBER>'
```
For example:
```yaml {configFile="app"}
applications:
# The app's name, which must be unique within the project.
app:
type: 'dotnet:{{% latest "dotnet" %}}'
```
## Building the application
To build basic applications in .NET containers, it's enough to use the [`dotnet publish` command](https://docs.microsoft.com/en-us/dotnet/core/tools/dotnet-publish)
with the default [framework-dependent deployment](https://docs.microsoft.com/en-us/dotnet/core/deploying/#publish-framework-dependent):

```yaml {configFile="app"}
applications:
app:
type: 'dotnet:{{% latest "dotnet" %}}'
hooks:
build: |
set -xe
dotnet publish --output "$PLATFORM_OUTPUT_DIR" \
-p:UseRazorBuildServer=false \
-p:UseSharedCompilation=false
```

where `PLATFORM_OUTPUT_DIR` is the output directory for compiled languages available at build time.

Typically, .NET Core builds start a collection of build servers, which are helpful for repeated builds.
On {{% vendor/name %}}, however, if this process isn't disabled,
the build process doesn't finish until the idle timeout is reached.

As a result, you should include `-p` toggles that disable the Razor compiler for dynamic CSHTML pages (`UseRazorBuildServer`)
and the .NET MSBuild compiler (`UseSharedCompilation`).

If you want multiple builds for your application,
make sure to call `dotnet build-server shutdown` at the end of your build hook.

## Running the application

.NET Core applications should be started using the `web.commands.start` directive in `{{< vendor/configfile "app" >}}`.
This ensures that the command starts at the right moment and stops gracefully when a redeployment needs to be executed.
Also, should the program terminate for any reason, it's automatically restarted.
Note that the start command _must_ run in the foreground.

Incoming requests are passed to the application using either a TCP (default) or Unix socket.
The application must use the [appropriate environment variable](../create-apps/app-reference.md#where-to-listen) to determine the URI to listen on.
For a TCP socket ([recommended](https://go.microsoft.com/fwlink/?linkid=874850)), the application must listen on `http://127.0.0.1`,
using the `PORT` environment variable.

There is an Nginx server sitting in front of your application.
Serving static content via Nginx is recommended, as this allows you to control headers (including cache headers)
and also has marginal performance benefits.

Note that HTTPS is also terminated at the Nginx proxy,
so the `app.UseHttpsRedirection();` line in `Startup.cs` should be removed.
To force HTTPS-only, refer to the [routes documentation](../define-routes/https.md#enable-https).

The following example configures an environment to serve the static content folders commonly found in [ASP.NET MVC](https://dotnet.microsoft.com/apps/aspnet/mvc) templates using Nginx,
while routing other traffic to the .NET application.

```yaml {configFile="app"}
applications:
app:
type: 'dotnet:{{% latest "dotnet" %}}'
web:
locations:
"/":
root: "wwwroot"
allow: true
passthru: true
rules:
# Serve these common asset types with customs cache headers.
\.(jpe?g|png|gif|svgz?|css|js|map|ico|bmp|eot|woff2?|otf|ttf)$:
allow: true
expires: 300s
commands:
start: "dotnet WebApplication1.dll"
```

You can also route all requests to the application unconditionally:

```yaml {configFile="app"}
applications:
app:
type: 'dotnet:{{% latest "dotnet" %}}'
web:
locations:
"/":
allow: false
passthru: true
commands:
start: "dotnet WebApplication1.dll"
```

{{< repolist lang="dotnet" displayName=".NET Core" >}}
177 changes: 177 additions & 0 deletions sites/friday/src/languages/elixir.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,177 @@
---
title: "Elixir"
description: "{{% vendor/name %}} supports building and deploying applications written in Elixir. There is no default flavor for the build phase, but you can define it explicitly in your build hook. {{% vendor/name %}} Elixir images support both committed dependencies and download-on-demand. The underlying Erlang version is 22.0.7."
---

{{% description %}}

## Supported versions

{{% major-minor-versions-note configMinor="true" %}}

{{< image-versions image="elixir" status="supported" environment="grid" >}}


{{% language-specification type="elixir" display_name="Elixir" %}}

```yaml {configFile="app"}
applications:
# The app's name, which must be unique within the project.
<APP_NAME>:
type: 'elixir:<VERSION_NUMBER>'
```
For example:
```yaml {configFile="app"}
applications:
# The app's name, which must be unique within the project.
app:
type: 'elixir:{{% latest "elixir" %}}'
```
## Built-in variables
{{% vendor/name %}} exposes relationships and other configuration as [environment variables](../development/variables/_index.md).
Most notably, it allows a program to determine at runtime what HTTP port it should listen on
and what the credentials are to access [other services](../add-services/_index.md).
To get the `PORT` environment variable (the port on which your web application is supposed to listen) you would:

```elixir
String.to_integer(System.get_env("PORT") || "8888")
```

Some of the environment variables are in JSON format and are base64 encoded. You would need to import a JSON parsing library such as [JSON](https://hexdocs.pm/json/readme.html) or [Poison](https://hexdocs.pm/poison/api-reference.html) to read those. (There is an example for doing this to decode the `PLATFORM_RELATIONSHIPS` environment variable in the section [below](#accessing-services-manually).)

{{< note title="Tip">}}
Remember `config/prod.exs` is evaluated at **build time** and has no access to runtime configuration. Use `config/releases.exs` to configure your runtime environment.
{{< /note >}}

## Building and running the application

If you are using Hex to manage your dependencies, you need to specify the `MIX_ENV` environment variable:

```yaml {configFile="app"}
applications:
app:
type: 'elixir:{{% latest "elixir" %}}'
variables:
env:
MIX_ENV: 'prod'
```
The `SECRET_KEY_BASE` variable is generated automatically based on the [`PLATFORM_PROJECT_ENTROPY` variable](../development/variables/use-variables.md#use-provided-variables).
You can change it.

Include in your build hook the steps to retrieve a local Hex and `rebar`, and then run `mix do deps.get, deps.compile, compile` on your application to build a binary.

```yaml {configFile="app"}
applications:
app:
type: 'elixir:{{% latest "elixir" %}}'
hooks:
build: |
mix local.hex --force
mix local.rebar --force
mix do deps.get --only prod, deps.compile, compile
```

{{< note >}}

That build hook works for most cases and assumes that your `mix.exs` file is located at [your app root](../create-apps/app-reference.md#root-directory).

{{< /note >}}

Assuming `mix.exs` is present at your app root and your build hook matches the above,
you can then start it from the `web.commands.start` directive.

The following basic app configuration is sufficient to run most Elixir applications.


```yaml {configFile="app"}
applications:
app:
type: 'elixir:{{% latest "elixir" %}}'
variables:
env:
MIX_ENV: 'prod'
hooks:
build: |
mix local.hex --force
mix local.rebar --force
mix do deps.get --only prod, deps.compile, compile
web:
commands:
start: mix phx.server
locations:
/:
allow: false
passthru: true
```

Note that there is still an Nginx proxy server sitting in front of your application. If desired, certain paths may be served directly by Nginx without hitting your application (for static files, primarily) or you may route all requests to the Elixir application unconditionally, as in the example above.

## Dependencies

The recommended way to handle Elixir dependencies on {{% vendor/name %}} is using Hex.
You can commit a `mix.exs` file in your repository and the system downloads the dependencies in your `deps` section using the build hook above.

```elixir
defp deps do
[
{:platformshconfig, "~> 0.1.0"}
]
end
```

## Accessing Services

{{% access-services version="2" %}}

### Accessing Services Manually

The services configuration is available in the environment variable `PLATFORM_RELATIONSHIPS`.

Given a relationship defined in `{{< vendor/configfile "app" >}}`:

```yaml {configFile="app"}
applications:
app:
type: 'elixir:{{% latest "elixir" %}}'
...
relationships:
postgresdatabase: "dbpostgres:postgresql"
```

Assuming you have in `mix.exs` the Poison library to parse JSON:

```elixir
defp deps do
[
{:poison, "~> 3.0"}
]
end
```

And assuming you use `ecto` you could put in `config/config.exs`:

```elixir
relationships = Poison.decode!(Base.decode64!(System.get_env("PLATFORM_RELATIONSHIPS")))
[postgresql_config | _tail] = relationships["postgresdatabase"]
config :my_app, Repo,
database: postgresql_config["path"],
username: postgresql_config["username"],
password: postgresql_config["password"],
hostname: postgresql_config["host"]
```

and setup Ecto during the deploy hook:

```yaml
deploy: |
mix do ecto.setup
```
Loading

0 comments on commit 128b316

Please sign in to comment.