Skip to content

Commit

Permalink
chore(ci): set runner image to fixed ubuntu version
Browse files Browse the repository at this point in the history
See actions/runner-images#10636
Better be specific from now on
  • Loading branch information
ptitmouton committed Dec 28, 2024
1 parent 60eafeb commit 358cb11
Show file tree
Hide file tree
Showing 13 changed files with 239 additions and 24 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/__deploy_dockerfile.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ on:
jobs:
build-image:
name: 'Build image from Dockerfile'
runs-on: ubuntu-latest
runs-on: ubuntu-24.04
env:
IMAGE_NAME: '${{ inputs.name }}'
RELEASE_NAME: '${{ inputs.releaseName }}'
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/chromatic.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ env:
jobs:
storybook-chromatic:
name: Storybook visual testing on Chromatic
runs-on: ubuntu-latest
runs-on: ubuntu-24.04
steps:
- name: Checkout Repo
uses: actions/checkout@v4
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ env:
jobs:
lint:
name: Lint Code
runs-on: ubuntu-latest
runs-on: ubuntu-24.04
steps:
- name: Checkout Repo
uses: actions/checkout@v4
Expand Down Expand Up @@ -53,7 +53,7 @@ jobs:

tests:
name: Run tests
runs-on: ubuntu-latest
runs-on: ubuntu-24.04
services:
postgres:
image: postgres:latest
Expand Down Expand Up @@ -171,7 +171,7 @@ jobs:

check-build:
name: Check the projects build
runs-on: ubuntu-latest
runs-on: ubuntu-24.04
steps:
- name: Checkout Repo
uses: actions/checkout@v4
Expand Down Expand Up @@ -260,7 +260,7 @@ jobs:
project: ['core', 'web']
exclude:
- environment: ${{ github.ref_name == 'main' && 'preview' || 'staging' }}
runs-on: ubuntu-latest
runs-on: ubuntu-24.04
steps:
# Sentry does need a repository it seems
- name: Checkout Repo
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/e2e.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
test:
name: Run Playwright tests
timeout-minutes: 60
runs-on: ubuntu-latest
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@v4
with:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/gh-pages.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ on:
jobs:
publish-storybook-page:
name: Publish Hubert Storybook as Github Page
runs-on: ubuntu-latest
runs-on: ubuntu-24.04
steps:
- name: Checkout Repo
uses: actions/checkout@v4
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/pr-target.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ on:

jobs:
add-reviews:
runs-on: ubuntu-latest
runs-on: ubuntu-24.04
steps:
- uses: kentaro-m/auto-assign-action@v2.0.0
2 changes: 1 addition & 1 deletion .github/workflows/release-create.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ on:
jobs:
create-release:
name: 'Create release'
runs-on: ubuntu-latest
runs-on: ubuntu-24.04
outputs:
version: ${{ steps.bump.outputs.version }}
steps:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release-push.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ jobs:
strategy:
matrix:
project: ['core', 'web']
runs-on: ubuntu-latest
runs-on: ubuntu-24.04
steps:
# Sentry does need a repository it seems
- name: Checkout Repo
Expand Down
4 changes: 3 additions & 1 deletion apps/core-api/config/runtime.exs
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ defmodule SystemConfig do

defp default("COCKPIT_ADMIN_API_USERNAME", _), do: "admin"
defp default("COCKPIT_ADMIN_API_KEY", env) when env in [:dev, :test], do: "test123"
defp default("COCKPIT_ENDPOINT", _), do: "http://localhost:4040"

defp default("SENTRY_DSN", _), do: nil
defp default("CLOUDIMAGE_TOKEN", env) when env in [:dev, :test], do: "123"
Expand Down Expand Up @@ -239,7 +240,8 @@ config :lotta, LottaWeb.Auth.AccessToken,
secret_key: SystemConfig.get("SECRET_KEY_JWT"),
issuer: "lotta"

config :lotta, :admin_api_key,
config :lotta, :cockpit,
endpoint: SystemConfig.get("COCKPIT_ENDPOINT"),
username: SystemConfig.get("COCKPIT_ADMIN_API_USERNAME"),
password: SystemConfig.get("COCKPIT_ADMIN_API_KEY")

Expand Down
109 changes: 109 additions & 0 deletions apps/core-api/lib/lotta/administration/Cockpit.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
defmodule Lotta.Administration.Cockpit do
@moduledoc """
Interact with Cockpit for the administration of Lotta.
"""
use Tesla

alias Lotta.Accounts.User
alias LottaWeb.Urls
alias Lotta.Tenants.Feedback
alias Lotta.{Tenants, Repo}

require Logger

@doc """
Forward a feedback
"""
@spec send_feedback(Feedback.t()) :: :ok | {:error, any()}
def send_feedback(feedback) do
feedback = Repo.preload(feedback, :user)

tenant =
feedback
|> Ecto.get_meta(:prefix)
|> Tenants.get_tenant_by_prefix()

create_client()
|> post("/api/feedback", %{
feedback: %{
tenant_id: tenant.id,
name: feedback.user.name,
email: feedback.user.email,
title: "FWD: #{feedback.topic}",
message: """
Ein Admin hat eben Feedback für #{tenant.title} erstellt.
Nutzername: #{feedback.user.name}
Email: #{feedback.user.email}
Kunde: #{tenant.title} (#{Urls.get_tenant_url(tenant)})
#{feedback.topic}
---
#{feedback.content}
"""
}
})
|> case do
{_, %{status: status}} when status >= 200 and status < 300 ->
:ok

{:ok, %{status: status, body: body}} ->
Logger.error("Failed to send message: #{inspect({status, body})}")
{:error, status}

{:error, reason} ->
Logger.error("Failed to send feedback: #{inspect(reason)}")
{:error, reason}
end
end

@doc """
Send a message to Lotta
"""
@spec send_message(User.t(), topic :: String.t(), message :: String.t()) ::
:ok | {:error, any()}
def send_message(user, topic, message) do
tenant = Tenants.get_tenant_by_prefix(Ecto.get_meta(user, :prefix))

create_client()
|> post("/api/feedback", %{
feedback: %{
tenant_id: tenant.id,
name: user.name,
email: user.email,
title: topic,
message: message
}
})
|> case do
{_, %{status: status}} when status >= 200 and status < 300 ->
:ok

{:ok, %{status: status, body: body}} ->
Logger.error("Failed to send message: #{inspect({status, body})}")
{:error, status}

{:error, reason} ->
Logger.error("Failed to send message: #{inspect(reason)}")
{:error, reason}
end
end

defp create_client() do
middleware = [
Tesla.Middleware.OpenTelemetry,
{Tesla.Middleware.BaseUrl, config(:endpoint)},
Tesla.Middleware.PathParams,
Tesla.Middleware.JSON,
{Tesla.Middleware.BasicAuth, username: config(:username), password: config(:password)}
]

Tesla.client(middleware)
end

defp config(key), do: Keyword.get(config(), key)

defp config() do
Application.fetch_env!(:lotta, :cockpit)
end
end
32 changes: 24 additions & 8 deletions apps/core-api/lib/lotta/tenants.ex
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ defmodule Lotta.Tenants do

import Ecto.Query

alias Lotta.Administration.Cockpit
alias LottaWeb.Schema.Tenants.Tenant
alias Ecto.Multi
alias Lotta.{Email, Mailer, Repo, Storage}
Expand Down Expand Up @@ -502,9 +503,17 @@ defmodule Lotta.Tenants do
Ecto.Multi.new()
|> Ecto.Multi.update(:feedback, Ecto.Changeset.change(feedback, is_forwarded: true))
|> Ecto.Multi.run(:send_feedback, fn _repo, %{feedback: feedback} ->
feedback
|> Email.send_feedback_to_lotta_mail(user, message)
|> Mailer.deliver_now()
case Cockpit.send_feedback(feedback) do
:ok ->
{:ok, feedback}

{:error, error} ->
Logger.error("Error sending feedback to lotta team:", %{sentry: %{error: error}})

feedback
|> Email.send_feedback_to_lotta_mail(user, message)
|> Mailer.deliver_now()
end
end)
|> Repo.transaction()
|> then(fn
Expand All @@ -523,16 +532,23 @@ defmodule Lotta.Tenants do
@spec create_feedback_for_lotta(binary(), binary() | nil, User.t()) ::
:ok | :error
def create_feedback_for_lotta(subject, message, user) do
Email.create_feedback_for_lotta(subject, message, user)
|> Mailer.deliver_now()
|> case do
{:ok, _} ->
case Cockpit.send_message(user, subject, message) do
:ok ->
:ok

{:error, error} ->
Logger.error("Error sending feedback to lotta team:", %{sentry: %{error: error}})

:error
Email.create_feedback_for_lotta(subject, message, user)
|> Mailer.deliver_now()
|> case do
{:ok, _} ->
:ok

{:error, error} ->
Logger.error("Error sending feedback to lotta team:", %{sentry: %{error: error}})
:error
end
end
end

Expand Down
6 changes: 5 additions & 1 deletion apps/core-api/lib/lotta_web/router.ex
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,10 @@ defmodule LottaWeb.Router do
def absinthe_before_send(conn, _blueprint), do: conn

defp admin_auth(conn, _opts) do
Plug.BasicAuth.basic_auth(conn, Application.get_env(:lotta, :admin_api_key))
conn
|> Plug.BasicAuth.basic_auth(
Application.get_env(:lotta, :cockpit)
|> Keyword.take([:username, :password])
)
end
end
Loading

0 comments on commit 358cb11

Please sign in to comment.