Skip to content

Commit

Permalink
feat: optimised docker build
Browse files Browse the repository at this point in the history
  • Loading branch information
proffapt committed Jul 2, 2024
1 parent 3dee899 commit fdf45e8
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 36 deletions.
30 changes: 18 additions & 12 deletions backend/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,21 +1,27 @@
FROM golang:1.21 AS builder

WORKDIR /src
COPY . .

COPY go.mod go.sum ./

RUN go mod download
RUN CGO_ENABLED=1 GOOS=linux go build -o /app --tags "fts5" -a -ldflags '-linkmode external -extldflags "-static"' .

FROM busybox:1.36-musl
COPY . .

RUN CGO_ENABLED=1 GOOS=linux go build -o ./build --tags "fts5" -a -ldflags '-linkmode external -extldflags "-static"' .

FROM alpine:latest AS app

RUN apk --no-cache add bash nginx ca-certificates tzdata

ENV TZ="Asia/Kolkata"

WORKDIR /app

# Copy metaploy configuration
COPY metaploy/iqps.metaploy.conf /
COPY metaploy/postinstall.sh /
COPY metaploy/ ./

# Set the postinstall script as executable
RUN chmod +x /postinstall.sh
RUN chmod +x ./postinstall.sh

# Copy the binary from the builder
COPY --from=builder /app /app
COPY --from=builder /src/build .

# Run postinstall script and the binary
CMD ["/postinstall.sh", "/app"]
CMD ["./postinstall.sh", "./build"]
11 changes: 2 additions & 9 deletions backend/docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ services:
container_name: iqps-backend
build: .
restart: always
env_file:
- .env
networks:
metaploy-network:
aliases:
Expand All @@ -13,15 +15,6 @@ services:
- ./db:/db
- nginx-config-volume:/etc/nginx/sites-enabled
- odins-vault:/srv/static
environment:
- STATIC_FILES_URL=${STATIC_FILES_URL}
- STATIC_FILES_STORAGE_LOCATION=${STATIC_FILES_STORAGE_LOCATION}
- DB_NAME=${DB_NAME}
- DB_HOST=${DB_HOST}
- DB_PORT=${DB_PORT}
- DB_USER=${DB_USER}
- DB_PASSWORD=${DB_PASSWORD}
- UPLOADED_QPS_PATH=${UPLOADED_QPS_PATH}

networks:
metaploy-network:
Expand Down
5 changes: 1 addition & 4 deletions backend/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@ module github.com/metakgp/iqps/backend

go 1.21.6

require (
github.com/joho/godotenv v1.5.1
github.com/rs/cors v1.10.1
)
require github.com/rs/cors v1.10.1

require github.com/lib/pq v1.10.9
2 changes: 0 additions & 2 deletions backend/go.sum
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0=
github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4=
github.com/lib/pq v1.10.9 h1:YXG7RB+JIjhP29X+OtkiDnYaXQwpS4JEWq7dtCCRUEw=
github.com/lib/pq v1.10.9/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o=
github.com/rs/cors v1.10.1 h1:L0uuZVXIKlI1SShY2nhFfo44TYvDPQ1w4oFkUJNfhyo=
Expand Down
6 changes: 0 additions & 6 deletions backend/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import (
"strings"
"time"

"github.com/joho/godotenv"
"github.com/rs/cors"

_ "github.com/lib/pq"
Expand Down Expand Up @@ -316,11 +315,6 @@ func CheckError(err error) {
}

func main() {
err := godotenv.Load(".env")
if err != nil {
log.Println(err)
}

host := os.Getenv("DB_HOST")
port, err := strconv.Atoi(os.Getenv("DB_PORT"))
CheckError(err)
Expand Down
4 changes: 1 addition & 3 deletions backend/metaploy/postinstall.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ trap 'cleanup' SIGQUIT SIGTERM SIGHUP

"${@}" &

cp /iqps.metaploy.conf /etc/nginx/sites-enabled
cp ./iqps.metaploy.conf /etc/nginx/sites-enabled

wait $!

echo "lmao"

0 comments on commit fdf45e8

Please sign in to comment.