-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dockerfile
51 lines (35 loc) · 1.43 KB
/
Dockerfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# Use the official Golang image as a base
FROM golang:1.20 AS builder
# Set the Current Working Directory inside the container
WORKDIR /app
# Copy go mod and sum files
COPY go.mod go.sum ./
# Download all dependencies. Dependencies will be cached if the go.mod and go.sum files are not changed
RUN go mod download
# Copy the source code into the container
COPY . .
# Install sql-migrate
RUN go install github.com/rubenv/sql-migrate/...@latest
# Build the Go app
RUN go build -o main ./delivery/http
# Start a new stage from scratch using the same base image
FROM golang:1.20
# Start a new stage from scratch
FROM ubuntu:22.04
# Install necessary libraries (glibc)
RUN apt-get update && apt-get install -y libc6 && apt-get install -y netcat && rm -rf /var/lib/apt/lists/*
# Set the Current Working Directory inside the container
WORKDIR /app
# Copy the pre-built binary file from the previous stage
COPY --from=builder /app/main .
COPY --from=builder /go/bin/sql-migrate /usr/local/bin/sql-migrate
COPY config.yml .
COPY buf.gen.yaml .
COPY buf.yaml .
# Copy migration files and configuration
COPY internal/infra/config/db/dbconfig.yml ./internal/infra/config/db/
COPY internal/infra/repository/migration ./internal/infra/repository/migration
# Expose port 8080 to the outside world
EXPOSE 8000
# Command to run the executable
CMD ["sh", "-c", "sleep 30 && sql-migrate up -env=production -config=internal/infra/config/db/dbconfig.yml && ./main"]