Skip to content

Commit

Permalink
Merge pull request #48 from Financial-Times/feature/atlas-migration
Browse files Browse the repository at this point in the history
Migration to Atlas (#47)
  • Loading branch information
martin-stanchev committed Sep 11, 2023
2 parents fccd694 + 43eab73 commit 5ccc12a
Show file tree
Hide file tree
Showing 9 changed files with 30 additions and 34 deletions.
5 changes: 0 additions & 5 deletions Dockerfile
Expand Up @@ -20,16 +20,11 @@ RUN VERSION="version=$(git describe --tag --always 2> /dev/null)" \
&& CGO_ENABLED=0 go build -a -o /artifacts/${PROJECT} -ldflags="${LDFLAGS}" \
&& echo "Build flags: ${LDFLAGS}"

RUN mkdir -p /tmp/amazonaws
WORKDIR /tmp/amazonaws
RUN apt-get update && apt-get install -y wget && wget https://s3.amazonaws.com/rds-downloads/rds-combined-ca-bundle.pem

# Multi-stage build - copy certs and the binary into the image
FROM scratch
WORKDIR /
COPY ./api/api.yml /
COPY --from=0 /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
COPY --from=0 /artifacts/* /
COPY --from=0 /tmp/amazonaws/* /

CMD [ "/list-notifications-rw" ]
4 changes: 2 additions & 2 deletions README.md
Expand Up @@ -24,7 +24,7 @@ go test -v -race ./...

## Running Locally

The `list-notifications-rw` requires access to DocumentDB. Update the environment variable `DOCDB_CLUSTER_ADDRESSES` field to point to the DocumentDB cluster. To run, simply build and run:
The `list-notifications-rw` requires access to Atlas MongoDB. Update the environment variable `DB_CLUSTER_ADDRESS` field to point to the Atlas MongoDB cluster. To run, simply build and run:

```
./list-notifications-rw
Expand All @@ -42,7 +42,7 @@ Write a new list notification:
curl http://localhost:8080/lists/notifications/{uuid} -XPUT --data '$json'
```

Where `$json` is a valid internal list in json format. To get example list data, see [sample-list.json](/sample-list.json) or get an example from the DocumentDB `lists` collection.
Where `$json` is a valid internal list in json format. To get example list data, see [sample-list.json](/sample-list.json) or get an example from the Atlas MongoDB `lists` collection.

Read notifications:

Expand Down
5 changes: 3 additions & 2 deletions db/client.go
Expand Up @@ -6,7 +6,7 @@ import (

"github.com/Financial-Times/go-logger/v2"
"github.com/Financial-Times/list-notifications-rw/model"
"github.com/Financial-Times/upp-go-sdk/pkg/documentdb"
"github.com/Financial-Times/upp-go-sdk/pkg/mongodb"
"go.mongodb.org/mongo-driver/bson"
"go.mongodb.org/mongo-driver/mongo"
"go.mongodb.org/mongo-driver/mongo/options"
Expand All @@ -26,10 +26,11 @@ func NewClient(address, username, password, database, collection string, cacheDe
ctx, cancel := context.WithTimeout(context.Background(), time.Second*15)
defer cancel()

client, err := documentdb.NewClient(ctx, documentdb.ConnectionParams{
client, err := mongodb.NewClient(ctx, mongodb.ConnectionParams{
Host: address,
Username: username,
Password: password,
UseSrv: true,
})
if err != nil {
return nil, err
Expand Down
4 changes: 2 additions & 2 deletions go.mod
@@ -1,14 +1,14 @@
module github.com/Financial-Times/list-notifications-rw

go 1.19
go 1.21

require (
github.com/Financial-Times/api-endpoint v1.0.0
github.com/Financial-Times/go-fthealth v0.6.2
github.com/Financial-Times/go-logger/v2 v2.0.1
github.com/Financial-Times/http-handlers-go v1.0.0
github.com/Financial-Times/service-status-go v0.3.0
github.com/Financial-Times/upp-go-sdk v1.3.4
github.com/Financial-Times/upp-go-sdk v1.4.1
github.com/gorilla/mux v1.8.0
github.com/jawher/mow.cli v1.2.0
github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Expand Up @@ -13,8 +13,8 @@ github.com/Financial-Times/service-status-go v0.3.0/go.mod h1:LNNWeeKgUn5qnMsa4L
github.com/Financial-Times/transactionid-utils-go v0.2.0/go.mod h1:tPAcAFs/dR6Q7hBDGNyUyixHRvg/n9NW/JTq8C58oZ0=
github.com/Financial-Times/transactionid-utils-go v1.0.0 h1:X7D+ouW1KyRcZo+jLDjXKfM1RY1U4/5BvHPw57DbZEQ=
github.com/Financial-Times/transactionid-utils-go v1.0.0/go.mod h1:Aeqj+Ye4pLO9ostLZAxEUK4AbkXCrW1DeuMhxnNxPXw=
github.com/Financial-Times/upp-go-sdk v1.3.4 h1:uHTjGISVFbHpcNp2bG6lpi/Z8PdbCpCpUNqVXCYFTcE=
github.com/Financial-Times/upp-go-sdk v1.3.4/go.mod h1:HjOzTS96WvTaxqMSstgI9RfAO6ccdj+JcE3b63g25ms=
github.com/Financial-Times/upp-go-sdk v1.4.1 h1:mgMekWguxaZtEg59qM/veEfmrcbPravH6rTq6jS+Ffs=
github.com/Financial-Times/upp-go-sdk v1.4.1/go.mod h1:HjOzTS96WvTaxqMSstgI9RfAO6ccdj+JcE3b63g25ms=
github.com/davecgh/go-spew v0.0.0-20170829195320-a47672248388/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1-0.20170711183451-adab96458c51/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
Expand Down
20 changes: 10 additions & 10 deletions helm/list-notifications-rw/templates/deployment.yaml
Expand Up @@ -49,25 +49,25 @@ spec:
value: "{{ .Values.env.NOTIFICATIONS_LIMIT }}"
- name: LOG_LEVEL
value: "{{ .Values.env.LOG_LEVEL }}"
- name: DOCDB_CLUSTER_ADDRESS
- name: DB_CLUSTER_ADDRESS
valueFrom:
configMapKeyRef:
name: global-config
key: aws.documentdb.cluster.address
- name: DOCDB_NAME
value: "{{ .Values.env.DOCDB_NAME }}"
- name: DOCDB_COLLECTION
value: "{{ .Values.env.DOCDB_COLLECTION }}"
- name: DOCDB_USERNAME
key: documentstore.cluster.address
- name: DB_NAME
value: "{{ .Values.env.DB_NAME }}"
- name: DB_COLLECTION
value: "{{ .Values.env.DB_COLLECTION }}"
- name: DB_USERNAME
valueFrom:
secretKeyRef:
name: doppler-global-secrets
key: AWS_DOC_DB_USERNAME
- name: DOCDB_PASSWORD
key: DOCUMENT_STORE_CLUSTER_USERNAME
- name: DB_PASSWORD
valueFrom:
secretKeyRef:
name: doppler-global-secrets
key: AWS_DOC_DB_PASSWORD
key: DOCUMENT_STORE_CLUSTER_PASSWORD
ports:
- containerPort: 8080
livenessProbe:
Expand Down
4 changes: 2 additions & 2 deletions helm/list-notifications-rw/values.yaml
Expand Up @@ -16,6 +16,6 @@ resources:
env:
DUMP_REQUESTS: false
LOG_LEVEL: INFO
DOCDB_NAME: upp-store
DOCDB_COLLECTION: list-notifications
DB_NAME: upp-store
DB_COLLECTION: list-notifications
NOTIFICATIONS_LIMIT: 200
16 changes: 8 additions & 8 deletions main.go
Expand Up @@ -96,37 +96,37 @@ func main() {

dbClusterAddress := app.String(cli.StringOpt{
Name: "dbClusterAddress",
Desc: "DocumentDB cluster connection string",
Desc: "Database cluster connection string",
Value: "",
EnvVar: "DOCDB_CLUSTER_ADDRESS",
EnvVar: "DB_CLUSTER_ADDRESS",
})

dbName := app.String(cli.StringOpt{
Name: "dbName",
Value: "upp-store",
Desc: "Name of the database to read from",
EnvVar: "DOCDB_NAME",
EnvVar: "DB_NAME",
})

dbCollection := app.String(cli.StringOpt{
Name: "dbCollection",
Value: "list-notifications",
Desc: "Name of the collection to read from",
EnvVar: "DOCDB_COLLECTION",
EnvVar: "DB_COLLECTION",
})

dbUsername := app.String(cli.StringOpt{
Name: "dbUsername",
Value: "",
Desc: "Username to connect to DocumentDB",
EnvVar: "DOCDB_USERNAME",
Desc: "Username to connect to Atlas MongoDB",
EnvVar: "DB_USERNAME",
})

dbPassword := app.String(cli.StringOpt{
Name: "dbPassword",
Value: "",
Desc: "Password to use to connect to DocumentDB",
EnvVar: "DOCDB_PASSWORD",
Desc: "Password to use to connect to Atlas MongoDB",
EnvVar: "DB_PASSWORD",
})

log := logger.NewUPPLogger(*appName, *logLevel)
Expand Down
2 changes: 1 addition & 1 deletion runbooks/runbook.md
Expand Up @@ -4,7 +4,7 @@
-->
# UPP - List Notifications RW

This service is responsible for writing/reading change events for every list publish to/from a DocumentDB document store. This API is used to discover list updates.
This service is responsible for writing/reading change events for every list publish to/from a Atlas MongoDB. This API is used to discover list updates.

## Code

Expand Down

0 comments on commit 5ccc12a

Please sign in to comment.