summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSaumit Dinesan <justsaumit@protonmail.com>2023-12-26 01:04:24 +0530
committerSaumit Dinesan <justsaumit@protonmail.com>2023-12-26 01:04:24 +0530
commit75a1922a02f9488f605b8c49994b28b8e764d6be (patch)
tree08d45a03a74f06961b0e7ee48de620e126126c37
parent704d51df9a371f39c3137fcf7dcfc164b3150983 (diff)
Dockerfile & README.md: Optimizing Docker Image Size, adding persistant db using docker volume flag along w .env
-rw-r--r--Dockerfile17
-rw-r--r--README.md9
2 files changed, 19 insertions, 7 deletions
diff --git a/Dockerfile b/Dockerfile
index 41a64e1..6dd20d1 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -1,18 +1,27 @@
-#FROM golang:1.21.5-bullseye - debian/ubuntu has build dependencies(gcc)
-FROM golang:1.21.5-alpine
+FROM golang:1.21.5-alpine AS builder
RUN mkdir /app
+WORKDIR /app
-ADD . /app
+COPY go.mod go.sum ./
+RUN go mod download
-WORKDIR /app
+COPY . .
#Install the build dependencies
RUN apk add --no-cache gcc libc-dev
+# Build the binary
#CGO_ENABLED=1 for go-sqlite3 to work
RUN CGO_ENABLED=1 go build -o main .
+# Runner Stage
+FROM alpine:latest
+
+WORKDIR /app
+
+COPY --from=builder /app/main .
+
# Volume for SSL/TLS Certificates(optional for development)
VOLUME /certs
diff --git a/README.md b/README.md
index 89101bf..be41f4b 100644
--- a/README.md
+++ b/README.md
@@ -69,9 +69,10 @@ To get started with this project, follow these steps:
```bash
docker run -p 3000:3000 myapp
```
- - For `production` environment with specified certificate and private key paths:
+ - For `production` environment with specified certificate and private key paths and persistant storage:
+
```bash
- docker run -p 3000:3000 -v /path/to/certifcates:/certs myapp
+ docker run -p 3000:3000 --env-file .env -v docker-dbvolume:/app -v /path/to/certifcates:/certs myapp
```
### Usage
@@ -92,7 +93,9 @@ Once the server is running, you can access the API endpoints to upload a file fo
- [x] Store JSON data to DB
- [x] Perform verification
- [x] Containerize the API
-- [ ] Optimize Docker Image size (Currently 509MB)
+- [x] Optimize Docker Image size (Previously 509MB, Optimized: 22.2MB)
+- [ ] Create a Github workflow for binary releases and docker image packages
+
## License
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.