diff --git a/README.asciidoc b/README.asciidoc new file mode 100644 index 0000000..2b47423 --- /dev/null +++ b/README.asciidoc @@ -0,0 +1,129 @@ += Stock Ticker + +== Overview + +[source,console] +---- +$ curl http://stock-ticker.test/stockprice + +Symbol: MSFT + +Week | Closing Price +========================== +2023-02-17 | 258.0600 +2023-02-10 | 263.1000 +2023-02-03 | 258.3500 +2023-01-27 | 248.1600 +2023-01-20 | 240.2200 +2023-01-13 | 239.2300 +2023-01-06 | 224.9300 + +---- + +This is a simple web service that prints the last 'N' weeks of closing stock prices for a particular stock. +The data is retrieved from https://www.alphavantage.co/documentation/[Alpha Vantage's API]. + +The web service servers the following endpoints: + +- `/healthcheck` - Returns `200` if the server is up and running. +- `/stockprice` - Prints the closing prices for the latest N weeks. + +=== Alpha Vantage API Key + +Before running the web service you'll need to obtain an API key from Alpha Vantage. +You can claim a free key from: + +https://www.alphavantage.co/support/#api-key + +=== Required environment variables + +[%header,cols=3*] +|=== +|Environment Variable +|Description +|Example + +|SYMBOL +|The stock's symbol. +|MSFT + +|NWEEKS +|Display the closing price for the last N weeks. +|7 + +|APIKEY +|Your API key from Alpha Vantage. +| +|=== + +=== Command line arguments + +[%header,cols=3*] +|=== +|Argument +|Description +|Default + +|address +|The address that the web server will listen on. +|0.0.0.0:8080 +|=== + +== Running the docker image locally + +The docker image is published to the container registry at Code Flow https://codeflow.dananglin.me.uk/apollo/stock-ticker/packages[here]. +You can pull and run the docker image from the registry with the following command: + +[source,console] +---- +docker run --rm \ + -d \ + -e SYMBOL=MSFT \ + -e NWEEKS=3 \ + -e APIKEY= \ + --publish 8080:8080 \ + --name stock-ticker \ + codeflow.dananglin.me.uk/apollo/stock-ticker:v0.1.0 +---- + +Alternatively you can build and run the docker image locally. + +[source,console] +---- +git clone https://codeflow.dananglin.me.uk/apollo/stock-ticker.git +cd stock-ticker +docker build -t stock-ticker -f deploy/Dockerfile . +docker run --rm \ + -d \ + -e SYMBOL=MSFT \ + -e NWEEKS=3 \ + -e APIKEY= \ + --publish 8080:8080 \ + --name stock-ticker \ + stock-ticker +---- + +Now you can go to http://localhost:8080/stockprice in your browser to view a table of the latest weekly closing stock prices for Microsoft (MSFT). + +== Deploying the web service on Minikube + +The web service can be deployed on any distribution of Kubernetes but the below guide will focus on deployment onto a Minikube cluster. +The Kubernetes manifest can viewed https://codeflow.dananglin.me.uk/apollo/stock-ticker/src/branch/main/deploy/manifest.yaml[here] and you can download and modify it as you wish. + +1. Follow https://k8s-docs.netlify.app/en/docs/tasks/tools/install-minikube/[these instructions] to install and start a Minikube cluster. + +2. Set up ingress using either the https://minikube.sigs.k8s.io/docs/handbook/addons/ingress-dns/[Ingress DNS] or https://minikube.sigs.k8s.io/docs/handbook/addons/kong-ingress/[Kong Ingress] addon. + +3. Apply the Kubernetes manifest to your Minikube cluster. + + kubectl apply -f https://codeflow.dananglin.me.uk/apollo/stock-ticker/raw/branch/main/deploy/manifest.yaml + +4. Wait until the pods are running and in a 'Ready' state. + + $ kubectl -n stock-ticker get pods + NAME READY STATUS RESTARTS AGE + stock-ticker-656859cf74-bb8w6 1/1 Running 0 29s + stock-ticker-656859cf74-nvnbf 1/1 Running 0 29s + stock-ticker-656859cf74-p6xzk 1/1 Running 0 29s + +5. Go to http://stock-ticker./stockprice from your browser. diff --git a/README.md b/README.md deleted file mode 100644 index a03de47..0000000 --- a/README.md +++ /dev/null @@ -1,103 +0,0 @@ -# Stock Ticker - -## Overview - -``` -$ curl http://stock-ticker.test/stockprice - -Symbol: MSFT - -Week | Closing Price -========================== -2023-02-17 | 258.0600 -2023-02-10 | 263.1000 -2023-02-03 | 258.3500 -2023-01-27 | 248.1600 -2023-01-20 | 240.2200 -2023-01-13 | 239.2300 -2023-01-06 | 224.9300 - -``` -This is a simple web service that prints the last 'N' weeks of closing stock prices for a particular stock. -The data is retrieved from [Alpha Vantage's API](https://www.alphavantage.co/documentation/). - -The web service servers the following endpoints: - -- `/healthcheck` - Returns `200` if the server is up and running. -- `/stockprice` - Prints the closing prices for the latest N weeks. - -### Alpha Vantage API Key - -Before running the web service you'll need to obtain an API key from Alpha Vantage. -You can claim a free key from: - -https://www.alphavantage.co/support/#api-key - -### Required environment variables - -| Environment Variable | Description | Example | -|----------------------|------------------------------------------------|---------| -| SYMBOL | The stock's symbol. | MSFT | -| NWEEKS | Display the closing price for the last N weeks.| 7 | -| APIKEY | Your API key from Alpha Vantage. | | - -### Command line arguments - -| Argument | Description | Default | -|----------|-------------------------------------------------|--------------| -| address | The address that the web server will listen on. | 0.0.0.0:8080 | - -## Running the docker image locally - -The docker image is published to the container registry at Code Flow [here](https://codeflow.dananglin.me.uk/apollo/stock-ticker/packages). -You can pull and run the docker image from the registry with the following command: - -```bash -docker run --rm \ - -d \ - -e SYMBOL=MSFT \ - -e NWEEKS=3 \ - -e APIKEY= \ - --publish 8080:8080 \ - --name stock-ticker \ - codeflow.dananglin.me.uk/apollo/stock-ticker:v0.1.0 -``` - -Alternatively you can build and run the docker image locally. - -```bash -git clone https://codeflow.dananglin.me.uk/apollo/stock-ticker.git -cd stock-ticker -docker build -t stock-ticker -f deploy/Dockerfile . -docker run --rm \ - -d \ - -e SYMBOL=MSFT \ - -e NWEEKS=3 \ - -e APIKEY= \ - --publish 8080:8080 \ - --name stock-ticker \ - stock-ticker -``` - -Now you can go to http://localhost:8080/stockprice in your browser to view a table of the latest weekly closing stock prices for `MSFT`. - -## Deploying the web service on Minikube - -The web service can be deployed on any distribution of Kubernetes but the below guide will focus on deployment onto a Minikube cluster. -The Kubernetes manifest can viewed [here](https://gitlab.com/dananglin/stock-ticker/-/blob/main/kubernetes/manifest.yaml) and you can download and modify it as you wish. - -1. Follow [these instructions](https://k8s-docs.netlify.app/en/docs/tasks/tools/install-minikube/) to install and start a Minikube cluster. -2. Set up ingress using either the [Ingress DNS](https://minikube.sigs.k8s.io/docs/handbook/addons/ingress-dns/) or [Kong Ingress](https://minikube.sigs.k8s.io/docs/handbook/addons/kong-ingress/) addon. -3. Apply the Kubernetes manifest to your Minikube cluster. - ```bash - kubectl apply -f https://gitlab.com/dananglin/stock-ticker/-/raw/main/kubernetes/manifest.yaml - ``` -4. Wait until the pods are running and in a 'Ready' state. - ```bash - $ kubectl -n stock-ticker get pods - NAME READY STATUS RESTARTS AGE - stock-ticker-656859cf74-bb8w6 1/1 Running 0 29s - stock-ticker-656859cf74-nvnbf 1/1 Running 0 29s - stock-ticker-656859cf74-p6xzk 1/1 Running 0 29s - ``` -5. Go to http://stock-ticker./stockprice from your browser.