Skip to content

Commit

Permalink
adding Dockerfiles and compose for local dev
Browse files Browse the repository at this point in the history
  • Loading branch information
lornest committed Sep 6, 2023
1 parent 722f29f commit 6549264
Show file tree
Hide file tree
Showing 7 changed files with 145 additions and 3 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,4 @@ thumb
sketch

.terraform
tmp
28 changes: 28 additions & 0 deletions client/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
### STAGE 1: Setup the environment & install dependencies ###
FROM node:16.18-buster-slim AS setup

WORKDIR /app

COPY package*.json ./

RUN npm install
COPY . .

### STAGE 2: Run the app in development mode ###
FROM setup AS development
CMD ["npm", "run", "dev"]

### STAGE 3: Build the app for production ###
FROM setup AS build
RUN npm run build

### STAGE 4: Serve the production app with a busybox web server ###
FROM busybox:latest

RUN adduser -D public
USER public
WORKDIR /public

COPY --from=build /app/dist /public

CMD ["busybox", "httpd", "-f", "-v", "-p", "3000"]
7 changes: 5 additions & 2 deletions client/vite.config.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react-swc'

// https://vitejs.dev/config/
export default defineConfig({
plugins: [react()],
plugins: [react()],
server: {
host: true,
port: 3000,
}
})
30 changes: 30 additions & 0 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
version: '3.8'
name: digits
services:
fake-gcs:
image: fsouza/fake-gcs-server
ports:
- "4443:4443"

server:
build:
context: ./server
dockerfile: Dockerfile.local
ports:
- "3001:3001"
expose:
- "3001"
volumes:
- ./server:/app

frontend:
build:
context: ./client
target: development
ports:
- "3000:3000"
expose:
- "3000"
volumes:
- ./client/src:/app/src

69 changes: 69 additions & 0 deletions server/.air.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
# Config file for [Air](https://github.com/cosmtrek/air) in TOML format
## ONLY USING THIS FOR LIVE RELOADING DURING LOCAL DEV

# Working directory
root = "api"
tmp_dir = "tmp"

[build]
# Just plain old shell command. You could use `make` as well.
cmd = "go build -o ./tmp/main ./api"
# Binary file yields from `cmd`.
bin = "tmp/main"
# Customize binary, can setup environment variables when run your app.
full_bin = "APP_ENV=dev APP_USER=air ./tmp/main"
# Watch these filename extensions.
include_ext = ["go", "tpl", "tmpl", "html"]
# Ignore these filename extensions or directories.
exclude_dir = ["assets", "tmp", "vendor", "frontend/node_modules"]
# Watch these directories if you specified.
include_dir = []
# Watch these files.
include_file = []
# Exclude files.
exclude_file = []
# Exclude specific regular expressions.
exclude_regex = ["_test\\.go"]
# Exclude unchanged files.
exclude_unchanged = true
# Follow symlink for directories
follow_symlink = true
# This log file places in your tmp_dir.
log = "air.log"
# Poll files for changes instead of using fsnotify.
poll = false
# Poll interval (defaults to the minimum interval of 500ms).
poll_interval = 500 # ms
# It's not necessary to trigger build each time file changes if it's too frequent.
delay = 0 # ms
# Stop running old binary when build errors occur.
stop_on_error = true
# Send Interrupt signal before killing process (windows does not support this feature)
send_interrupt = false
# Delay after sending Interrupt signal
kill_delay = 500 # ms
# Rerun binary or not
rerun = false
# Delay after each executions
rerun_delay = 500

[log]
# Show log time
time = false
# Only show main log (silences watcher, build, runner)
main_only = false

[color]
# Customize each part's color. If no color found, use the raw app log.
main = "magenta"
watcher = "cyan"
build = "yellow"
runner = "green"

[misc]
# Delete tmp directory on exit
clean_on_exit = true

[screen]
clear_on_rebuild = true
keep_scroll = true
11 changes: 11 additions & 0 deletions server/Dockerfile.local
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
FROM golang:1.19-alpine

WORKDIR /app

RUN go install github.com/cosmtrek/air@latest

COPY go.mod go.sum .air.toml ./
RUN go mod download

# Run using air for live reloading
CMD ["air", "-c", ".air.toml"]
2 changes: 1 addition & 1 deletion server/api/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"github.com/go-chi/chi/v5"
)

const port = "3000"
const port = "3001"

func main() {
srv := &http.Server{
Expand Down

0 comments on commit 6549264

Please sign in to comment.