Skip to content

Commit

Permalink
add docker-compose
Browse files Browse the repository at this point in the history
  • Loading branch information
Dima committed Nov 3, 2023
1 parent 47a73e0 commit beec6e9
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 29 deletions.
24 changes: 0 additions & 24 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,3 @@ on:
branches:
- master

jobs:
deploy:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Install SSH key
run: |
mkdir -p ~/.ssh
echo "$SSH_PRIVATE_KEY" > ~/.ssh/id_rsa
chmod 600 ~/.ssh/id_rsa
ssh-keyscan -H "$SERVER_IP" >> ~/.ssh/known_hosts
env:
SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }}
SERVER_IP: ${{ secrets.SERVER_IP }}

- name: SSH into the server and update the code
run: |
ssh $SERVER_USERNAME@$SERVER_IP 'cd /root/ytstalker && git pull && export PATH=$PATH:/usr/local/go/bin && go build . && systemctl restart ytstalker.service'
env:
SERVER_USERNAME: ${{ secrets.SERVER_USERNAME }}
SERVER_IP: ${{ secrets.SERVER_IP }}
8 changes: 8 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
FROM golang:latest

WORKDIR /app

# pre-copy/cache go.mod for pre-downloading dependencies and only redownloading them in subsequent builds if they change
COPY . .
RUN go mod tidy && go build -v -o app
ENTRYPOINT app
5 changes: 1 addition & 4 deletions backend/api/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,7 @@ type Server struct {
ytr *youtube.YouTubeRequester
}

func NewServer() *Server {

// read config
config := conf.ParseConfig("conf.json")
func NewServer(config *conf.Config) *Server {

// init db
db, err := sqlitex.Open(config.DSN, 0, 100)
Expand Down
52 changes: 52 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
version: '3.9'

networks:
app:
driver: bridge

services:
app:
build: .
labels:
- traefik.enable=true
- traefik.http.routers.app.rule=Host(`ytstalker.fun`)
- traefik.http.routers.app.entrypoints=websecure
- traefik.http.routers.app.tls.certresolver=letsencrypt
volumes:
- ./conf.json:/app/conf.json:ro
networks:
- app

traefik:
image: docker.io/traefik
restart: always
command:
- --log.level=DEBUG
- --providers.docker=true
- --providers.docker.exposedbydefault=false
- --global.sendAnonymousUsage=false

# entrypoints
- --entrypoints.web.address=:80
- --entrypoints.websecure.address=:443

# redirect http to https
- --entrypoints.web.http.redirections.entrypoint.to=websecure
- --entrypoints.web.http.redirections.entrypoint.scheme=https

# let's encrypt resolver
- --certificatesresolvers.letsencrypt.acme.tlschallenge=true
- --certificatesresolvers.letsencrypt.acme.email=thedmdim@gmail.com
- --certificatesresolvers.letsencrypt.acme.storage=/letsencrypt/acme.json
ports:
- 80:80
- 443:443
labels:
traefik.enable: "true"
volumes:
- ./letsencrypt:/letsencrypt:rw
- /run/docker.sock:/var/run/docker.sock:ro
networks:
- app


10 changes: 9 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,22 @@ import (
"time"

"ytstalker/backend/api"
"ytstalker/backend/conf"
)

func main() {

// read config
confPath := os.Getenv("CONF_PATH")
if confPath == "" {
confPath = "conf.json"
}
config := conf.ParseConfig(confPath)

stop := make(chan os.Signal, 1)
signal.Notify(stop, os.Interrupt)

server := api.NewServer()
server := api.NewServer(config)

go server.ListenAndServe()
log.Println("server started!")
Expand Down

0 comments on commit beec6e9

Please sign in to comment.