Skip to content

Commit

Permalink
feat: Add deployment + package workflows for API and Web App
Browse files Browse the repository at this point in the history
- Added new workflow files `build-package-api.yml` and `build-package-web.yml`
- Workflows trigger on a workflow call with a required input parameter
- Workflows have necessary permissions to read contents and packages
- Build API (prod) job in `build-package-api.yml`:
  - Checks out the code repository
  - Sets up .NET environment
  - Builds the .NET project using the specified build configuration
  - Packages the API using the specified build configuration
  - Uploads artifacts to be used later
- Build Web App job in `build-package-web.yml`:
  - Checks out the code repository
  - Sets up Node.js environment
  - Installs Angular CLI globally
  - Installs dependencies for the app
  - Builds the Angular app using the specified build configuration
  - Uploads artifacts to be used later
  • Loading branch information
SakuraIsayeki committed Feb 1, 2024
1 parent b92e292 commit e0e9e4c
Show file tree
Hide file tree
Showing 8 changed files with 206 additions and 4 deletions.
41 changes: 41 additions & 0 deletions .github/workflows/build-package-api.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: Build & Package API

on:
workflow_call:
inputs:
build_configuration:
description: 'Build Configuration'
type: string
required: true

permissions:
contents: read
packages: read

jobs:
# Build prod
build-api-prod:
name: Build API (prod)
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
submodules: 'recursive'

- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: '8.0.x'
# include-prerelease: true

- name: Build .NET project (prod)
run: dotnet build --configuration ${{ inputs.build_configuration }}

- name: Package API (prod)
run: dotnet publish --configuration ${{ inputs.build_configuration }} --output ./publish

- name: Upload Artifacts
uses: actions/upload-artifact@v4
with:
name: wowskarma_api
path: ./publish
43 changes: 43 additions & 0 deletions .github/workflows/build-package-web.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: Build & Package Web App

on:
workflow_call:
inputs:
build_configuration:
description: 'Build Configuration'
type: string
required: true

permissions:
contents: read
packages: read

jobs:
# Build angular app
build-web:
name: Build Web App
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
submodules: 'recursive'

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20.x'

- name: Install Angular CLI
run: npm install -g @angular/cli

- name: Install dependencies
run: npm install

- name: Build Angular app
run: ng build --configuration=${{ inputs.build_configuration }}

- name: Upload Artifacts
uses: actions/upload-artifact@v4
with:
name: wowskarma_app
path: ./dist
66 changes: 66 additions & 0 deletions .github/workflows/deploy-preview.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
name: deploy-preview.yml

on:
push:
branches: [ develop ]

permissions:
contents: read
packages: read
deployments: write

jobs:
# First: Make sure dev build ran fine.
build-test-solution:
name: Build & Test Solution
uses: ./.github/workflows/dotnet-build.yml

# Build & Package API & Web from 'build-package-api.yml' and 'build-package-web.yml'.
build-package-api:
name: Build & Package API
needs: build-test-solution
uses: ./.github/workflows/build-package-api.yml
with:
build_configuration: 'Preview'

build-package-web:
name: Build & Package Web App
needs: build-test-solution
uses: ./.github/workflows/build-package-web.yml
with:
build_configuration: 'Preview'

# Deploy to server
deploy-preview:
name: Deploy Preview to server
environment:
name: preview
url: https://preview.wows-karma.com/
needs:
- build-package-api
- build-package-web
runs-on: ubuntu-latest
steps:
- name: Download packaged API artifacts
uses: actions/download-artifact@v4
with:
name: wowskarma_api
path: ./api

- name: Download packaged Web App artifacts
uses: actions/download-artifact@v4
with:
name: wowskarma_app
path: ./web

- name: Install SSH Key
uses: shimataro/ssh-key-action@v2
with:
key: ${{ secrets.SSH_PRIVATEKEY }}
known_hosts: '*.nodsoft.net'

- name: Add Known Hosts
run: ssh-keyscan -H ${{ secrets.SSH_HOST }} >> ~/.ssh/known_hosts

- name: Deploy with rsync
run: rsync -avz . ${{ secrets.SSH_USER }}@${{ secrets.SSH_HOST }}:${{ secrets.SSH_DEPLOYPATH }}
29 changes: 28 additions & 1 deletion wowskarma.app/angular.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,40 @@
],
"outputHashing": "all"
},
"preview": {
"budgets": [
{
"type": "initial",
"maximumWarning": "1mb",
"maximumError": "4mb"
},
{
"type": "anyComponentStyle",
"maximumWarning": "2kb",
"maximumError": "4kb"
}
],
"fileReplacements": [
{
"replace": "src/environments/environment.ts",
"with": "src/environments/environment.preview.ts"
}
],
"outputHashing": "all"
},
"development": {
"buildOptimizer": false,
"optimization": false,
"vendorChunk": true,
"extractLicenses": false,
"sourceMap": true,
"namedChunks": true
"namedChunks": true,
"fileReplacements": [
{
"replace": "src/environments/environment.ts",
"with": "src/environments/environment.development.ts"
}
]
}
},
"defaultConfiguration": "production"
Expand Down
25 changes: 25 additions & 0 deletions wowskarma.app/src/environments/environment.preview.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
export const environment = {
name: "preview",

apiHost: {
EU: "https://api.preview.wows-karma.com",
NA: "https://api.preview.wows-karma.com",
CIS: "https://api.preview.wows-karma.com",
SEA: "https://api.preview.wows-karma.com",
},

applicationInsights: {
connectionString: "InstrumentationKey=3fab5b95-b531-4f15-95e9-83f31e2ed531;IngestionEndpoint=https://francecentral-1.in.applicationinsights.azure.com/;LiveEndpoint=https://francecentral.livediagnostics.monitor.azure.com/",
},

cookies: {
domain: "localhost",

name: {
EU: "Auth_EU",
NA: "Auth_NA",
CIS: "Auth_CIS",
SEA: "Auth_SEA",
},
},
};
2 changes: 1 addition & 1 deletion wowskarma.app/src/environments/environment.prod.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export const environment = {
production: true,
name: "production",

apiHost: {
EU: "https://api.wows-karma.com",
Expand Down
2 changes: 1 addition & 1 deletion wowskarma.app/src/environments/environment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// The list of file replacements can be found in `angular.json`.

export const environment = {
production: false,
name: "development",

apiHost: {
EU: "http://localhost:5010",
Expand Down
2 changes: 1 addition & 1 deletion wowskarma.app/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { AppModule } from './app/app.module';
import { environment } from './environments/environment';

if (environment.production) {
if (environment.name === "production") {
enableProdMode();
//console.debug = (...args: any[]) => {};
}
Expand Down

0 comments on commit e0e9e4c

Please sign in to comment.