Skip to content

Commit

Permalink
Merge pull request #18 from Vaansh/improvements
Browse files Browse the repository at this point in the history
refactor: gofmt -s and rearrange imports
  • Loading branch information
Vaansh authored Jul 21, 2023
2 parents 369b830 + 204a219 commit 5f63c7b
Show file tree
Hide file tree
Showing 19 changed files with 61 additions and 53 deletions.
43 changes: 19 additions & 24 deletions .github/workflows/cicd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,26 @@ on:
branches:
- main

# Environment variables local to this file
env:
PROJECT_ID: ${{ secrets.PROJECT_ID }}
IMAGE_NAME: gore

jobs:
# Build and push Docker image job
build_and_push:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v2

# In order for the docker image we build to have the .env variables and credentials
# Create .env file for the Docker image
- name: Make envfile
uses: SpicyPizza/create-envfile@v2.0
with:
file_name: .env
envkey_PROJECT_ID: ${{ secrets.PROJECT_ID }}
envkey_INSTANCE_CONNECTION_NAME: ${{ secrets.INSTANCE_CONNECTION_NAME }}
envkey_PROJECT_ID: ${{ secrets.PROJECT_ID }}
envkey_DB_USER: ${{ secrets.DB_USER }}
envkey_DB_NAME: ${{ secrets.DB_NAME }}
envkey_DB_PASS: ${{ secrets.DB_PASS }}
Expand All @@ -35,41 +37,34 @@ jobs:
envkey_ACCESS_TOKEN: ${{ secrets.ACCESS_TOKEN }}
envkey_API_AUTH_TOKEN: ${{ secrets.API_AUTH_TOKEN }}

# Create credentials JSON file
- name: Create credentials json file
uses: jsdaniell/create-json@v1.2.2
with:
name: ${{ secrets.GOOGLE_APPLICATION_CREDENTIALS }}
json: ${{ secrets.GOOGLE_APPLICATION_CREDENTIALS_JSON }}

- name: Build Docker image
run: docker build -t gore .

# Push Docker image to Docker Hub (it is a private image, hosted there for my own reference)
- name: Tag Docker image for Docker Hub
run: docker tag gore ${{ secrets.DOCKER_USERNAME }}/gore:latest

- name: Push Docker image to Docker Hub
run: docker login -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_PASSWORD }} && docker push ${{ secrets.DOCKER_USERNAME }}/gore:latest

# Push Docker image to DigitalOcean Container Registry
- name: Install doctl
uses: digitalocean/action-doctl@v2
with:
token: ${{ secrets.DOCR_TOKEN }}

- name: Log in to DigitalOcean Container Registry
run: doctl registry login --expiry-seconds 600

- name: Tag Docker image for DigitalOcean Container Registry
run: docker tag gore:latest registry.digitalocean.com/gore/gore:latest
# Build the Docker image and push to Docker Hub
- name: Build and Push Docker image to Docker Hub
run: |
docker build -t gore .
docker tag gore ${{ secrets.DOCKER_USERNAME }}/gore:latest
docker login -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_PASSWORD }}
docker push ${{ secrets.DOCKER_USERNAME }}/gore:latest
# Authenticate and push the Docker image to DigitalOcean Container Registry
- name: Push Docker image to DigitalOcean Container Registry
run: docker push registry.digitalocean.com/gore/gore:latest
run: |
doctl registry login --expiry-seconds 600
docker tag gore:latest registry.digitalocean.com/gore/gore:latest
docker push registry.digitalocean.com/gore/gore:latest
# Deploy job
deploy:
runs-on: ubuntu-latest
needs: build_and_push
steps:
# SSH into instance, remove current instance, and start the newest image after pulling it from the registry
- name: Deploy to Digital Ocean droplet via SSH action
uses: appleboy/ssh-action@v0.1.10
with:
Expand Down
5 changes: 1 addition & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@
<a href="https://github.com/Vaansh/gore/blob/main/LICENSE">
<img src="https://img.shields.io/github/license/gatsbyjs/gatsby.svg?style=for-the-badge">
</a>
<a href="https://linkedin.com/in/Vaansh">
<img src="https://img.shields.io/badge/-LinkedIn-black.svg?style=for-the-badge&logo=linkedin&colorB=555">
</a>
</p>

<!-- PROJECT LOGO -->
Expand Down Expand Up @@ -213,7 +210,7 @@ Another one for building and pushing the docker image to the registry, acting as
I tried Google Cloud Run, Kubernetes, & Compute Engine but nothing really suited what I was looking for. I decided to go with another platform and created a Droplet (VM) on DigitalOcean. I really liked my experience with DigitalOcean so far, it gave me a streamlined developer solution I was looking for.

<p align="center">
<img src="https://i.imgur.com/XIireVV.jpg">
<img src="https://i.imgur.com/zGEWBkS.jpeg">
</p>

<!-- Miscellaneous -->
Expand Down
4 changes: 2 additions & 2 deletions cmd/api/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@ package main

import (
"fmt"
"log"

"github.com/Vaansh/gore/internal/api"
"github.com/Vaansh/gore/internal/domain"
"github.com/Vaansh/gore/internal/gcloud"
"github.com/Vaansh/gore/internal/util"
"github.com/gin-gonic/gin"
"github.com/joho/godotenv"
"log"
)

func main() {
Expand Down Expand Up @@ -52,4 +53,3 @@ func main() {
gcloud.LogFatal(err.Error())
}
}

3 changes: 2 additions & 1 deletion internal/api/handler.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package api

import (
"net/http"

"github.com/Vaansh/gore"
"github.com/Vaansh/gore/internal/domain"
"github.com/Vaansh/gore/internal/model"
"github.com/gin-gonic/gin"
"net/http"
)

type TaskHandler struct {
Expand Down
3 changes: 2 additions & 1 deletion internal/api/middleware.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package api

import (
"net/http"

"github.com/Vaansh/gore/internal/util"
"github.com/gin-gonic/gin"
"net/http"
)

func AuthMiddleware(c *gin.Context) {
Expand Down
3 changes: 2 additions & 1 deletion internal/api/request.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package api

import (
gore "github.com/Vaansh/gore"
"time"

"github.com/Vaansh/gore"
)

// Api task request dtos live here
Expand Down
3 changes: 2 additions & 1 deletion internal/config/logger.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package config

import (
"github.com/Vaansh/gore/internal/util"
"strings"

"github.com/Vaansh/gore/internal/util"
)

type LoggerConfig struct {
Expand Down
3 changes: 2 additions & 1 deletion internal/domain/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ package domain
import (
"database/sql"
"fmt"
"sync"

"github.com/Vaansh/gore"
"github.com/Vaansh/gore/internal/gcloud"
"github.com/Vaansh/gore/internal/model"
"github.com/Vaansh/gore/internal/repository"
"sync"
)

// Task service is a singleton
Expand Down
7 changes: 4 additions & 3 deletions internal/domain/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@ package domain

import (
"fmt"
"reflect"
"strings"
"sync"

"github.com/Vaansh/gore"
"github.com/Vaansh/gore/internal/gcloud"
"github.com/Vaansh/gore/internal/model"
"github.com/Vaansh/gore/internal/publisher"
"github.com/Vaansh/gore/internal/repository"
"github.com/Vaansh/gore/internal/subscriber"
"reflect"
"strings"
"sync"
)

type Task struct {
Expand Down
5 changes: 3 additions & 2 deletions internal/gcloud/database.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
package gcloud

import (
"cloud.google.com/go/cloudsqlconn"
"context"
"database/sql"
"fmt"
"net"

"cloud.google.com/go/cloudsqlconn"
"github.com/Vaansh/gore/internal/config"
"github.com/jackc/pgx/v4"
"github.com/jackc/pgx/v4/stdlib"
"net"
)

// Initialize db
Expand Down
7 changes: 4 additions & 3 deletions internal/gcloud/logger.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
package gcloud

import (
"cloud.google.com/go/logging"
"context"
"fmt"
"github.com/Vaansh/gore/internal/config"
"google.golang.org/api/option"
"log"
"os"
"time"

"cloud.google.com/go/logging"
"github.com/Vaansh/gore/internal/config"
"google.golang.org/api/option"
)

const (
Expand Down
9 changes: 5 additions & 4 deletions internal/gcloud/storage.go
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
package gcloud

import (
"cloud.google.com/go/storage"
"context"
"fmt"
"io"
"os"
"time"

"cloud.google.com/go/storage"
"github.com/Vaansh/gore"
"github.com/Vaansh/gore/internal/config"
"github.com/kkdai/youtube/v2"
"google.golang.org/api/option"
"io"
"os"
"time"
)

var (
Expand Down
3 changes: 2 additions & 1 deletion internal/http/instagram.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ package http

import (
"fmt"
fb "github.com/huandu/facebook/v2"
"time"

fb "github.com/huandu/facebook/v2"
)

type InstagramClient struct {
Expand Down
5 changes: 3 additions & 2 deletions internal/http/youtube.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ import (
"encoding/json"
"errors"
"fmt"
"github.com/Vaansh/gore"
"github.com/Vaansh/gore/internal/model"
"net/http"
"net/url"

"github.com/Vaansh/gore"
"github.com/Vaansh/gore/internal/model"
)

type YoutubeClient struct {
Expand Down
1 change: 1 addition & 0 deletions internal/model/post.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package model

import (
"fmt"

"github.com/Vaansh/gore"
)

Expand Down
2 changes: 1 addition & 1 deletion internal/publisher/youtube.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func (p *YoutubePublisher) PublishTo(c chan<- model.Post, quit <-chan struct{})
}
}

if len(videosBuffer) == 50 {
if len(videosBuffer) == 100 {
videosBuffer = make([]string, 0)
}
}
Expand Down
1 change: 1 addition & 0 deletions internal/repository/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package repository
import (
"database/sql"
"fmt"

"github.com/Vaansh/gore"
"github.com/Vaansh/gore/internal/model"
)
Expand Down
5 changes: 3 additions & 2 deletions internal/subscriber/instagram.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@ package subscriber

import (
"fmt"
"strings"
"time"

"github.com/Vaansh/gore"
"github.com/Vaansh/gore/internal/gcloud"
"github.com/Vaansh/gore/internal/http"
"github.com/Vaansh/gore/internal/model"
"github.com/Vaansh/gore/internal/repository"
"github.com/Vaansh/gore/internal/util"
"strings"
"time"
)

type InstagramSubscriber struct {
Expand Down
2 changes: 2 additions & 0 deletions scripts/clean.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@
if [[ "$OSTYPE" == "linux-gnu" || "$OSTYPE" == "darwin"* ]]; then
rm ./data/*.mp4
rm ./log/*-*.log
rm main
elif [[ "$OSTYPE" == "msys" || "$OSTYPE" == "cygwin" || "$OSTYPE" == "win32" ]]; then
del .\data\*.mp4
del .\log\*.log
del main
else
echo "Unknown operating system"
fi

0 comments on commit 5f63c7b

Please sign in to comment.