Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
client.js
node_modules/
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules/
1 change: 0 additions & 1 deletion 1

This file was deleted.

49 changes: 49 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# Copyright 2020 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

FROM node:20.2.0-alpine@sha256:f25b0e9d3d116e267d4ff69a3a99c0f4cf6ae94eadd87f1bf7bd68ea3ff0bef7 as base

FROM base as builder

# Some packages (e.g. @google-cloud/profiler) require additional
# deps for post-install scripts
RUN apk add --update --no-cache \
python3 \
make \
g++

WORKDIR /usr/src/app

COPY package*.json ./

RUN npm install --only=production

FROM base as without-grpc-health-probe-bin

WORKDIR /usr/src/app

COPY --from=builder /usr/src/app/node_modules ./node_modules

COPY . .

EXPOSE 7000

ENTRYPOINT [ "node", "server.js" ]

FROM without-grpc-health-probe-bin

# renovate: datasource=github-releases depName=grpc-ecosystem/grpc-health-probe
ENV GRPC_HEALTH_PROBE_VERSION=v0.4.18
RUN wget -qO/bin/grpc_health_probe https://github.com/grpc-ecosystem/grpc-health-probe/releases/download/${GRPC_HEALTH_PROBE_VERSION}/grpc_health_probe-linux-amd64 && \
chmod +x /bin/grpc_health_probe
25 changes: 25 additions & 0 deletions Jenkinsfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
pipeline {
agent any

stages {
stage('Build & Tag Docker Image') {
steps {
script {
withDockerRegistry(credentialsId: 'docker-cred', toolName: 'docker') {
sh "docker build -t abhishek0768/currencyservice:latest ."
}
}
}
}

stage('Push Docker Image') {
steps {
script {
withDockerRegistry(credentialsId: 'docker-cred', toolName: 'docker') {
sh "docker push abhishek0768/currencyservice:latest "
}
}
}
}
}
}
68 changes: 68 additions & 0 deletions client.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/*
*
* Copyright 2015 gRPC authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
require('@google-cloud/trace-agent').start();

const path = require('path');
const grpc = require('grpc');
const pino = require('pino');

const PROTO_PATH = path.join(__dirname, './proto/demo.proto');
const PORT = 7000;

const shopProto = grpc.load(PROTO_PATH).hipstershop;
const client = new shopProto.CurrencyService(`localhost:${PORT}`,
grpc.credentials.createInsecure());

const logger = pino({
name: 'currencyservice-client',
messageKey: 'message',
formatters: {
level (logLevelString, logLevelNum) {
return { severity: logLevelString }
}
}
});

const request = {
from: {
currency_code: 'CHF',
units: 300,
nanos: 0
},
to_code: 'EUR'
};

function _moneyToString (m) {
return `${m.units}.${m.nanos.toString().padStart(9,'0')} ${m.currency_code}`;
}

client.getSupportedCurrencies({}, (err, response) => {
if (err) {
logger.error(`Error in getSupportedCurrencies: ${err}`);
} else {
logger.info(`Currency codes: ${response.currency_codes}`);
}
});

client.convert(request, (err, response) => {
if (err) {
logger.error(`Error in convert: ${err}`);
} else {
logger.log(`Convert: ${_moneyToString(request.from)} to ${_moneyToString(response)}`);
}
});
35 changes: 35 additions & 0 deletions data/currency_conversion.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"EUR": "1.0",
"USD": "1.1305",
"JPY": "126.40",
"BGN": "1.9558",
"CZK": "25.592",
"DKK": "7.4609",
"GBP": "0.85970",
"HUF": "315.51",
"PLN": "4.2996",
"RON": "4.7463",
"SEK": "10.5375",
"CHF": "1.1360",
"ISK": "136.80",
"NOK": "9.8040",
"HRK": "7.4210",
"RUB": "74.4208",
"TRY": "6.1247",
"AUD": "1.6072",
"BRL": "4.2682",
"CAD": "1.5128",
"CNY": "7.5857",
"HKD": "8.8743",
"IDR": "15999.40",
"ILS": "4.0875",
"INR": "79.4320",
"KRW": "1275.05",
"MXN": "21.7999",
"MYR": "4.6289",
"NZD": "1.6679",
"PHP": "59.083",
"SGD": "1.5349",
"THB": "36.012",
"ZAR": "16.0583"
}
23 changes: 23 additions & 0 deletions genproto.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/bin/bash -eu
#
# Copyright 2018 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# [START gke_currencyservice_genproto]

# protos are loaded dynamically for node, simply copies over the proto.
mkdir -p proto
cp -r ../../protos/* ./proto

# [END gke_currencyservice_genproto]
Loading