Skip to content

Commit a786d58

Browse files
committed
github actions
1 parent bb82504 commit a786d58

File tree

6 files changed

+205
-13
lines changed

6 files changed

+205
-13
lines changed
Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
name: Backend Build and Deploy to AWS ECS
2+
on:
3+
release:
4+
types:
5+
- created
6+
workflow_dispatch:
7+
inputs:
8+
env:
9+
description: "AWS Env"
10+
required: true
11+
default: "dev"
12+
ref:
13+
description: "Branch, Tag, or Full SHA"
14+
required: true
15+
merge:
16+
branch:
17+
- main
18+
19+
env:
20+
AWS_APP_NAME: open-disclosure-backend
21+
AWS_REGION: us-west-2
22+
DOCKERFILE: ./redis_api/Dockerfile.cloud
23+
DOCKER_PATH: ./frontend
24+
jobs:
25+
setup_env:
26+
name: Set-up environment
27+
runs-on: ubuntu-latest
28+
steps:
29+
- name: Debug Action
30+
uses: hmarr/debug-action@v1.0.0
31+
- name: Checkout
32+
uses: actions/checkout@v2
33+
with:
34+
ref: ${{ github.event.inputs.ref }}
35+
- name: Set AWS Env & Image Tag per workflow
36+
run: |
37+
SHORT_SHA=$(git rev-parse --short HEAD)
38+
if [[ "$GITHUB_EVENT_NAME" == "release" ]]; then
39+
RELEASE_TAG=$(git describe --tags)
40+
echo AWS_APPENV="$AWS_APP_NAME"-prod >> $GITHUB_ENV
41+
echo AWS_ENV=prod >> $GITHUB_ENV
42+
echo IMAGE_TAG=$RELEASE_TAG >> $GITHUB_ENV
43+
fi
44+
if [[ "$GITHUB_EVENT_NAME" == "workflow_dispatch" ]]; then
45+
INPUT_ENV=${{ github.event.inputs.env }}; INPUT_REF=${{ github.event.inputs.ref }}
46+
echo AWS_APPENV="$AWS_APP_NAME"-$INPUT_ENV >> $GITHUB_ENV
47+
echo AWS_ENV=$INPUT_ENV >> $GITHUB_ENV
48+
echo IMAGE_TAG=$SHORT_SHA >> $GITHUB_ENV
49+
fi
50+
outputs:
51+
AWS_APPENV: ${{ env.AWS_APPENV }}
52+
AWS_ENV: ${{ env.AWS_ENV }}
53+
IMAGE_TAG: ${{ env.IMAGE_TAG }}
54+
build:
55+
name: Build & Push Docker Image
56+
runs-on: ubuntu-latest
57+
needs: [setup_env]
58+
steps:
59+
- name: Checkout
60+
uses: actions/checkout@v2
61+
with:
62+
ref: ${{ github.event.inputs.ref }}
63+
- name: Configure AWS credentials
64+
uses: aws-actions/configure-aws-credentials@v1
65+
with:
66+
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
67+
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
68+
aws-region: ${{ env.AWS_REGION }}
69+
- name: Login to Amazon ECR
70+
id: login-ecr
71+
uses: aws-actions/amazon-ecr-login@v1
72+
- name: Build & Push Image to ECR
73+
uses: kciter/aws-ecr-action@v3
74+
with:
75+
access_key_id: ${{ secrets.AWS_ACCESS_KEY_ID }}
76+
secret_access_key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
77+
account_id: ${{ secrets.AWS_ACCOUNT_ID }}
78+
repo: ${{ needs.setup_env.outputs.AWS_APPENV }}
79+
region: ${{ env.AWS_REGION }}
80+
tags: latest,${{ needs.setup_env.outputs.IMAGE_TAG }}
81+
dockerfile: ${{ env.DOCKERFILE }}
82+
path: ${{ env.DOCKER_PATH }}
83+
extra_build_args: "--build-arg ENV=${{ needs.setup_env.outputs.AWS_ENV }}"
84+
deploy:
85+
name: Deploy to AWS ECS
86+
runs-on: ubuntu-latest
87+
needs: [setup_env, build]
88+
steps:
89+
- name: Configure AWS credentials
90+
uses: aws-actions/configure-aws-credentials@v1
91+
with:
92+
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
93+
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
94+
aws-region: ${{ env.AWS_REGION }}
95+
- name: Login to Amazon ECR
96+
id: login-ecr
97+
uses: aws-actions/amazon-ecr-login@v1
98+
- name: Pull Task Definition & write to file
99+
id: aws-task-definition
100+
run: |
101+
aws ecs describe-task-definition \
102+
--task-definition ${{ needs.setup_env.outputs.AWS_APPENV }} \
103+
--query taskDefinition | \
104+
jq 'del(.taskDefinitionArn,.revision,.status,.registeredBy,.registeredAt,.compatibilities,.requiresAttributes)' > task-def-backend.json
105+
- name: Interpolate new Docker Image into Task Definition
106+
id: task-definition
107+
uses: aws-actions/amazon-ecs-render-task-definition@v1
108+
with:
109+
task-definition: task-def-backend.json
110+
container-name: ${{ needs.setup_env.outputs.AWS_APPENV }}
111+
image: ${{ steps.login-ecr.outputs.registry }}/${{ needs.setup_env.outputs.AWS_APPENV }}:${{ needs.setup_env.outputs.IMAGE_TAG }}
112+
- name: Deploy Amazon ECS
113+
uses: aws-actions/amazon-ecs-deploy-task-definition@v1
114+
with:
115+
task-definition: ${{ steps.task-definition.outputs.task-definition }}
116+
service: ${{ needs.setup_env.outputs.AWS_APPENV }}
117+
cluster: multi-tenant-prod
118+
wait-for-service-stability: true
119+
wait-for-minutes: 7 minutes

src/common/divider.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import React from "react"
2+
3+
export default function Divider() {
4+
return (<div style={{width: "100%", border: "0.2rem solid #e7e7e7", margin: "2.4rem 0"}}></div>)
5+
}

src/components/sectionHeader.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import React from "react"
2+
import Divider from "../common/divider"
23
import styles from "./sectionHeader.module.scss"
34

45
export default function SectionHeader({
@@ -14,7 +15,7 @@ export default function SectionHeader({
1415
>
1516
<h3>{title}</h3>
1617
<p>{subtitle}</p>
17-
<div className={styles.divider} />
18+
{!isSubsection && <Divider/>}
1819
</div>
1920
)
2021
}

src/components/sectionHeader.module.scss

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,6 @@
2424
font-size: 2.8rem;
2525
margin: 4rem 0;
2626
}
27-
.divider {
28-
display: none;
29-
}
30-
}
31-
32-
.divider {
33-
width: 100%;
34-
border: 0.2rem solid $backgroundGray;
35-
margin: 2.4rem 0;
3627
}
3728

3829
@media screen and (max-width: 760px) {
@@ -42,7 +33,4 @@
4233
line-height: 120%;
4334
}
4435
}
45-
.divider {
46-
margin: 1rem 0 1.4rem;
47-
}
4836
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import React from "react"
2+
import useWindowIsLarge from "../common/hooks/useWindowIsLarge";
3+
import LandingPageHero from "../components/landingPageHero";
4+
import Layout from "../components/layout"
5+
import SectionHeader from "../components/sectionHeader";
6+
7+
import styles from "./independentExpenditures.module.scss"
8+
9+
export default function IndependentExpenditures() {
10+
const title = "Independent Expenditures"
11+
const subtitle = "City of San Jose Independent Expenditures"
12+
return (
13+
<Layout
14+
title={title}
15+
windowIsLarge={useWindowIsLarge()}
16+
description={subtitle}>
17+
<header>
18+
<LandingPageHero title={title} subtitle={subtitle}/>
19+
</header>
20+
<main className={styles.container}>
21+
<SectionHeader
22+
title="Independent Expenditures"
23+
subtitle="Learn what independent expenditures are and why they are important"
24+
isSubsection={false}
25+
isPageHeader={false}/>
26+
<iframe
27+
title="Independent Expenditures Explanation"
28+
width="720" height="415" src="https://www.youtube.com/embed/ktaADxb4P5E"/>
29+
</main>
30+
</Layout>);
31+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
@import "../styles/colors";
2+
3+
.container {
4+
padding: 10rem;
5+
max-width: 1440px;
6+
margin: auto;
7+
8+
h1,
9+
h2,
10+
p {
11+
line-height: 130%;
12+
}
13+
14+
h1 {
15+
font-size: 3.2rem;
16+
margin-bottom: 3.5rem;
17+
}
18+
19+
h2 {
20+
font-weight: 500;
21+
font-size: 2.4rem;
22+
margin: 4rem 0 2rem;
23+
}
24+
p {
25+
font-size: 2rem;
26+
margin: 1.5rem 0 1.5rem;
27+
a {
28+
color: $primaryGreen;
29+
}
30+
}
31+
}
32+
33+
@media screen and (max-width: 760px) {
34+
.container {
35+
padding: 2rem 5rem;
36+
}
37+
38+
h1 {
39+
font-size: 2.2rem;
40+
margin-bottom: 1.4rem;
41+
}
42+
h2 {
43+
font-size: 1.8rem;
44+
}
45+
p {
46+
font-size: 1.4rem;
47+
}
48+
}

0 commit comments

Comments
 (0)