From 906b1c9620ab5654e1bef52eef4c41a12da5c634 Mon Sep 17 00:00:00 2001 From: Art Date: Sat, 25 Sep 2021 01:08:19 +0300 Subject: [PATCH] deploy frontend into s3 bucket (#33, #32) --- README.md | 47 +++++++++++++++++++ .../src/main/resources/application.yml | 4 +- support-portal-frontend/angular.json | 21 +++++++++ .../src/environments/environment.test.ts | 5 ++ 4 files changed, 75 insertions(+), 2 deletions(-) create mode 100644 support-portal-frontend/src/environments/environment.test.ts diff --git a/README.md b/README.md index 96a3ae3..4afd821 100644 --- a/README.md +++ b/README.md @@ -174,3 +174,50 @@ WantedBy=multi-user.target - and another - Username: `shyshkin.art` - Password: `5C<"0dVx=>` + +#### 33 deploy frontend into s3 bucket + +1. S3 console + - Create bucket: `portal.shyshkin.net` +2. Build Angular app + - create `environment.test.ts` + - modify `angular.json` + - `ng build -c test` +3. Copy files from `dist/support-portal-frontend` to the bucket +4. Static website hosting + - Enable + - index.html +5. Allow public access + - `Block public access (bucket settings)` - All OFF +6. Edit bucket policy + - `{` + - ` "Version": "2012-10-17",` + - ` "Statement": [` + - ` {` + - ` "Sid": "PublicRead",` + - ` "Effect": "Allow",` + - ` "Principal": "*",` + - ` "Action": [` + - ` "s3:GetObject",` + - ` "s3:GetObjectVersion"` + - ` ],` + - ` "Resource": "arn:aws:s3:::portal.shyshkin.net/*"` + - ` }` + - ` ]` + - `}` +7. Visit `http://portal.shyshkin.net.s3-website.eu-north-1.amazonaws.com` +8. Make an Alias to Website + - Route 53 console + - Hosted zone: shyshkin.net + - Add record + - Name: portal + - Record Type: A + - Routing policy: Simple routing + - Alias: true + - Alias to S3 website endpoint + - Stockholm + - s3-website.eu-north-1.amazonaws.com +9. Tune CORS for backend + - add `http://portal.shyshkin.net` + + \ No newline at end of file diff --git a/support-portal-backend/src/main/resources/application.yml b/support-portal-backend/src/main/resources/application.yml index 7fd388a..9102095 100644 --- a/support-portal-backend/src/main/resources/application.yml +++ b/support-portal-backend/src/main/resources/application.yml @@ -42,7 +42,7 @@ spring: app: public-urls: /user/login,/user/register,/user/*/image/**,/user/image/** cors: - allowed-origins: http://localhost:4200,https://localhost:4200,http://art-support-portal.s3-website.eu-north-1.amazonaws.com + allowed-origins: http://localhost:4200,https://localhost:4200,http://art-support-portal.s3-website.eu-north-1.amazonaws.com,http://portal.shyshkin.net jwt: secret: VeRy_5ecretP@55W0rd! # secret: ${random.value} #Does not work - every time generates new value @@ -80,7 +80,7 @@ app: from: d.art.shishkin@gmail.com carbon-copy: d.art.shishkin@gmail.com cors: - allowed-origins: http://localhost:4200,http://art-support-portal.s3-website.eu-north-1.amazonaws.com,http://support-portal.shyshkin.net + allowed-origins: http://localhost:4200,http://art-support-portal.s3-website.eu-north-1.amazonaws.com,http://support-portal.shyshkin.net,http://portal.shyshkin.net server: port: 5000 logging: diff --git a/support-portal-frontend/angular.json b/support-portal-frontend/angular.json index 4d3c106..3b512d7 100644 --- a/support-portal-frontend/angular.json +++ b/support-portal-frontend/angular.json @@ -56,6 +56,27 @@ ], "outputHashing": "all" }, + "test": { + "budgets": [ + { + "type": "initial", + "maximumWarning": "500kb", + "maximumError": "1mb" + }, + { + "type": "anyComponentStyle", + "maximumWarning": "2kb", + "maximumError": "4kb" + } + ], + "fileReplacements": [ + { + "replace": "src/environments/environment.ts", + "with": "src/environments/environment.test.ts" + } + ], + "outputHashing": "all" + }, "development": { "buildOptimizer": false, "optimization": false, diff --git a/support-portal-frontend/src/environments/environment.test.ts b/support-portal-frontend/src/environments/environment.test.ts new file mode 100644 index 0000000..523fbe8 --- /dev/null +++ b/support-portal-frontend/src/environments/environment.test.ts @@ -0,0 +1,5 @@ +export const environment = { + production: false, + apiUrl: 'http://localhost:8080', + publicUrls: ['/user/login', '/user/register', '/user/*/image/**', '/user/image/**'] +};