Skip to content

Commit

Permalink
Merge branch 'release/v8.2.10'
Browse files Browse the repository at this point in the history
  • Loading branch information
zacksiri committed Jul 15, 2024
2 parents 95d5d29 + 07b2c90 commit 8638700
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 6 deletions.
4 changes: 2 additions & 2 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,14 @@ runs:
uses: actions/cache@v4
with:
path: ~/.mix
key: ${{ runner.arch }}-alpine-${{ inputs.alpine }}-pakman-8.2.9
key: ${{ runner.arch }}-alpine-${{ inputs.alpine }}-pakman-8.2.10

- name: Install Pakman
if: steps.cache-pakman.outputs.cache-hit != 'true'
run: |
mix local.rebar --force
mix local.hex --force
mix escript.install hex pakman 8.2.9 --force
mix escript.install hex pakman 8.2.10 --force
shell: alpine.sh {0}
env:
MIX_ENV: prod
18 changes: 17 additions & 1 deletion lib/pakman/instellar.ex
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,11 @@ defmodule Pakman.Instellar do
end
end

def create_configuration(token, deployment_id, %{"kits" => kits})
def create_configuration(
token,
deployment_id,
%{"kits" => kits} = configuration
)
when is_list(kits) do
package_token = System.get_env("INSTELLAR_PACKAGE_TOKEN")

Expand All @@ -100,12 +104,24 @@ defmodule Pakman.Instellar do
{"x-instellar-package-token", package_token}
]

sizes = Map.get(configuration, "sizes")

configuration_params = %{
payload: %{
kits: kits
}
}

configuration_params =
if sizes do
payload = configuration_params.payload
payload = Map.put(payload, :sizes, sizes)

Map.put(configuration_params, :payload, payload)
else
configuration_params
end

client()
|> post(
"/publish/deployments/#{deployment_id}/configurations",
Expand Down
2 changes: 1 addition & 1 deletion mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ defmodule Pakman.MixProject do
def project do
[
app: :pakman,
version: "8.2.9",
version: "8.2.10",
elixir: "~> 1.13",
elixirc_paths: elixirc_paths(Mix.env()),
start_permanent: Mix.env() == :prod,
Expand Down
6 changes: 6 additions & 0 deletions test/fixtures/rails.yml
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,12 @@ hook:
rc-service locomo stop
rc-update locomo rdio
sizes:
- name: medium
allocation:
cpu: 1
memory: 1

kits:
- name: web
description: "web service"
Expand Down
44 changes: 42 additions & 2 deletions test/pakman/instellar_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,44 @@ defmodule Pakman.InstellarTest do
System.put_env("INSTELLAR_PACKAGE_TOKEN", "somepackage")
System.put_env("INSTELLAR_ENDPOINT", "http://localhost:#{bypass.port}")

with_kits = YamlElixir.read_from_file!("test/fixtures/rails.yml")
with_kits_and_sizes = YamlElixir.read_from_file!("test/fixtures/rails.yml")
with_kits = YamlElixir.read_from_file!("test/fixtures/laravel.yml")

{:ok, bypass: bypass, config_with_kits: with_kits}
{:ok,
bypass: bypass,
config_with_kits: with_kits,
config_with_kits_and_sizes: with_kits_and_sizes}
end

describe "create_configuration" do
test "calls instellar to create configuration", %{
bypass: bypass,
config_with_kits_and_sizes: config
} do
Bypass.expect_once(
bypass,
"POST",
"/publish/deployments/1/configurations",
fn conn ->
{:ok, body, _} = Plug.Conn.read_body(conn)

assert %{"configuration" => %{"payload" => payload}} =
Jason.decode!(body)

assert %{"kits" => kits, "sizes" => sizes} = payload

assert Enum.count(sizes) == 1

conn
|> Plug.Conn.put_resp_header("content-type", "application/json")
|> Plug.Conn.resp(201, Jason.encode!(%{data: %{id: 1}}))
end
)

{:ok, :created, _} = Instellar.create_configuration("token", 1, config)
end

test "configuration without size", %{
bypass: bypass,
config_with_kits: config
} do
Expand All @@ -24,6 +55,15 @@ defmodule Pakman.InstellarTest do
"POST",
"/publish/deployments/1/configurations",
fn conn ->
{:ok, body, _} = Plug.Conn.read_body(conn)

assert %{"configuration" => %{"payload" => payload}} =
Jason.decode!(body)

assert %{"kits" => kits} = payload

assert is_nil(payload["sizes"])

conn
|> Plug.Conn.put_resp_header("content-type", "application/json")
|> Plug.Conn.resp(201, Jason.encode!(%{data: %{id: 1}}))
Expand Down

0 comments on commit 8638700

Please sign in to comment.