Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Janus#463 cassandra repo #466

Merged
merged 17 commits into from
Mar 18, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
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
48 changes: 48 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
jobs:
build_test:
#docker:
# - image: docker/compose:1.25.3

machine:
image: ubuntu-1604:201903-01

steps:
- checkout

# - run:
# name: Running Unit Tests
# command: |
# echo "Running unit tests and building binary"
# go mod download
# make all
- run:
name: Build and Push Images
command: |
echo "Logging in to Docker Hub"
docker login --username ${DOCKERHUB_USERNAME} --password ${DOCKERHUB_PASSWORD}

echo "Setting Image Name"
IMAGE_NAME="motivlabs/janus:$(date +%Y%m%d%H%M%S)-${CIRCLE_SHA1:0:6}"
echo "Image Name"
echo $IMAGE_NAME

echo "Building Service Image"
docker build -f ./Dockerfile --target=prod -t ${IMAGE_NAME} -t motivlabs/janus:latest .
echo "Finished Building Service Image"

echo "Pushing Service Images to Docker Hub"
docker push $IMAGE_NAME
echo "Pushed Extended Image Name"
docker push motivlabs/janus:latest
echo "Pushed Latest Image Name"

workflows:
version: 2
build:
jobs:
- build_test:
context: MotivLabs
filters:
branches:
only:
- master
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@
*.o
*.a
*.so
main

# Folders
_obj
_test
.idea

# Architecture specific extensions/prefixes
*.[568vq]
Expand Down
16 changes: 14 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,18 @@
FROM ubuntu:20.04
####### Start from a golang base image ###############
FROM golang:1.13.6-buster as builder
LABEL maintainer="Motiv Labs <[email protected]>"
WORKDIR /app
COPY ./ ./

ADD janus /bin/janus
RUN go mod download

RUN make build

FROM ubuntu:20.04 as prod

COPY --from=builder /app/cassandra/schema.sql /usr/local/bin

COPY --from=builder /app/dist/janus /bin/janus
RUN chmod a+x /bin/janus && \
mkdir -p /etc/janus/apis && \
mkdir -p /etc/janus/auth
Expand Down
45 changes: 45 additions & 0 deletions Dockerfile.dev
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# run this from the root of janus
FROM golang:1.14-alpine AS build-debug-common

ARG VERSION='0.0.1-docker'

WORKDIR /janus

COPY . ./

# Add tooling to install GCC
RUN apk add build-base
# Add cqlsh to the image.
RUN apk add --update \
bash \
curl \
py-pip
RUN go get github.com/go-delve/delve/cmd/dlv

RUN apk add --update bash make git
RUN export JANUS_BUILD_ONLY_DEFAULT=1 && \
export VERSION=$VERSION && \
make build

# ---

FROM alpine

COPY --from=build-debug-common /janus/dist/janus /

RUN apk add --no-cache ca-certificates
RUN mkdir -p /etc/janus/apis && \
mkdir -p /etc/janus/auth

RUN apk add --update curl && \
rm -rf /var/cache/apk/*

HEALTHCHECK --interval=5s --timeout=5s --retries=3 CMD curl -f http://localhost:8081/status || exit 1

FROM build-debug-common as dev
EXPOSE 8080 8081 8443 8444 40000
COPY entry-dev.sh /usr/local/bin
COPY cassandra/schema.sql /usr/local/bin
RUN chmod 755 /usr/local/bin/entry-dev.sh
ENTRYPOINT ["/usr/local/bin/entry-dev.sh"]
#ENTRYPOINT ["/janus", "start"]
17 changes: 17 additions & 0 deletions cassandra/schema.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
CREATE KEYSPACE IF NOT EXISTS janus with replication = {'class': 'SimpleStrategy', 'replication_factor': 1};
USE janus;

CREATE TABLE IF NOT EXISTS janus.user (
username text,
password text,
PRIMARY KEY (username));

CREATE TABLE IF NOT EXISTS janus.api_definition (
name text,
definition text,
PRIMARY KEY (name));

CREATE TABLE IF NOT EXISTS janus.oauth (
name text,
oauth text,
PRIMARY KEY (name));
26 changes: 26 additions & 0 deletions cassandra/session.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package cassandra

import (
"github.com/hellofresh/janus/cassandra/wrapper"
)
const (
// Cassandra cluster host
ClusterHostName = "db"
// System keyspace
SystemKeyspace = "system"
// Github taxi dispatcher keyspace
AppKeyspace = "janus"
// default timeout
Timeout = 300
)

// SessionHolder holds our connection to Cassandra
var sessionHolder wrapper.Holder

func GetSession() wrapper.SessionInterface {
return sessionHolder.GetSession()
}

func SetSessionHolder(holder wrapper.Holder) {
sessionHolder = holder
}
Loading