Skip to content

Commit

Permalink
Merge pull request #259 from DEFRA/tweaks-to-deployments
Browse files Browse the repository at this point in the history
Tweaks to deployments
  • Loading branch information
feedmypixel authored Dec 21, 2023
2 parents 09ce4d9 + a6a5c32 commit 35966f4
Show file tree
Hide file tree
Showing 6 changed files with 96 additions and 67 deletions.
4 changes: 2 additions & 2 deletions src/server/common/helpers/user/is-user-in-service-team.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ import { fetchTeams } from '~/src/server/teams/helpers/fetch-teams'
async function isUserInServiceTeam(userGroups) {
// TODO pagination on teams
const { teams } = await fetchTeams(true)
const teamIds = teams?.map((team) => team.teamId)
const teamIds = teams?.map((team) => team.teamId) ?? []

return userGroups.some((userGroupId) => teamIds.includes(userGroupId))
return userGroups.some((userGroupId) => teamIds?.includes(userGroupId))
}

export { isUserInServiceTeam }
12 changes: 4 additions & 8 deletions src/server/deployments/controllers/deployment.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { fetchDeployment } from '~/src/server/deployments/helpers/fetch-deployme
import { transformDeploymentToEntityDataList } from '~/src/server/deployments/transformers/transform-deployment-to-entity-data-list'
import { deploymentTabs } from '~/src/server/deployments/helpers/deployment-tabs'
import { transformDeployment } from '~/src/server/deployments/transformers/transform-deployment'
import { getDeploymentStatusClassname } from '~/src/server/deployments/helpers/get-deployment-status-classname'

const deploymentController = {
options: {
Expand All @@ -19,20 +18,17 @@ const deploymentController = {
}
},
handler: async (request, h) => {
const deploymentDetail = transformDeployment(
const deployment = transformDeployment(
await fetchDeployment(request.params?.deploymentId)
)

return h.view('deployments/views/deployment', {
pageTitle: `${deploymentDetail.service} Service Deployment`,
pageTitle: `${deployment.service} Service Deployment`,
heading: 'Deployment',
caption: 'Microservice deployment detail.',
statusClasses: getDeploymentStatusClassname(
deploymentDetail.status.overall
),
entityDataList: transformDeploymentToEntityDataList(deploymentDetail),
tabs: deploymentTabs(request),
deploymentDetail
entityDataList: transformDeploymentToEntityDataList(deployment),
deployment
})
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,7 @@ function transformDeploymentToEntityDataList(deploymentDetail) {
heading: 'Updated',
entity: {
kind: 'date',
value: deploymentDetail.updatedAt,
size: 'large'
}
},
{
heading: 'Created',
entity: {
kind: 'date',
value: deploymentDetail.createdAt,
value: deploymentDetail.deployedAt,
size: 'large'
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,18 +45,9 @@ describe('#transformDeploymentToEntityDataList', () => {
{
entity: {
kind: 'date',
size: 'large',
value: '2023-12-14T14:10:49Z'
size: 'large'
},
heading: 'Updated'
},
{
entity: {
kind: 'date',
size: 'large',
value: '2023-12-14T14:04:49Z'
},
heading: 'Created'
}
])
})
Expand Down
26 changes: 19 additions & 7 deletions src/server/deployments/transformers/transform-deployment.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,28 @@
import { omit, pickBy } from 'lodash'
import { getDeploymentStatusClassname } from '~/src/server/deployments/helpers/get-deployment-status-classname'

const byLatest = (a, b) => Date.parse(b.deployedAt) - Date.parse(a.deployedAt)

function calculateOverallStatus(ecsSvcDeployments) {
const instanceStatuses = Object.entries(ecsSvcDeployments).reduce(
(statuses, [key, value]) => ({
...statuses,
[key]: value?.at(0)?.status
[key]: value?.at(0)?.status.text
}),
{}
)

const allRunning = Object.values(instanceStatuses).every(
(status) => status === 'RUNNING'
)
const allFailed = Object.values(instanceStatuses).every(
(status) => status === 'FAILED'
)
const statusText = allRunning ? 'RUNNING' : allFailed ? 'FAILED' : 'PENDING'

return {
overall: Object.values(instanceStatuses).every(
(status) => status === 'RUNNING'
)
? 'RUNNING'
: 'PENDING',
instances: instanceStatuses
text: statusText,
classes: getDeploymentStatusClassname(statusText)
}
}

Expand All @@ -36,6 +41,13 @@ function transformDeployment(deployments) {
...deploymentsByEcsSvcId,
[id]: deployments
.filter((deployment) => deployment?.ecsSvcDeploymentId === id)
.map((deployment) => ({
...deployment,
status: {
text: deployment.status,
classes: getDeploymentStatusClassname(deployment.status)
}
}))
.sort(byLatest)
}),
{}
Expand Down
100 changes: 69 additions & 31 deletions src/server/deployments/views/deployment.njk
Original file line number Diff line number Diff line change
Expand Up @@ -2,39 +2,77 @@

{% block tabContent %}

<div class="govuk-grid-row govuk-!-margin-bottom-4">
<div class="govuk-grid-column-two-thirds">
<section class="govuk-!-margin-bottom-6">
<h2 class="govuk-heading-xl govuk-!-margin-bottom-3">{{ deploymentDetail.service }} {{ deploymentDetail
.version }}</h2>
{% if deployment.status.text != "RUNNING" and deployment.status.text != "FAILED" %}
<div data-js="app-poll"
data-poll-url="/deployments/{{ deployment.environment }}/{{ deployment.deploymentId }}"
data-poll-interval="3000"
data-poll-limit="45">
{% endif %}

</section>
<section class="govuk-!-margin-bottom-6">
<h2 class="govuk-heading-l govuk-!-margin-bottom-3">Status</h2>
{{ govukTag({
text: deploymentDetail.status.overall,
classes: statusClasses,
attributes: {
"data-testid": "deployment-status"
}
}) }}
</section>
<section class="govuk-!-margin-bottom-6">
<h2 class="govuk-heading-l govuk-!-margin-bottom-3">Environment</h2>
{{ govukTag({
text: deploymentDetail.environment,
classes: 'govuk-tag--blue',
attributes: {
"data-testid": "deployment-environment"
}
{% block xhrContent %}
<div class="govuk-grid-row govuk-!-margin-top-2 govuk-!-margin-bottom-4">
<div class="govuk-grid-column-two-thirds">
<div class="govuk-!-margin-bottom-6">
<h2 class="govuk-heading-l govuk-!-margin-bottom-2">{{ deployment.service }}</h2>
</div>
<div class="govuk-!-margin-bottom-6">
<h2 class="govuk-heading-m govuk-!-margin-bottom-2">Version</h2>
{{ deployment.version }}
</div>
<div class="govuk-!-margin-bottom-6">
<h2 class="govuk-heading-m govuk-!-margin-bottom-2">Status</h2>
{{ govukTag({
text: deployment.status.text,
classes: deployment.status.classes,
attributes: {
"data-testid": "deployment-status"
}
}) }}
</div>
<div class="govuk-!-margin-bottom-6">
<h2 class="govuk-heading-m govuk-!-margin-bottom-2">Environment</h2>
{{ govukTag({
text: deployment.environment,
classes: 'govuk-tag--blue',
attributes: {
"data-testid": "deployment-environment"
}
}) }}
</div>
<div class="govuk-!-margin-bottom-6">
<h2 class="govuk-heading-m govuk-!-margin-bottom-2">Deployment history</h2>
{% for key, deployments in deployment.deployments %}
<h2 class="govuk-heading-s govuk-!-margin-bottom-2">Instance {{ loop.index }}</h2>

<ul class="govuk-list govuk-list--bullet">
{% for deploymentDetail in deployments %}
<li>
{{ deploymentDetail.deployedAt | formatDate("k:mm:ss EE do MMM yyyy") }}
<span class="govuk-!-margin-left-2">
{{ govukTag({
text: deploymentDetail.status.text,
classes: deploymentDetail.status.classes,
attributes: {
"data-testid": "deployment-status"
}
}) }}
</span>
</li>
{% endfor %}
</ul>
{% endfor %}

</div>
</div>
<div class="govuk-grid-column-one-third">
{{ appEntityDataList({
items: entityDataList
}) }}
</section>
</div>
</div>
<div class="govuk-grid-column-one-third">
{{ appEntityDataList({
items: entityDataList
}) }}
</div>
</div>
{% endblock %}

{% if deployment.status.text != "RUNNING" and deployment.status.text != "FAILED" %}
</div>
{% endif %}
{% endblock %}

0 comments on commit 35966f4

Please sign in to comment.