Skip to content

Commit

Permalink
feat: deploy web app to staging environment (#1560)
Browse files Browse the repository at this point in the history
  • Loading branch information
lottspot authored Sep 12, 2023
1 parent 00888ba commit 95f0c9a
Show file tree
Hide file tree
Showing 9 changed files with 137 additions and 9 deletions.
51 changes: 51 additions & 0 deletions .github/workflows/stg_web_client_merge.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
name: Web client staging CD

on:
push:
branches:
- master

jobs:

web_cd:
name: Deploy web client
runs-on: ubuntu-latest

env:
ENV_NAME : stg
CLOUDSDK_CORE_PROJECT : web-based-gtfs-validator

steps:

- uses: actions/checkout@v3
with:
# We need to download all tags so that the axion-release-plugin
# can resolve the most recent version tag.
fetch-depth: 0

- name: Set up JDK 17
uses: actions/setup-java@v3
with:
# We need a recent version of Java with jpackage included.
java-version: '17'
# We use the zulu distribution, which is an OpenJDK distro.
distribution: 'zulu'

# for npm
- uses: actions/setup-node@v3
with:
node-version: 16

- uses: google-github-actions/auth@v1
with:
credentials_json: ${{ secrets.GCP_WEB_VALIDATOR_SA_KEY }}

- uses: google-github-actions/setup-gcloud@v1
with:
version: '>= 390.0.0'

- name: run gradle tasks
shell: bash
run: |
ENV_FILE=web/pipeline/${ENV_NAME}.env source web/pipeline/env-file.sh
./gradlew ':web:client:webDeploy'
51 changes: 51 additions & 0 deletions .github/workflows/stg_web_svc_merge.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
name: Web service staging CD

on:
push:
branches:
- master

jobs:

web_cd:
name: Deploy web service
runs-on: ubuntu-latest

env:
ENV_NAME : stg
CLOUDSDK_CORE_PROJECT : web-based-gtfs-validator

steps:

- uses: actions/checkout@v3
with:
# We need to download all tags so that the axion-release-plugin
# can resolve the most recent version tag.
fetch-depth: 0

- name: Set up JDK 17
uses: actions/setup-java@v3
with:
# We need a recent version of Java with jpackage included.
java-version: '17'
# We use the zulu distribution, which is an OpenJDK distro.
distribution: 'zulu'

# for npm
- uses: actions/setup-node@v3
with:
node-version: 16

- uses: google-github-actions/auth@v1
with:
credentials_json: ${{ secrets.GCP_WEB_VALIDATOR_SA_KEY }}

- uses: google-github-actions/setup-gcloud@v1
with:
version: '>= 390.0.0'

- name: run gradle tasks
shell: bash
run: |
ENV_FILE=web/pipeline/${ENV_NAME}.env source web/pipeline/env-file.sh
./gradlew ':web:service:webDeploy'
3 changes: 2 additions & 1 deletion web/client/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ node_modules
!.env.example
vite.config.js.timestamp-*
vite.config.ts.timestamp-*
/static/rules.json
/notice_schema.json
rules.json
5 changes: 3 additions & 2 deletions web/client/src/routes/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import { fly } from 'svelte/transition';
import { onMount, tick } from 'svelte';
import { quintOut } from 'svelte/easing';
import { env } from '$env/dynamic/public';
/**
* @typedef CreateJobParameters
Expand All @@ -35,7 +36,7 @@
let showDocs = true;
const apiRoot = 'https://gtfs-validator-web-mbzoxaljzq-ue.a.run.app';
const apiRoot = `${env.PUBLIC_CLIENT_API_ROOT}`;
/** @type {HTMLInputElement} */
let fileInput;
Expand Down Expand Up @@ -67,7 +68,7 @@
/** @type {HTMLDialogElement} */
let statusModal;
$: reportUrl = `https://gtfs-validator-results.mobilitydata.org/${jobId}/report.html`;
$: reportUrl = `${env.PUBLIC_CLIENT_REPORTS_ROOT}/${jobId}/report.html`;
function clearErrors() {
errors = [];
Expand Down
2 changes: 2 additions & 0 deletions web/pipeline/prd.env
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@ WEB_BUILD_ENV=prd
WEB_DEPLOY_CLIENT_BUCKET=gtfs-validator-web
WEB_DEPLOY_SVC_IMAGE=gcr.io/web-based-gtfs-validator/gtfs-validator-web
WEB_DEPLOY_SVC_CLOUDRUN=gtfs-validator-web
PUBLIC_CLIENT_API_ROOT=https://gtfs-validator-web-mbzoxaljzq-ue.a.run.app
PUBLIC_CLIENT_REPORTS_ROOT=https://gtfs-validator-results.mobilitydata.org
7 changes: 7 additions & 0 deletions web/pipeline/stg.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
CLOUDSDK_CORE_PROJECT=web-based-gtfs-validator
WEB_BUILD_ENV=stg
WEB_DEPLOY_CLIENT_BUCKET=stg-gtfs-validator-web
WEB_DEPLOY_SVC_IMAGE=gcr.io/web-based-gtfs-validator/gtfs-validator-web
WEB_DEPLOY_SVC_CLOUDRUN=stg-gtfs-validator-web
PUBLIC_CLIENT_API_ROOT=https://stg-gtfs-validator-web-mbzoxaljzq-ue.a.run.app
PUBLIC_CLIENT_REPORTS_ROOT=https://staging-gtfs-validator-results.mobilitydata.org
10 changes: 10 additions & 0 deletions web/service/gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,13 @@ env.prd.svcAPMLicenseDst = newrelic/newrelic.yml
env.prd.svcSecretPropertiesProvider = gcloud-secrets
env.prd.svcSecretPropertiesSrc = web-validator-properties
env.prd.svcSecretPropertiesDst = src/main/resources/application.properties

env.stg.svcCredentialProvider = gcloud-secrets
env.stg.svcCredentialSrc = web-validator-sa-key
env.stg.svcCredentialDst = src/main/resources/web-based-gtfs-validator-a088ec5f045d.json
env.stg.svcAPMLicenseProvider = gcloud-secrets
env.stg.svcAPMLicenseSrc = web-validator-newrelic-license
env.stg.svcAPMLicenseDst = newrelic/newrelic.yml
env.stg.svcSecretPropertiesProvider = gcloud-secrets
env.stg.svcSecretPropertiesSrc = web-validator-properties
env.stg.svcSecretPropertiesDst = src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,18 @@
/** Helper class for interacting with GCS. */
@Component
public class StorageHelper {
public static final String JOB_INFO_BUCKET_NAME = "gtfs-validator-results";
public String JOB_INFO_BUCKET_NAME =
System.getenv().getOrDefault("JOB_INFO_BUCKET_NAME", "gtfs-validator-results");

static final String JOB_FILENAME_PREFIX = "job";
static final String JOB_FILENAME_SUFFIX = ".json";
public static final String JOB_FILENAME = JOB_FILENAME_PREFIX + JOB_FILENAME_SUFFIX;
public static final String TEMP_FOLDER_NAME = "gtfs-validator-temp";
static final String USER_UPLOAD_BUCKET_NAME = "gtfs-validator-user-uploads";
static final String RESULTS_BUCKET_NAME = "gtfs-validator-results";
public static final String TEMP_FOLDER_NAME =
System.getenv().getOrDefault("TEMP_FOLDER_NAME", "gtfs-validator-temp");
static final String USER_UPLOAD_BUCKET_NAME =
System.getenv().getOrDefault("USER_UPLOAD_BUCKET_NAME", "gtfs-validator-user-uploads");
static final String RESULTS_BUCKET_NAME =
System.getenv().getOrDefault("RESULTS_BUCKET_NAME", "gtfs-validator-results");
static final String FILE_NAME = "gtfs-job.zip";

private final Logger logger = LoggerFactory.getLogger(StorageHelper.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public void testSaveJobMetadata() throws Exception {
byte[] bytes = byteArrayCaptor.getValue();
String expectedPath = jobMetadata.getJobId() + "/" + StorageHelper.JOB_FILENAME;
BlobInfo expectedBlobInfo =
BlobInfo.newBuilder(BlobId.of(StorageHelper.JOB_INFO_BUCKET_NAME, expectedPath))
BlobInfo.newBuilder(BlobId.of(storageHelper.JOB_INFO_BUCKET_NAME, expectedPath))
.setContentType("application/json")
.build();
byte[] expectedBytes = mapper.writeValueAsString(jobMetadata).getBytes();
Expand All @@ -69,7 +69,7 @@ public void testGetJobMetadata() throws Exception {

verify(storage, times(1)).get(blobIdCaptor.capture());
BlobId expectedBlobId =
BlobId.of(StorageHelper.JOB_INFO_BUCKET_NAME, StorageHelper.getJobInfoPath(testJobId));
BlobId.of(storageHelper.JOB_INFO_BUCKET_NAME, StorageHelper.getJobInfoPath(testJobId));
assertEquals(expectedBlobId, blobIdCaptor.getValue());

assertEquals(expectedJson, mapper.writeValueAsString(actualJobMetadata));
Expand Down

0 comments on commit 95f0c9a

Please sign in to comment.