Skip to content

Commit 438b780

Browse files
committed
Testing docker
1 parent 13749f2 commit 438b780

File tree

6 files changed

+141
-6
lines changed

6 files changed

+141
-6
lines changed

.dockerignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
.env
2+
node_modules/
3+
.git
4+
.gitignore

.github/workflows/production2.yaml

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
name: Build and Deploy Docker Image
2+
3+
on:
4+
push:
5+
branches:
6+
- docker
7+
8+
jobs:
9+
build:
10+
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: actions/checkout@v3
14+
15+
- name: Setup Node and NPM
16+
uses: actions/setup-node@v3
17+
with:
18+
node-version: 18.14.0
19+
20+
- name: Install NPM Packages
21+
run: npm ci
22+
23+
- name: Compile UI
24+
run: npm run build:css && npm run build:brixi && npm run build:bundle && npm run build:js
25+
26+
- name: Build Docker image
27+
run: docker build -t codewithkyle/divinedrop:prod .
28+
29+
- name: Save Docker image as tarball
30+
run: docker save -o divinedrop.tar codewithkyle/divinedrop:prod
31+
32+
- name: Load SSH Key
33+
uses: webfactory/[email protected]
34+
with:
35+
ssh-private-key: ${{ secrets.SSH_KEY }}
36+
37+
- name: Deploy
38+
run: scp ./divinedrop.tar ./compose.prod.yaml ${{ secrets.USERNAME }}@${{ secrets.HOST }}:~/docker
39+
40+
- name: Post Deployment
41+
uses: appleboy/ssh-action@master
42+
with:
43+
host: ${{ secrets.HOST }}
44+
USERNAME: ${{ secrets.USERNAME }}
45+
PORT: 22
46+
KEY: ${{ secrets.SSH_KEY }}
47+
script: docker load -i ~/divinedrop.tar

Dockerfile

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Step 1: Use an official Go image to build the Go application
2+
FROM golang:1.22-alpine AS builder
3+
4+
# Step 2: Set the working directory inside the container
5+
WORKDIR /server
6+
7+
# Step 3: Copy the Go modules and dependencies
8+
COPY go.mod go.sum ./
9+
10+
# Step 4: Download necessary Go dependencies
11+
RUN go mod download
12+
13+
# Step 5: Copy the entire Go project into the working directory
14+
COPY . .
15+
16+
# Step 6: Build the Go application
17+
RUN go build -ldflags="-s -w" -o divinedrop .
18+
19+
# Step 7: Create a small image to run the application
20+
FROM alpine:latest
21+
22+
# Step 8: Set the working directory in the final image
23+
WORKDIR /root/
24+
25+
# Step 9: Copy the Go binary from the builder stage
26+
COPY --from=builder /server/divinedrop .
27+
28+
COPY . .
29+
30+
# Step 10: Expose the port that the app will run on
31+
EXPOSE 3000
32+
33+
# Step 11: Command to run the Go app
34+
CMD ["./divinedrop"]
35+

compose.prod.yaml

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
services:
2+
watchtower:
3+
image: containrrr/watchtower
4+
command:
5+
- "--label-enable"
6+
- "--interval"
7+
- "30"
8+
- "--rolling-restart"
9+
volumes:
10+
- /var/run/docker.sock:/var/run/docker.sock
11+
reverse-proxy:
12+
image: traefik:v3.1
13+
command:
14+
- "--providers.docker"
15+
- "--providers.docker.exposedbydefault=false"
16+
- "--entryPoints.websecure.address=:443"
17+
- "--certificatesresolvers.myresolver.acme.tlschallenge=true"
18+
- "--certificatesresolvers.myresolver.acme.email=codingwithkyle@gmail.com"
19+
- "--certificatesresolvers.myresolver.acme.storage=/letsencrypt/acme.json"
20+
- "--entrypoints.web.address=:80"
21+
- "--entrypoints.web.http.redirections.entrypoint.to=websecure"
22+
- "--entrypoints.web.http.redirections.entrypoint.scheme=https"
23+
ports:
24+
- "80:80"
25+
- "443:443"
26+
volumes:
27+
- /var/run/docker.sock:/var/run/docker.sock
28+
- letsencrypt:/letsencrypt
29+
server:
30+
image: codewithkyle/divinedrop:prod
31+
network_mode: "host"
32+
labels:
33+
- "traefik.enable=true"
34+
- "traefik.http.routers.divinedrop.rule=Host(`divinedrop.app`)"
35+
- "traefik.http.routers.divinedrop.entrypoints=websecure"
36+
- "traefik.http.routers.divinedrop.tls.certresolver=myresolver"
37+
- "com.centurylinklabs.watchtower.enable=true"
38+
volumes:
39+
- .:/app
40+
env_file: ".env"
41+
deploy:
42+
mode: replicated
43+
replicas: 3
44+
restart: always
45+
volumes:
46+
letsencrypt:

compose.yaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
services:
2+
server:
3+
build: .
4+
network_mode: "host"
5+
ports:
6+
- "3000:3000"
7+
volumes:
8+
- .:/app
9+
env_file: ".env"

server.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import (
44
"app/controllers"
55
"app/helpers"
66
"app/models"
7-
"log"
87
"os"
98
"strings"
109
"time"
@@ -13,14 +12,9 @@ import (
1312
"github.com/gofiber/fiber/v2"
1413
"github.com/gofiber/template/html/v2"
1514
"github.com/google/uuid"
16-
"github.com/joho/godotenv"
1715
)
1816

1917
func main() {
20-
if err := godotenv.Load(); err != nil {
21-
log.Fatalf("failed to load environment variables: %v", err)
22-
}
23-
2418
client, _ := clerk.NewClient(os.Getenv("CLERK_API_KEY"))
2519

2620
engine := html.New("./views", ".html")

0 commit comments

Comments
 (0)