Skip to content

Commit d9cc062

Browse files
Added Dockerfile to payment and authentication services
1 parent 29febfb commit d9cc062

File tree

18 files changed

+234
-61
lines changed

18 files changed

+234
-61
lines changed

client/src/actions/index.js

Lines changed: 59 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -83,22 +83,65 @@ export const signInUsingOAuth = googleAuth => async dispatch => {
8383
log.info('[signInUsingOAuth] User has not signed in yet')
8484

8585
// sign in
86-
googleAuth.signIn(JSON.parse(googleAuth.currentUser.get().getId())).then(() => {
87-
// if sign in works
88-
if (googleAuth.isSignedIn.get()) {
89-
log.info('[signInUsingOAuth] User is signed in successfully')
90-
// here we are sure that we signed in and now dispatch.
91-
dispatch({
92-
type: HANDLE_GOOGLE_AUTH_SIGN_IN,
93-
payload: {
94-
firstName: "Norman",
95-
oAuth: googleAuth
96-
}
97-
})
98-
99-
history.push("/");
86+
googleAuth.signIn(JSON.parse(googleAuth.currentUser.get().getId())).then(async () => {
87+
88+
// if sign in works
89+
if (googleAuth.isSignedIn.get()) {
90+
log.info('[signInUsingOAuth] User is signed in successfully')
91+
92+
dispatch({
93+
type: HANDLE_GOOGLE_AUTH_SIGN_IN,
94+
payload: {
95+
firstName: googleAuth.currentUser.get().getBasicProfile().getGivenName(),
96+
oAuth: googleAuth
97+
}
98+
})
99+
history.push("/");
100+
101+
// try {
102+
// let userProfile = googleAuth.currentUser.get().getBasicProfile()
103+
// if (userProfile) {
104+
// authServiceAPI.defaults.timeout = 15000;
105+
// const response = await authServiceAPI.post('/signin-using-google-auth', {
106+
// 'id': userProfile.getId(),
107+
// 'firstname': userProfile.getGivenName(),
108+
// 'lastname': userProfile.getFamilyName(),
109+
// 'email': userProfile.getEmail(),
110+
// 'username': null,
111+
// 'password': null,
112+
// }).catch(err => {
113+
// log.info(`[ACTION]: signUp dispatch HANDLE_SIGN_UP_ERROR err.message = ${err.message}.`)
114+
// });
115+
//
116+
// if(response.data === "success") {
117+
// // here we are sure that we signed in and now dispatch.
118+
// dispatch({
119+
// type: HANDLE_GOOGLE_AUTH_SIGN_IN,
120+
// payload: {
121+
// oAuth: googleAuth
122+
// }
123+
// })
124+
// history.push("/");
125+
// } else {
126+
// dispatch({type: HANDLE_SIGN_IN_ERROR, payload: response.data.error});
127+
// }
128+
129+
// dispatch({
130+
// type: HANDLE_GOOGLE_AUTH_SIGN_IN,
131+
// payload: {
132+
// oAuth: googleAuth
133+
// }
134+
// })
135+
// history.push("/");
136+
// }
137+
// } catch
138+
// (e) {
139+
// log.info(`[signInUsingOAuth] Unable to retrieve user profile.`)
140+
// dispatch({type: HANDLE_SIGN_IN_ERROR, payload: "Unable to retrieve user profile."});
141+
// }
142+
}
100143
}
101-
})
144+
)
102145
}
103146
}
104147

@@ -160,7 +203,7 @@ export const sendPaymentToken = (token) => async dispatch => {
160203
log.info(`Token = ${JSON.stringify(token)}`)
161204
let config = {
162205
method: 'post',
163-
url: 'http://localhost:9050/payment',
206+
url: `http://localhost:${process.env.REACT_APP_PAYMENT_SERVICE_PORT}/payment`,
164207
headers: {
165208
'Content-Type': 'application/json'
166209
},

client/src/api/service_api.js

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
import axios from 'axios';
22

3-
const {REACT_APP_COMMON_DATA_SERVICE_IP, REACT_APP_COMMON_DATA_SERVICE_PORT} = process.env
4-
5-
export const paymentServiceAPI = axios.create({
6-
baseURL: 'http://localhost:9050'
7-
})
3+
const {
4+
REACT_APP_COMMON_DATA_SERVICE_PORT,
5+
REACT_APP_AUTHENTICATION_SERVICE_PORT
6+
} = process.env
87

98
export const authServiceAPI = axios.create({
10-
baseURL: 'http://localhost:7000'
9+
baseURL: `http://localhost:${REACT_APP_AUTHENTICATION_SERVICE_PORT}`
1110
})
1211

1312
export const commonServiceAPI = axios.create({
14-
baseURL: `http://${REACT_APP_COMMON_DATA_SERVICE_IP}:${REACT_APP_COMMON_DATA_SERVICE_PORT}`
13+
baseURL: `http://localhost:${REACT_APP_COMMON_DATA_SERVICE_PORT}`
1514
})

client/src/components/routes/navbar/navBar.js

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -87,13 +87,14 @@ const NavBar = props => {
8787
window.gapi.load('client:auth2', () => {
8888
window.gapi.client.init({
8989
clientId: process.env.REACT_APP_GOOGLE_AUTH_CLIENT_ID,
90-
scope: 'email'
90+
scope: 'profile'
9191
}).then(() => {
9292
const auth = window.gapi.auth2.getAuthInstance();
9393
dispatch({
9494
type: SET_GOOGLE_AUTH,
9595
payload: {
96-
firstName: "Norman",
96+
firstName: auth.currentUser.get().getBasicProfile() ?
97+
auth.currentUser.get().getBasicProfile().getGivenName() : null,
9798
oAuth: auth
9899
}
99100
})
@@ -102,7 +103,9 @@ const NavBar = props => {
102103
} catch (e) {
103104
log.info(`[Navbar] Failed to load google OAuth.`)
104105
}
105-
} else if (isSignedIn === null) {
106+
}
107+
108+
if (isSignedIn === null) {
106109
// if user is not signed in then signed it in using
107110
// account details from the cookie.
108111

@@ -148,12 +151,19 @@ const NavBar = props => {
148151
}
149152

150153
if (isSignedIn || googleAuthReducer.isSignedInUsingOAuth) {
154+
let fName
155+
if (firstName) {
156+
fName = firstName
157+
} else if (googleAuthReducer.isSignedInUsingOAuth) {
158+
fName = googleAuthReducer.firstName
159+
} else {
160+
fName = "S"
161+
}
162+
151163
authIcon = <Avatar className={classes.orange} sizes="small"
152164
style={{width: 20, height: 20, marginBottom: 3}}>
153-
{firstName ? firstName.charAt(0)
154-
: googleAuthReducer.isSignedInUsingOAuth ?
155-
googleAuthReducer.firstName.charAt(0) : "S"}
156-
</Avatar>
165+
{fName.charAt(0).toUpperCase()}
166+
</Avatar>
157167
authLabel = "Sign Out"
158168
} else {
159169
authIcon = <AccountCircle/>

client/src/components/routes/signin/GoogleAuthButton.js

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,6 @@ class GoogleAuthButton extends React.Component {
1111
};
1212

1313
render() {
14-
if(!this.props.googleAuthReducer.oAuth) {
15-
log.info(`[GoogleAuthButton] Failed to load Google OAuth`)
16-
return null
17-
}
18-
1914
log.info('[GoogleAuthButton] Rendering GoogleAuthButton Component')
2015
return (
2116
<Button className='googleButtonStyle' color='google plus' onClick={this.onSignInClick}>

client/src/components/routes/signin/signIn.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ const SignIn = () => {
2222
log.info(`[SignIn]: Component did mount...`)
2323
setIsLoading(false)
2424

25+
// eslint-disable-next-line
2526
}, [timestamp])
2627

2728
if ((isSignedIn !== null && isSignedIn)

client/src/reducers/screens/commonScreenReducer.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,14 @@ import _ from "lodash";
3333

3434

3535
export const signInReducer = (state
36-
= {isSignedIn: null, timestamp: null, firstName: null, oAuth: null}, action) => {
36+
= {isSignedIn: null, timestamp: null, firstName: null}, action) => {
3737

3838
// timestamp is used to update the state so that
3939
// we can stop loading progress component
4040
switch (action.type) {
4141
case HANDLE_SIGN_IN:
4242
return {
43-
...state, isSignedIn: true, tokenId: action.payload.jwt,
43+
...state, isSignedIn: true, tokenId: action.payload.jwt, errorMsg: null,
4444
firstName: action.payload.firstName, timestamp: Date.now()
4545
};
4646
case HANDLE_SIGN_IN_ERROR:

docker-compose.yml

Lines changed: 54 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,33 @@ services:
2525
networks:
2626
- spring-cloud-microservices
2727

28+
authentication-service:
29+
build:
30+
context: .
31+
dockerfile: ./server/authentication-service/Dockerfile
32+
container_name: authentication-service-container
33+
restart: always
34+
depends_on:
35+
- mysql-db
36+
- redis-cache
37+
- react-ui
38+
environment:
39+
- DB_HOST=mysql-db
40+
- DB_PORT=${DB_PORT}
41+
- DB_USER=${DB_USER}
42+
- DB_PASS=${DB_PASS}
43+
- DB_SCHEMA=${DB_SCHEMA}
44+
- ACTIVE_PROFILE=${ACTIVE_PROFILE}
45+
- REACT_APP_AUTHENTICATION_SERVICE_PORT=${AUTHENTICATION_SERVICE_PORT}
46+
links:
47+
- mysql-db:mysql
48+
expose:
49+
- ${AUTHENTICATION_SERVICE_PORT}
50+
ports:
51+
- ${AUTHENTICATION_SERVICE_PORT}:${AUTHENTICATION_SERVICE_PORT}
52+
networks:
53+
- spring-cloud-microservices
54+
2855
common-data-service:
2956
build:
3057
context: .
@@ -55,6 +82,33 @@ services:
5582
networks:
5683
- spring-cloud-microservices
5784

85+
payment-service:
86+
build:
87+
context: .
88+
dockerfile: ./server/payment-service/Dockerfile
89+
container_name: payment-service-container
90+
restart: always
91+
depends_on:
92+
- mysql-db
93+
- redis-cache
94+
- react-ui
95+
environment:
96+
- DB_HOST=mysql-db
97+
- DB_PORT=${DB_PORT}
98+
- DB_USER=${DB_USER}
99+
- DB_PASS=${DB_PASS}
100+
- DB_SCHEMA=${DB_SCHEMA}
101+
- ACTIVE_PROFILE=${ACTIVE_PROFILE}
102+
- REACT_APP_PAYMENT_SERVICE_PORT=${PAYMENT_SERVICE_PORT}
103+
links:
104+
- mysql-db:mysql
105+
expose:
106+
- ${PAYMENT_SERVICE_PORT}
107+
ports:
108+
- ${PAYMENT_SERVICE_PORT}:${PAYMENT_SERVICE_PORT}
109+
networks:
110+
- spring-cloud-microservices
111+
58112
react-ui:
59113
build:
60114
context: .
@@ -68,7 +122,6 @@ services:
68122
- ${REACT_APP_PORT}:${REACT_APP_PORT}
69123
environment:
70124
- REACT_APP_STRIPE_PUBLISH_KEY=${REACT_APP_STRIPE_PUBLISH_KEY}
71-
- REACT_APP_COMMON_DATA_SERVICE_IP=${REACT_APP_COMMON_DATA_SERVICE_IP}
72125
- REACT_APP_COMMON_DATA_SERVICE_PORT=${COMMON_DATA_SERVICE_PORT}
73126
volumes:
74127
- ./client:/usr/src/app
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Docker multi-stage build
2+
3+
# 1. Building the App with Maven
4+
FROM maven:3-jdk-11
5+
6+
ADD ./server/authentication-service /authentication_service_staging
7+
8+
WORKDIR /authentication_service_staging
9+
10+
# Just echo so we can see, if everything is there
11+
RUN ls -l
12+
13+
# Run Maven build
14+
RUN mvn clean install -DskipTests
15+
16+
# 2. Just using the build artifact and then removing the build-container
17+
FROM openjdk:11-jdk
18+
19+
VOLUME /tmp
20+
21+
# Add Spring Boot authentication-service.jar to Container
22+
COPY --from=0 /authentication_service_staging/target/authentication-service.jar authentication-service.jar
23+
24+
# Fire up our Spring Boot app by default
25+
CMD ["sh", "-c", "java -Dserver.port=$AUTHENTICATION_SERVICE_PORT -Xmx300m -Xss512k -XX:CICompilerCount=2 -Dfile.encoding=UTF-8 -XX:+UseContainerSupport -Dspring.profiles.active=$ACTIVE_PROFILE -Djava.security.egd=file:/dev/./urandom -jar authentication-service.jar" ]
26+

server/authentication-service/pom.xml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,19 @@
8787
</dependencies>
8888

8989
<build>
90+
<finalName>authentication-service</finalName>
9091
<plugins>
9192
<plugin>
9293
<groupId>org.springframework.boot</groupId>
9394
<artifactId>spring-boot-maven-plugin</artifactId>
95+
<executions>
96+
<execution>
97+
<id>repackage</id>
98+
<goals>
99+
<goal>repackage</goal>
100+
</goals>
101+
</execution>
102+
</executions>
94103
</plugin>
95104
</plugins>
96105
</build>

server/authentication-service/src/main/resources/application.properties

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
spring.application.name=authentication-service
2-
server.port=7000
3-
spring.datasource.url=jdbc:mysql://localhost:3306/ecommerce_data?useSSL=false&serverTimezone=UTC
4-
spring.datasource.username=springstudent
5-
spring.datasource.password=springstudent
6-
#spring.datasource.url=jdbc:mysql://${DB_HOST:localhost}:${DB_PORT:6603}/${DB_SCHEMA}?autoReconnect=true&failOverReadOnly=false&maxReconnects=2
2+
server.port=${AUTHENTICATION_SERVICE_PORT}
3+
spring.datasource.url=jdbc:mysql://${DB_HOST}:${DB_PORT}/${DB_SCHEMA}?allowPublicKeyRetrieval=true&useSSL=false&serverTimezone=UTC
4+
spring.datasource.username=${DB_USER}
5+
spring.datasource.password=${DB_PASS}
6+
77
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
8+
spring.jpa.generate-ddl=true
89
#spring.datasource.initialization-mode=always
910
#spring.jpa.hibernate.ddl-auto=create-drop
10-
spring.jpa.generate-ddl=true
11-
spring.profiles.active=dev
1211

1312
# debugging purpose
1413
spring.jpa.properties.hibernate.format_sql=true

0 commit comments

Comments
 (0)