Skip to content

Commit 43faa31

Browse files
committed
Merge branch 'develop'
2 parents 3894122 + 19c41dd commit 43faa31

33 files changed

+283
-291
lines changed

.github/workflows/integration.yml

+7-39
Original file line numberDiff line numberDiff line change
@@ -29,43 +29,11 @@ jobs:
2929
- name: Get the version
3030
id: get_version
3131
run: "echo ::set-output name=VERSION::$(cat package.json | grep version | head -1 | awk -F: '{ print $2 }' | sed 's/[\",]//g' | tr -d '[[:space:]]')"
32-
- name: Generate git ref in environment variables
33-
run: "sed -i -E \"s|gitRef: '(.*)'|gitRef: '$GITHUB_SHA'|g\" src/environments/environment.heroku.ts"
34-
- name: Generate version in environment variables
35-
run: "sed -i -E \"s|version: '(.*)'|version: '${{ steps.get_version.outputs.VERSION }}'|g\" src/environments/environment.heroku.ts"
3632
- name: Build the Docker image
37-
run: docker build . --file Dockerfile --build-arg configuration=heroku-fr --tag docker.pkg.github.com/les-projets-cagnottes/web/web:heroku-${{ steps.get_version.outputs.VERSION }}
38-
- name: Login to Registry
39-
run: docker login docker.pkg.github.com -u thomah -p ${{secrets.GITHUB_TOKEN}}
40-
- name: Publish to Registry
41-
run: docker push docker.pkg.github.com/les-projets-cagnottes/web/web:heroku-${{ steps.get_version.outputs.VERSION }}
42-
43-
deploy-heroku:
44-
needs: publish-docker
45-
runs-on: ubuntu-latest
46-
steps:
47-
- uses: actions/checkout@v2
48-
- uses: sjdonado/heroku@0f16401029a67519b6547af7247983640996393a
49-
- name: Get the version
50-
id: get_version
51-
run: "echo ::set-output name=VERSION::$(cat package.json | grep version | head -1 | awk -F: '{ print $2 }' | sed 's/[\",]//g' | tr -d '[[:space:]]')"
52-
- name: Login to Registry
53-
run: docker login docker.pkg.github.com -u thomah -p ${{secrets.GITHUB_TOKEN}}
54-
- name: Pull Docker Image
55-
run: docker pull docker.pkg.github.com/les-projets-cagnottes/web/web:heroku-${{ steps.get_version.outputs.VERSION }}
56-
- name: Tag the image
57-
run: docker tag docker.pkg.github.com/les-projets-cagnottes/web/web:heroku-${{ steps.get_version.outputs.VERSION }} registry.heroku.com/les-projets-cagnottes/web
58-
- name: Get Heroku Tools
59-
run: wget -qO- https://toolbelt.heroku.com/install.sh | sh
60-
- name: Login to Heroku Registry
61-
run: echo "${{secrets.HEROKU_PASSWORD}}" | docker login -u "${{secrets.HEROKU_USERNAME}}" --password-stdin registry.heroku.com
62-
- name: Login to Heroku API
63-
run: heroku container:login
64-
env:
65-
HEROKU_API_KEY: ${{secrets.HEROKU_PASSWORD}}
66-
- name: Publish to Heroku Registry
67-
run: docker push registry.heroku.com/les-projets-cagnottes/web
68-
- name: Release Heroku app
69-
run: heroku container:release web --app les-projets-cagnottes
70-
env:
71-
HEROKU_API_KEY: ${{secrets.HEROKU_PASSWORD}}
33+
run: docker build . --file Dockerfile --build-arg configuration=production --tag web:latest
34+
- name: Tag the image for Docker Hub
35+
run: docker tag web:latest lesprojetscagnottes/web:${{ steps.get_version.outputs.VERSION }}
36+
- name: Login to Docker Hub
37+
run: docker login -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_PASSWORD }}
38+
- name: Publish to Docker Hub
39+
run: docker push lesprojetscagnottes/web:${{ steps.get_version.outputs.VERSION }}

.github/workflows/pre-release.yml

+1-3
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,11 @@ jobs:
4242
run: echo ::set-output name=VERSION::$(sed "s/-SNAPSHOT//g" <<<"${{ steps.get_previous_version.outputs.VERSION }}")
4343
- name: Get release
4444
id: get_release
45-
run: echo ::set-output name=RELEASE_HTTP_CODE::$(curl -s -o out.html -w '%{http_code}' https://github.com/les-projets-cagnottes/slack-events-catcher/releases/tag/${{ steps.get_released_version.outputs.VERSION }};)
45+
run: echo ::set-output name=RELEASE_HTTP_CODE::$(curl -s -o out.html -w '%{http_code}' https://github.com/les-projets-cagnottes/web/releases/tag/${{ steps.get_released_version.outputs.VERSION }};)
4646
- name: Test release existence
4747
run: if [[ "${{ steps.get_release.outputs.RELEASE_HTTP_CODE }}" -eq "200" ]]; then exit 1; else exit 0; fi
4848
- name: Replace version without snapshot
4949
run: "sed -i 's/\"version\": \"${{ steps.get_previous_version.outputs.VERSION }}\"/\"version\": \"${{ steps.get_released_version.outputs.VERSION }}\"/g' package.json"
50-
- name: Generate version in environment variables
51-
run: "sed -i -E \"s|version: '(.*)'|version: '${{ steps.get_released_version.outputs.VERSION }}'|g\" src/environments/environment.prod.ts"
5250
- name: Use Node.js ${{ matrix.node-version }}
5351
uses: actions/setup-node@v1
5452
with:

.github/workflows/release.yml

+8-53
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ jobs:
2020
run: if [[ "${{ steps.get_version.outputs.VERSION }}" == *"-SNAPSHOT" ]]; then exit 1; else exit 0; fi
2121
- name: Get release
2222
id: get_release
23-
run: echo ::set-output name=RELEASE_HTTP_CODE::$(curl -s -o out.html -w '%{http_code}' https://github.com/les-projets-cagnottes/slack-events-catcher/releases/tag/${{ steps.get_version.outputs.VERSION }};)
23+
run: echo ::set-output name=RELEASE_HTTP_CODE::$(curl -s -o out.html -w '%{http_code}' https://github.com/les-projets-cagnottes/web/releases/tag/${{ steps.get_version.outputs.VERSION }};)
2424
- name: Test release existence
2525
run: if [[ "${{ steps.get_release.outputs.RELEASE_HTTP_CODE }}" -eq "200" ]]; then exit 1; else exit 0; fi
2626

@@ -67,56 +67,11 @@ jobs:
6767
- uses: actions/checkout@v2
6868
with:
6969
ref: '${{ needs.verify-version.outputs.version }}'
70-
- name: Generate git ref in environment variables
71-
run: "sed -i -E \"s|gitRef: '(.*)'|gitRef: '$GITHUB_SHA'|g\" src/environments/environment.heroku.ts"
7270
- name: Build the Docker image
73-
run: docker build . --file Dockerfile --build-arg configuration=heroku-fr --tag docker.pkg.github.com/les-projets-cagnottes/web/web:heroku-${{ needs.verify-version.outputs.version }}
74-
- name: Login to Registry
75-
run: docker login docker.pkg.github.com -u thomah -p ${{secrets.GITHUB_TOKEN}}
76-
- name: Publish to Registry
77-
run: docker push docker.pkg.github.com/les-projets-cagnottes/web/web:heroku-${{ needs.verify-version.outputs.version }}
78-
79-
deploy-production:
80-
needs: [verify-version, release]
81-
runs-on: ubuntu-latest
82-
steps:
83-
- uses: actions/checkout@v2
84-
with:
85-
ref: '${{ needs.verify-version.outputs.version }}'
86-
- name: Use Node.js 10.x
87-
uses: actions/setup-node@v1
88-
with:
89-
node-version: 10.x
90-
- name: Generate git ref in environment variables
91-
run: "sed -i -E \"s|gitRef: '(.*)'|gitRef: '$GITHUB_SHA'|g\" src/environments/environment.heroku.ts"
92-
- run: npm ci
93-
- run: npm run build -- --configuration production-fr --output-path=dist
94-
- name: Get the version
95-
id: get_version
96-
run: "echo ::set-output name=VERSION::$(cat package.json | grep version | head -1 | awk -F: '{ print $2 }' | sed 's/[\",]//g' | tr -d '[[:space:]]')"
97-
- name: Create temp directory to copy files
98-
uses: appleboy/[email protected]
99-
with:
100-
host: ${{ secrets.PRODUCTION_HOST }}
101-
username: ${{ secrets.PRODUCTION_USER }}
102-
key : ${{ secrets.PRODUCTION_KEY }}
103-
port: ${{ secrets.PRODUCTION_PORT }}
104-
script: mkdir -p /opt/les-projets-cagnottes/web/deployment
105-
- name: Copy content recursively to production
106-
uses: appleboy/[email protected]
107-
with:
108-
host: ${{ secrets.PRODUCTION_HOST }}
109-
username: ${{ secrets.PRODUCTION_USER }}
110-
key : ${{ secrets.PRODUCTION_KEY }}
111-
port: ${{ secrets.PRODUCTION_PORT }}
112-
source: "dist,bin/deploy.sh"
113-
target: /opt/les-projets-cagnottes/web/deployment
114-
rm: true
115-
- name: Execute deployment remotely
116-
uses: appleboy/[email protected]
117-
with:
118-
host: ${{ secrets.PRODUCTION_HOST }}
119-
username: ${{ secrets.PRODUCTION_USER }}
120-
key : ${{ secrets.PRODUCTION_KEY }}
121-
port: ${{ secrets.PRODUCTION_PORT }}
122-
script: (sudo chmod 755 /opt/les-projets-cagnottes/web/deployment/bin/deploy.sh) && (nohup /opt/les-projets-cagnottes/web/deployment/bin/deploy.sh ${{ steps.get_version.outputs.VERSION }} &> /opt/les-projets-cagnottes/web/deployment/bin/console.log < /dev/null &) && exit 0
71+
run: docker build . --file Dockerfile --build-arg configuration=production --tag web:latest
72+
- name: Tag the image for Docker Hub
73+
run: docker tag web:latest lesprojetscagnottes/web:${{ steps.get_version.outputs.VERSION }}
74+
- name: Login to Docker Hub
75+
run: docker login -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_PASSWORD }}
76+
- name: Publish to Docker Hub
77+
run: docker push lesprojetscagnottes/web:${{ steps.get_version.outputs.VERSION }}

Dockerfile

+2-4
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,7 @@ RUN npm run ng build -- --configuration $configuration --output-path=dist
1010

1111
FROM nginx:1.17.3
1212

13-
ARG configuration
14-
15-
COPY nginx/${configuration}.conf /etc/nginx/conf.d/default.conf
13+
COPY nginx/nginx.conf /etc/nginx/conf.d/default.conf
1614
RUN rm -rf /usr/share/nginx/html/*
17-
COPY --from=builder /ng-app/dist/fr /usr/share/nginx/html
15+
COPY --from=builder /ng-app/dist /usr/share/nginx/html
1816
CMD sed -i -e 's/$PORT/'"$PORT"'/g' /etc/nginx/conf.d/default.conf && nginx -g 'daemon off;'

README.md

+55-5
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,60 @@
77

88
- Les Projets Cagnottes - core - [Install Guide here](https://github.com/les-projets-cagnottes/core#getting-started)
99
- NodeJS 12 - [Download here](https://nodejs.org)
10-
- Angular CLI 8.1.2 - [Download here](https://cli.angular.io)
10+
- Angular CLI 10+ - [Download here](https://cli.angular.io)
1111

12-
## Getting Started
12+
## Build
1313

14-
1. Install node modules : `npm install`
15-
2. Run the Angular App : `ng serve`
16-
3. Access the URL : [http://localhost:4200](http://localhost:4200)
14+
### Build with Angular CLI
15+
16+
With [Angular CLI](https://github.com/angular/angular-cli), you can build the app only :
17+
18+
```bash
19+
npm install
20+
ng build
21+
```
22+
23+
### Build the Docker image
24+
25+
With Docker, you can build the image :
26+
27+
```bash
28+
docker build . --build-arg configuration=production
29+
```
30+
31+
## Run
32+
33+
### Run locally in development
34+
35+
With [Angular CLI](https://github.com/angular/angular-cli), you can run a dev server :
36+
37+
```bash
38+
npm install
39+
ng serve
40+
```
41+
42+
Navigate to `http://localhost:4200/`. The app will automatically reload if you change any of the source files.
43+
44+
### Run with Docker
45+
46+
On your host, create a `config.json` file with the following content :
47+
48+
```json
49+
{
50+
"webUrl": "http://localhost:4200",
51+
"apiUrl": "http://localhost:8080/api",
52+
"slackClientId": "1267900044419.1280463132273",
53+
"version": "head",
54+
"versionUrl": "head"
55+
}
56+
```
57+
58+
Then, run the command :
59+
60+
```bash
61+
docker run -d --name web \
62+
-p 80:80 \
63+
-e PORT="80" \
64+
-v <YOUR_HOST_DIRECTORY>/config.json:/usr/share/nginx/html/assets/config.json \
65+
lesprojetscagnottes/web:<tag>
66+
```

angular.json

+1-36
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@
8787
]
8888
},
8989
"configurations": {
90-
"production-fr": {
90+
"production": {
9191
"fileReplacements": [{
9292
"replace": "src/environments/environment.ts",
9393
"with": "src/environments/environment.prod.ts"
@@ -113,38 +113,6 @@
113113
"maximumWarning": "6kb"
114114
}
115115
]
116-
},
117-
"heroku-fr": {
118-
"fileReplacements": [{
119-
"replace": "src/environments/environment.ts",
120-
"with": "src/environments/environment.heroku.ts"
121-
}],
122-
"localize": [
123-
"fr"
124-
],
125-
"optimization": true,
126-
"outputHashing": "all",
127-
"sourceMap": false,
128-
"extractCss": true,
129-
"namedChunks": false,
130-
"extractLicenses": true,
131-
"vendorChunk": false,
132-
"buildOptimizer": true,
133-
"budgets": [{
134-
"type": "initial",
135-
"maximumWarning": "2mb",
136-
"maximumError": "5mb"
137-
},
138-
{
139-
"type": "anyComponentStyle",
140-
"maximumWarning": "6kb"
141-
}
142-
]
143-
},
144-
"dev": {
145-
"localize": [
146-
"fr"
147-
]
148116
}
149117
}
150118
},
@@ -156,9 +124,6 @@
156124
"configurations": {
157125
"dev": {
158126
"browserTarget": "web:build:dev:fr"
159-
},
160-
"heroku-fr": {
161-
"browserTarget": "web:build:heroku-fr"
162127
}
163128
}
164129
},

nginx/heroku-fr.conf nginx/nginx.conf

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
server {
22
listen $PORT;
3-
server_name les-projets-cagnottes.herokuapp.com;
3+
server_name localhost;
44
keepalive_timeout 5;
55

66
root /usr/share/nginx/html;

package-lock.json

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "les-projets-cagnottes",
3-
"version": "0.7.0",
3+
"version": "0.7.1",
44
"scripts": {
55
"ng": "ng",
66
"start": "ng serve",

src/app/_services/apitoken.service.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
11
import { Injectable } from '@angular/core';
22
import { HttpClient } from '@angular/common/http';
3-
import { environment } from 'src/environments/environment';
3+
import { ConfigService } from '../_services/config/config.service';
44
import { ApiToken } from '../_models';
55

66
@Injectable({
77
providedIn: 'root'
88
})
99
export class ApiTokenService {
10-
constructor(private http: HttpClient) { }
10+
constructor(private http: HttpClient, private configService: ConfigService) { }
1111

1212
getAll() {
13-
return this.http.get<ApiToken[]>(`${environment.apiUrl}/token`);
13+
return this.http.get<ApiToken[]>(`${this.configService.get('apiUrl')}/token`);
1414
}
1515

1616
generateApiToken() {
17-
return this.http.post<ApiToken>(`${environment.apiUrl}/token`, {});
17+
return this.http.post<ApiToken>(`${this.configService.get('apiUrl')}/token`, {});
1818
}
1919

2020
delete(id: number) {
21-
return this.http.delete(`${environment.apiUrl}/token/${id}`);
21+
return this.http.delete(`${this.configService.get('apiUrl')}/token/${id}`);
2222
}
2323

2424
}

src/app/_services/authentication.service.ts

+9-8
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ import { HttpClient } from '@angular/common/http';
33
import { BehaviorSubject, Observable } from 'rxjs';
44
import { forkJoin } from 'rxjs';
55
import { map } from 'rxjs/operators';
6-
import { environment } from '../../environments/environment';
6+
7+
import { ConfigService } from '../_services/config/config.service';
78

89
import { AuthorityModel, OrganizationAuthorityModel, UserModel, OrganizationModel } from '../_models';
910

@@ -17,7 +18,7 @@ export class AuthenticationService {
1718
private currentOrganizationSubject: BehaviorSubject<Organization>;
1819
public currentOrganization: Observable<Organization>;
1920

20-
constructor(private http: HttpClient) {
21+
constructor(private http: HttpClient, private configService: ConfigService) {
2122
this.currentUserSubject = new BehaviorSubject<User>(JSON.parse(localStorage.getItem('currentUser')));
2223
this.currentUser = this.currentUserSubject.asObservable();
2324
if(localStorage.getItem('currentOrganization') != undefined) {
@@ -37,7 +38,7 @@ export class AuthenticationService {
3738
}
3839

3940
login(email: string, password: string) {
40-
return this.http.post<any>(`${environment.apiUrl}/auth/login`,
41+
return this.http.post<any>(`${this.configService.get('apiUrl')}/auth/login`,
4142
{
4243
email,
4344
password
@@ -54,10 +55,10 @@ export class AuthenticationService {
5455
}
5556

5657
whoami(): Observable<User> {
57-
const principal = this.http.get<UserModel>(`${environment.apiUrl}/whoami`);
58-
const authorities = this.http.get<AuthorityModel[]>(`${environment.apiUrl}/authority`);
59-
const orgauthorities = this.http.get<OrganizationAuthorityModel[]>(`${environment.apiUrl}/orgauthorities`);
60-
const organizations = this.http.get<OrganizationModel[]>(`${environment.apiUrl}/organizations`);
58+
const principal = this.http.get<UserModel>(`${this.configService.get('apiUrl')}/whoami`);
59+
const authorities = this.http.get<AuthorityModel[]>(`${this.configService.get('apiUrl')}/authority`);
60+
const orgauthorities = this.http.get<OrganizationAuthorityModel[]>(`${this.configService.get('apiUrl')}/orgauthorities`);
61+
const organizations = this.http.get<OrganizationModel[]>(`${this.configService.get('apiUrl')}/organizations`);
6162
return forkJoin([principal, authorities, orgauthorities, organizations])
6263
.pipe(map(responses =>{
6364
var user = User.fromModel(responses[0]);
@@ -80,7 +81,7 @@ export class AuthenticationService {
8081
}
8182

8283
slack(code: string, redirect_uri) {
83-
return this.http.get<any>(`${environment.apiUrl}/auth/login/slack?code=${code}&redirect_uri=${redirect_uri}`)
84+
return this.http.get<any>(`${this.configService.get('apiUrl')}/auth/login/slack?code=${code}&redirect_uri=${redirect_uri}`)
8485
.pipe(map(user => {
8586
// login successful if there's a jwt token in the response
8687
if (user && user.token) {

0 commit comments

Comments
 (0)