Skip to content

Commit

Permalink
Workflows for deploying to on prem servers (#533)
Browse files Browse the repository at this point in the history
* Add deploy workflows, remove splunk logger backend from prod config

* Add formatting for console logs

* Change console log level for prod to info. Add usage of :code.priv_dir/1 for stops.json

* add back call to Jason.decode

* update cpu and memory values
  • Loading branch information
PaulJKim authored Oct 19, 2022
1 parent b3ea02b commit feaf15a
Show file tree
Hide file tree
Showing 6 changed files with 85 additions and 12 deletions.
36 changes: 36 additions & 0 deletions .github/workflows/dev.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: Deploy to Dev

on:
workflow_dispatch:
push:
branches: [main]

jobs:
Build:
runs-on: windows-2019
steps:
- name: Checkout repository
uses: actions/checkout@v2
- uses: mbta/actions/build-push-ecr@v1
id: build-push
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
docker-repo: ${{ secrets.DOCKER_REPO }}
deploy:
name: Deploy
needs: build
uses: mbta/workflows/.github/workflows/deploy-on-prem.yml@main
with:
app-name: realtime-signs
environment: dev
on-prem-cluster: hsctd-dev-managers
splunk-index: realtime-signs-dev
task-cpu: .5
task-memory: 1024M
task-port: 80
secrets:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
docker-repo: ${{ secrets.DOCKER_REPO }}
slack-webhook: ${{ secrets.SLACK_WEBHOOK }}
22 changes: 22 additions & 0 deletions .github/workflows/prod.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: Deploy to Prod

on:
workflow_dispatch:

jobs:
deploy:
name: Deploy
uses: mbta/workflows/.github/workflows/deploy-on-prem.yml@main
with:
app-name: realtime-signs
environment: prod
on-prem-cluster: hsctd-prod-managers
splunk-index: realtime-signs-prod
task-cpu: .5
task-memory: 1024M
task-port: 80
secrets:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
docker-repo: ${{ secrets.DOCKER_REPO }}
slack-webhook: ${{ secrets.SLACK_WEBHOOK }}
4 changes: 4 additions & 0 deletions config/config.exs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ config :ex_aws,

config :logger, backends: [:console]

config :logger, :console,
format: "$dateT$time [$level]$levelpad node=$node $metadata$message\n",
metadata: [:request_id]

config :ehmon, :report_mf, {:ehmon, :info_report}

config :sentry, json_library: Jason
Expand Down
13 changes: 2 additions & 11 deletions config/prod.exs
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,9 @@ config :sentry,
},
included_environments: [:prod]

config :logger,
backends: [{Logger.Backend.Splunk, :splunk}, :console]
config :logger, backends: [:console]

config :logger, :console, level: :warn

config :logger, :splunk,
connector: Logger.Backend.Splunk.Output.Http,
host: 'https://http-inputs-mbta.splunkcloud.com/services/collector/event',
token: {:system, "PROD_SIGNS_SPLUNK_TOKEN"},
format: "$dateT$time [$level]$levelpad node=$node $metadata$message\n",
metadata: [:request_id],
max_buffer: 100
config :logger, :console, level: :info

config :realtime_signs,
external_config_getter: ExternalConfig.S3,
Expand Down
15 changes: 15 additions & 0 deletions config/runtime.exs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,21 @@ if config_env() == :prod do
config :realtime_signs, RealtimeSignsWeb.Endpoint, secret_key_base: System.fetch_env!("SECRET_KEY_BASE")
end

# For maintaining backwards compatibility with opstech3
splunk_token = System.get_env("PROD_SIGNS_SPLUNK_TOKEN", "")

if config_env() == :prod and splunk_token != "" do
config :logger, backends: [Logger.Backend.Splunk, :console]

config :logger, :splunk,
connector: Logger.Backend.Splunk.Output.Http,
host: 'https://http-inputs-mbta.splunkcloud.com/services/collector/event',
token: splunk_token,
format: "$dateT$time [$level]$levelpad node=$node $metadata$message\n",
metadata: [:request_id],
max_buffer: 100
end

if System.get_env("DRY_RUN") == "true" do
config :realtime_signs, sign_updater_mod: PaEss.Logger
end
7 changes: 6 additions & 1 deletion lib/engine/alerts/station_config.ex
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@ defmodule Engine.Alerts.StationConfig do
defstruct [:stop_to_station, :station_to_stops, :station_neighbors]

def load_config do
stops_data = File.read!("priv/stops.json") |> Jason.decode!()
stops_data =
:realtime_signs
|> :code.priv_dir()
|> Path.join("stops.json")
|> File.read!()
|> Jason.decode!()

{stop_to_station, station_to_stops, station_neighbors} =
Enum.reduce(stops_data, {%{}, %{}, %{}}, fn {_segment, stops},
Expand Down

0 comments on commit feaf15a

Please sign in to comment.