Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

deploy frontend as a docker image #37

Merged
merged 48 commits into from
Dec 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
d5053a5
add terraform changes
BobanL Dec 1, 2023
1015014
specify app location
BobanL Dec 1, 2023
aaa877e
add prebuild command
BobanL Dec 1, 2023
2a8c15e
skip app build
BobanL Dec 1, 2023
00c67d1
add prebuild command to see if it works
BobanL Dec 1, 2023
6d0a1a0
add appsvc file
BobanL Dec 4, 2023
b3f6099
add workflow to deploy on this branch
BobanL Dec 4, 2023
3bd59b2
add ls command
BobanL Dec 4, 2023
8f20f14
rename cd to front-end
BobanL Dec 4, 2023
46f3c75
fix build issues temp
BobanL Dec 4, 2023
0a0aaf0
update script to only zip .next folder
BobanL Dec 4, 2023
66d24c9
add command to start up app
BobanL Dec 4, 2023
c7bb6b5
add terraform deployment to auto-deploy
BobanL Dec 4, 2023
b3db64f
move out deployTerraform into own job
BobanL Dec 4, 2023
b15c9cf
add branch name
BobanL Dec 4, 2023
b0a40b7
put build in deployment.yaml
BobanL Dec 4, 2023
941d78d
move needs terraform to deploy
BobanL Dec 4, 2023
8d9995a
fix typo in terraform
BobanL Dec 4, 2023
d016db1
set to dev2
BobanL Dec 4, 2023
4902f95
set environment name properly
BobanL Dec 4, 2023
a53114f
make it only use dev2
BobanL Dec 4, 2023
78ed7c2
update terraform job name to include env variable
BobanL Dec 4, 2023
8c54a89
add proper curly brace around name
BobanL Dec 4, 2023
73b9e9e
remove env name in terraform job
BobanL Dec 4, 2023
77c2eb4
add test echo statement
BobanL Dec 4, 2023
09c4a15
add quotes around branch name
BobanL Dec 4, 2023
e67e9e1
remove set env job
BobanL Dec 4, 2023
a903e76
fix the start up command for the app service
BobanL Dec 4, 2023
a7867b1
include all files in artifact
BobanL Dec 4, 2023
035411b
revert next.config.js
BobanL Dec 4, 2023
c1e8b04
add standalone as output
BobanL Dec 5, 2023
c6a4303
only copy standalone folder
BobanL Dec 5, 2023
6edb9a3
include all .next files
BobanL Dec 5, 2023
212782e
update command line to be npm run start
BobanL Dec 5, 2023
e8e6872
include public folder in zip
BobanL Dec 5, 2023
7d73c8f
try to deploy with docker image
BobanL Dec 5, 2023
cb74ca4
set context to frontend
BobanL Dec 5, 2023
10263ae
fix file location for dockerfile
BobanL Dec 5, 2023
7727efb
clean up terraform to remove github deployment
BobanL Dec 5, 2023
e29c8d1
clean up deployment action to deploy manually
BobanL Dec 5, 2023
14b065f
update environment name to be the one selected
BobanL Dec 5, 2023
7cb3732
delete appsvc that was used for oryx
BobanL Dec 5, 2023
b959cd5
rename webapps deploy to use v3
BobanL Dec 5, 2023
d37baf6
Update main.tf with env vars
KennethSkylight Dec 6, 2023
312f763
Adding environment variables
KennethSkylight Dec 6, 2023
57d02eb
Merge branch 'boban/deploy-frontend' of github.com:CDCgov/phdi-playgr…
KennethSkylight Dec 6, 2023
baf4bec
Adding production env vars
KennethSkylight Dec 6, 2023
74c58b6
adding env vars
KennethSkylight Dec 6, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 45 additions & 5 deletions .github/workflows/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ permissions:
packages: write
jobs:
terraform:
name: Run Terraform (${{github.event.inputs.environment}})
KennethSkylight marked this conversation as resolved.
Show resolved Hide resolved
name: Run Terraform
runs-on: ubuntu-latest
environment: main
defaults:
Expand Down Expand Up @@ -78,11 +78,7 @@ jobs:
CLIENT_ID: ${{ secrets.CLIENT_ID }}
run: |-
echo "tf_env=$(
if [[ "${{ github.event.inputs.environment }}" != "" ]]; then
echo ${{ github.event.inputs.environment }}
else
echo dev
fi
)" >> $GITHUB_OUTPUT
echo "short_cid=${CLIENT_ID:0:8}" >> $GITHUB_OUTPUT

Expand All @@ -96,3 +92,47 @@ jobs:
terraform init -backend-config=backend.tfvars
terraform workspace select -or-create $TF_ENV
terraform apply -auto-approve -lock-timeout=30m

build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2

- name: Log in to GitHub container registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Lowercase the repo name
run: echo "REPO=${GITHUB_REPOSITORY,,}" >>${GITHUB_ENV}

- name: Build and push container image to registry
uses: docker/build-push-action@v4
with:
context: front-end
push: true
tags: ghcr.io/${{ env.REPO }}:${{ github.sha }}
file: ./front-end/Dockerfile
deploy:
runs-on: ubuntu-latest
needs: build
environment:
name: ${{ github.event.inputs.environment }}
url: ${{ steps.deploy-to-webapp.outputs.webapp-url }}
steps:
- name: Lowercase the repo name
run: echo "REPO=${GITHUB_REPOSITORY,,}" >>${GITHUB_ENV}

- name: Deploy to Azure Web App
id: deploy-to-webapp
uses: azure/webapps-deploy@v3
with:
app-name: app-service-${{ github.event.inputs.environment }}-dibbs
publish-profile: ${{ secrets.AZURE_WEBAPP_PUBLISH_PROFILE }}
images: 'ghcr.io/${{ env.REPO }}:${{ github.sha }}'
1 change: 1 addition & 0 deletions front-end/.env.production
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
NEXT_PUBLIC_PROCESS_URL=wss://phdi-playground-dev.centralus.cloudapp.azure.com/orchestration/process-ws
75 changes: 75 additions & 0 deletions front-end/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
FROM node:18-alpine AS base

# Install dependencies only when needed
FROM base AS deps
# Check https://github.com/nodejs/docker-node/tree/b4117f9333da4138b03a546ec926ef50a31506c3#nodealpine to understand why libc6-compat might be needed.
RUN apk add --no-cache libc6-compat
WORKDIR /app

# Install dependencies based on the preferred package manager
COPY package.json yarn.lock* package-lock.json* pnpm-lock.yaml* ./
RUN \
if [ -f yarn.lock ]; then yarn --frozen-lockfile; \
elif [ -f package-lock.json ]; then npm ci; \
elif [ -f pnpm-lock.yaml ]; then yarn global add pnpm && pnpm i --frozen-lockfile; \
else echo "Lockfile not found." && exit 1; \
fi


# Rebuild the source code only when needed
FROM base AS builder
WORKDIR /app
COPY --from=deps /app/node_modules ./node_modules
COPY . .

# Next.js collects completely anonymous telemetry data about general usage.
# Learn more here: https://nextjs.org/telemetry
# Uncomment the following line in case you want to disable telemetry during the build.
# ENV NEXT_TELEMETRY_DISABLED 1

RUN yarn build

# If using npm comment out above and use below instead
# RUN npm run build

# Production image, copy all the files and run next
FROM base AS runner
WORKDIR /app

ENV NODE_ENV production
# Uncomment the following line in case you want to disable telemetry during runtime.
# ENV NEXT_TELEMETRY_DISABLED 1

ARG NEXT_PUBLIC_PROCESS_URL

ENV NEXT_PUBLIC_PROCESS_URL $NEXT_PUBLIC_PROCESS_URL

# Add your environment variable here
ENV NEXT_PUBLIC_PROCESS_URL "wss://phdi-playground-dev.centralus.cloudapp.azure.com/orchestration/process-ws"

RUN addgroup --system --gid 1001 nodejs
RUN adduser --system --uid 1001 nextjs

COPY --from=builder /app/public ./public

# Set the correct permission for prerender cache
RUN mkdir .next
RUN chown nextjs:nodejs .next

# Automatically leverage output traces to reduce image size
# https://nextjs.org/docs/advanced-features/output-file-tracing
COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./
COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static
COPY .env.production .

USER nextjs

EXPOSE 3000

ENV PORT 3000
# set hostname to localhost
ENV HOSTNAME "0.0.0.0"

# server.js is created by next build from the standalone output
# https://nextjs.org/docs/pages/api-reference/next-config-js/output
CMD ["node", "server.js"]
2 changes: 1 addition & 1 deletion front-end/app/upload_file/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { useData } from '@/utils/DataContext';
export default function UploadFile() {
const { setData } = useData();
const router = useRouter();
const url = process.env.NEXT_PUBLIC_PROCESS_URL
const url = process.env.NEXT_PUBLIC_PROCESS_URL ?? ""
const [progress, setProgress] = useState<ProgressData | null>(null); // State for progress
const [socket, setSocket] = useState<WebSocket | null>(null);
const [file, setFile] = useState<File | null>(null);
Expand Down
6 changes: 3 additions & 3 deletions front-end/components/ECRTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ import {
} from '@trussworks/react-uswds'
import _ from 'lodash';

export default function ECRTable({ ecrData }) {
export default function ECRTable({ ecrData }: any) {
const options = ['patient_id', 'first_name', 'last_name', 'gender', 'birth_date']


const getTableBody = (data: any) => {
return (
<tbody>
{options.map(function (option) {
{data && options.map(function (option) {
return (
<tr key={option}>
<th scope="row">{_.startCase(option)}</th>
Expand All @@ -37,7 +37,7 @@ export default function ECRTable({ ecrData }) {
<th scope="col">Field Value</th>
</tr>
</thead>
{getTableBody(ecrData.processed_values.parsed_values)}
{getTableBody(ecrData?.processed_values?.parsed_values)}
</Table>
</div>
</div>
Expand Down
5 changes: 3 additions & 2 deletions front-end/next.config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/** @type {import('next').NextConfig} */
const nextConfig = {};

module.exports = nextConfig;
module.exports ={
output:"standalone",
KennethSkylight marked this conversation as resolved.
Show resolved Hide resolved
}
7 changes: 7 additions & 0 deletions front-end/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions front-end/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
"devDependencies": {
"@testing-library/jest-dom": "^6.1.4",
"@testing-library/react": "^14.0.0",
"@types/lodash": "^4.14.202",
"@types/websocket": "^1.0.7",
"change-case": "^5.1.2",
"cypress": "^13.3.0",
Expand Down
31 changes: 31 additions & 0 deletions terraform/implementation/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -446,3 +446,34 @@ resource "kubectl_manifest" "keda_scaled_object" {
depends_on = [kubectl_manifest.keda_trigger]
yaml_body = data.kubectl_path_documents.keda_scaled_object[each.key].documents[0]
}


# Azure Web App Service

# Create the Linux App Service Plan
resource "azurerm_service_plan" "playground_appserviceplan" {
name = "appserviceplan-${terraform.workspace}-dibbs"
location = var.location
resource_group_name = var.resource_group_name
os_type = "Linux"
sku_name = "B1"
}

# Create the web app, pass in the App Service Plan ID
resource "azurerm_linux_web_app" "playground_webapp" {
name = "app-service-${terraform.workspace}-dibbs"
location = var.location
resource_group_name = var.resource_group_name
service_plan_id = azurerm_service_plan.playground_appserviceplan.id
https_only = true
site_config {
minimum_tls_version = "1.2"
application_stack {
node_version = "18-lts"
}
}
app_settings = {
"NEXT_PUBLIC_PROCESS_URL" = "wss://phdi-playground-dev.centralus.cloudapp.azure.com/orchestration/process-ws"
# Add other environment variables here
}
}
Loading