...
 
Commits (3)
build-development:
docker build -t registry.gitlab.com/shereland/graphql:development .
build-production:
docker build -t registry.gitlab.com/shereland/graphql:stable -f production.Dockerfile .
SCHEMA_LOCATION=schema.gql go run main/main.go
......@@ -16,11 +16,16 @@ import (
// GetLatestTweets Look for tweets at Redis DB
// If it doesn't exist, look at Twitter and persist at Redis DB
func GetLatestTweets() []string {
methodLog := logging.Log.WithFields(log.Fields{
"method": "GetLatestTweets",
})
var tweets []string
client := database.DBRedisCon
tweets = getFromRedis(client)
if tweets == nil {
tweets = getFromTwitter()
methodLog.Debug(tweets)
setToRedis(client, tweets)
}
return tweets
......@@ -34,6 +39,10 @@ func getFromRedis(client *redis.Client) []string {
tweetsArray := make([]string, 0, 2)
tweet1, err1 := client.Get("latest_tweet1").Result()
tweet2, err2 := client.Get("latest_tweet2").Result()
if err1 == redis.Nil || err2 == redis.Nil {
// Keys does not exist
return nil
}
if err1 != nil || err2 != nil {
methodLog.WithFields(log.Fields{
"err1": err1,
......@@ -58,6 +67,10 @@ func setToRedis(client *redis.Client, tweets []string) {
}
func getFromTwitter() []string {
methodLog := logging.Log.WithFields(log.Fields{
"method": "getFromTwitter",
})
api := anaconda.NewTwitterApiWithCredentials(os.Getenv("TWITTER_OAUTH_TOKEN"),
os.Getenv("TWITTER_OAUTH_SECRET"),
os.Getenv("TWITTER_CONSUMER_KEY"),
......@@ -65,7 +78,11 @@ func getFromTwitter() []string {
v := url.Values{}
v.Set("count", "2")
v.Set("screen_name", "_shereland")
tweets, _ := api.GetUserTimeline(v)
tweets, err := api.GetUserTimeline(v)
if err != nil {
methodLog.Error(err)
return nil
}
tweetsArray := make([]string, 0, 2)
for _, tweet := range tweets {
tweetsArray = append(tweetsArray, tweet.Text)
......
......@@ -9,9 +9,9 @@ ENV GOBIN=/go/bin
RUN go get -d -v ./...
RUN CGO_ENABLED=0 GOOS=linux go build -o graphql -a -ldflags '-extldflags "-static"' .
VOLUME [ "/var/log/graphql" ]
FROM scratch
COPY --from=0 /go/src/gitlab.com/shereland/graphql/main/graphql .
COPY --from=0 /go/src/gitlab.com/shereland/graphql/schema.gql .
COPY --from=0 /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
VOLUME [ "/var/log/graphql" ]
ENTRYPOINT ["/graphql"]