Skip to content
This repository has been archived by the owner on Oct 22, 2023. It is now read-only.

Commit

Permalink
Merge pull request #9 from 3n3a/dev
Browse files Browse the repository at this point in the history
Multiple Fixes and Improvements
  • Loading branch information
3n3a authored Aug 28, 2022
2 parents 774f7a8 + 8e037a1 commit 40a6a4f
Show file tree
Hide file tree
Showing 10 changed files with 49 additions and 26 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,7 @@ jobs:
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=registry,ref=3n3a/manager:latest
cache-to: type=inline
secrets: |
"WEBHOOK_URL=${{ secrets.WEBHOOK_URL }}"
"WEBHOOK_KEY=${{ secrets.WEBHOOK_KEY }}"
2 changes: 0 additions & 2 deletions deployment/prod/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ services:
DATABASE_URL: ecto://postgres:postgres@db/manager
SECRET_KEY_BASE: AEHwSQet/650xylvkc2r/XzOBS0HunCyRMNEVzebnlB1gUWfs80leMzKlIgioFul
PHX_HOST: localhost
WEBHOOK_URL:
WEBHOOK_KEY:
ports:
- 8004:4000
- 8005:5000
Expand Down
9 changes: 9 additions & 0 deletions manager_umbrella/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,15 @@ RUN chown nobody /app
# set runner ENV
ENV MIX_ENV="prod"

# set secrets
RUN --mount=type=bind,target=. \
--mount=type=secret,id=WEBHOOK_URL \
export WEBHOOK_URL=$(cat /run/secrets/WEBHOOK_URL)

RUN --mount=type=bind,target=. \
--mount=type=secret,id=WEBHOOK_KEY \
export WEBHOOK_KEY=$(cat /run/secrets/WEBHOOK_KEY)

# Only copy the final release from the build stage
COPY --from=builder --chown=nobody:root /app/_build/${MIX_ENV}/rel/manager_umbrella ./

Expand Down
2 changes: 1 addition & 1 deletion manager_umbrella/apps/manager/lib/manager/homepage.ex
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ defmodule Manager.Homepage do
"""
def list_projects do
Repo.all(Project)
Repo.all(from p in Project, order_by: p.title)
end

@doc """
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ defmodule Manager.Homepage.Project do
project
|> cast(attrs, [:title, :body, :href, :color, :customBg, :status])
|> validate_required([:title, :body, :href, :status])
|> unique_constraint(:href)
|> unique_constraint(:title)
|> unique_constraint(:href)
end
end
6 changes: 3 additions & 3 deletions manager_umbrella/apps/manager/lib/manager/school.ex
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ defmodule Manager.School do
"""
def list_exams do
Repo.all(Exam)
Repo.all(from e in Exam, order_by: e.name)
end

@doc """
Expand Down Expand Up @@ -117,7 +117,7 @@ defmodule Manager.School do
"""
def list_subjects do
Repo.all(Subject)
Repo.all(from s in Subject, order_by: s.name)
end

@doc """
Expand All @@ -130,7 +130,7 @@ defmodule Manager.School do
"""
def select_list_subjects do
Repo.all from p in Subject, select: {p.name, p.id}
Repo.all from p in Subject, select: {fragment("concat(?, ' - ', ?)", p.name, p.description), p.id}
end

@doc """
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,14 @@ defmodule ManagerApi.ExamView do
alias Manager.School


def get_subject_name(exam) do
School.get_subject!(exam.subject_id).name
def get_subject(exam) do
subject = School.get_subject!(exam.subject_id)
%{
id: subject.id,
name: subject.name,
description: subject.description,
teacher: subject.teacher
}
end

def render("index.json", %{exams: exams}) do
Expand All @@ -23,7 +29,7 @@ defmodule ManagerApi.ExamView do
name: exam.name,
mark: exam.mark,
type: exam.type,
subject: get_subject_name(exam),
subject: get_subject(exam),
status: exam.status
}
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ defmodule ManagerWeb.ExamController do
def new(conn, _params) do
changeset = School.change_exam(%Exam{})
subject_list = School.select_list_subjects()

render(conn, "new.html", changeset: changeset, subject_list: subject_list)
end

Expand All @@ -22,7 +22,7 @@ defmodule ManagerWeb.ExamController do

case School.create_exam(exam_params) do
{:ok, exam} ->
trigger_deploy()
trigger_deploy(exam)
conn
|> put_flash(:info, "Exam created successfully.")
|> redirect(to: Routes.exam_path(conn, :show, exam))
Expand Down Expand Up @@ -51,7 +51,7 @@ defmodule ManagerWeb.ExamController do

case School.update_exam(exam, exam_params) do
{:ok, exam} ->
trigger_deploy()
trigger_deploy(exam)
conn
|> put_flash(:info, "Exam updated successfully.")
|> redirect(to: Routes.exam_path(conn, :show, exam))
Expand All @@ -65,13 +65,15 @@ defmodule ManagerWeb.ExamController do
exam = School.get_exam!(id)
{:ok, _exam} = School.delete_exam(exam)

trigger_deploy()
trigger_deploy(exam)
conn
|> put_flash(:info, "Exam deleted successfully.")
|> redirect(to: Routes.exam_path(conn, :index))
end

def trigger_deploy() do
WebhookAdapter.trigger_deploy("school")
def trigger_deploy(exam) do
if exam.status == :live do
WebhookAdapter.trigger_deploy("school")
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ defmodule ManagerWeb.ProjectController do
def create(conn, %{"project" => project_params}) do
case Homepage.create_project(project_params) do
{:ok, project} ->
trigger_deploy()
trigger_deploy(project)
conn
|> put_flash(:info, "Project created successfully.")
|> redirect(to: Routes.project_path(conn, :show, project))
Expand All @@ -43,7 +43,7 @@ defmodule ManagerWeb.ProjectController do

case Homepage.update_project(project, project_params) do
{:ok, project} ->
trigger_deploy()
trigger_deploy(project)
conn
|> put_flash(:info, "Project updated successfully.")
|> redirect(to: Routes.project_path(conn, :show, project))
Expand All @@ -57,13 +57,15 @@ defmodule ManagerWeb.ProjectController do
project = Homepage.get_project!(id)
{:ok, _project} = Homepage.delete_project(project)

trigger_deploy()
trigger_deploy(project)
conn
|> put_flash(:info, "Project deleted successfully.")
|> redirect(to: Routes.project_path(conn, :index))
end

def trigger_deploy() do
WebhookAdapter.trigger_deploy("home")
def trigger_deploy(project) do
if project.status == :live do
WebhookAdapter.trigger_deploy("home")
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ defmodule ManagerWeb.SubjectController do
def create(conn, %{"subject" => subject_params}) do
case School.create_subject(subject_params) do
{:ok, subject} ->
trigger_deploy()
trigger_deploy(subject)
conn
|> put_flash(:info, "Subject created successfully.")
|> redirect(to: Routes.subject_path(conn, :show, subject))
Expand All @@ -43,7 +43,7 @@ defmodule ManagerWeb.SubjectController do

case School.update_subject(subject, subject_params) do
{:ok, subject} ->
trigger_deploy()
trigger_deploy(subject)
conn
|> put_flash(:info, "Subject updated successfully.")
|> redirect(to: Routes.subject_path(conn, :show, subject))
Expand All @@ -57,13 +57,15 @@ defmodule ManagerWeb.SubjectController do
subject = School.get_subject!(id)
{:ok, _subject} = School.delete_subject(subject)

trigger_deploy()
trigger_deploy(subject)
conn
|> put_flash(:info, "Subject deleted successfully.")
|> redirect(to: Routes.subject_path(conn, :index))
end

def trigger_deploy() do
WebhookAdapter.trigger_deploy("school")
def trigger_deploy(subject) do
if subject.status == :live do
WebhookAdapter.trigger_deploy("school")
end
end
end

0 comments on commit 40a6a4f

Please sign in to comment.