Skip to content

Commit 50f71d7

Browse files
author
Diyor Khaydarov
committed
fix: split dockerfile into production & test files
1 parent 8a9c8b1 commit 50f71d7

File tree

3 files changed

+38
-28
lines changed

3 files changed

+38
-28
lines changed

Dockerfile

+10-28
Original file line numberDiff line numberDiff line change
@@ -2,53 +2,35 @@ FROM golang:1.23.2 AS base
22

33
WORKDIR /build
44

5-
RUN case "$(uname -m)" in \
6-
"x86_64") ARCH="x64" ;; \
7-
"aarch64") ARCH="arm64" ;; \
8-
*) echo "Unsupported architecture: $(uname -m)" && exit 1 ;; \
9-
esac && \
10-
curl -sLO https://github.com/tailwindlabs/tailwindcss/releases/download/v3.4.15/tailwindcss-linux-${ARCH} && \
11-
chmod +x tailwindcss-linux-${ARCH} && \
12-
mv tailwindcss-linux-${ARCH} /usr/local/bin/tailwindcss
13-
14-
RUN curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.61.0
15-
RUN go install github.com/a-h/templ/cmd/[email protected] && go install github.com/mitranim/gow@latest
16-
17-
FROM base AS install
5+
COPY scripts/install.sh .
6+
RUN chmod +x install.sh && ./install.sh && go install github.com/a-h/templ/cmd/[email protected]
7+
8+
FROM base AS build
189
COPY go.mod go.sum ./
1910
RUN go mod download
2011
COPY . .
2112
RUN make generate && go vet ./...
2213
RUN make css
23-
RUN make release
14+
RUN make release && go build -o migrate cmd/migrate/main.go && go build -o seed_db cmd/seed/main.go
2415

2516
# Default final base image to Alpine Linux
2617
FROM alpine:3.21 AS production
2718

2819
# Ensure we have latest packages applied
29-
RUN apk update \
30-
&& apk upgrade
20+
RUN apk update && apk upgrade
3121

3222
# Create a non-root user
3323
RUN addgroup -g 10001 -S iota-user \
3424
&& adduser --disabled-password --gecos '' -u 10000 --home /home/iota-user iota-user -G iota-user \
3525
&& chown -R iota-user:iota-user /home/iota-user
3626

3727
WORKDIR /home/iota-user
38-
COPY --from=install /build/run_server ./run_server
28+
COPY --from=build /build/run_server ./run_server
29+
COPY --from=build /build/migrate ./migrate
30+
COPY --from=build /build/seed_db ./seed_db
3931

4032
ENV PATH=/home/iota-user:$PATH
4133

4234
USER iota-user
43-
ENTRYPOINT run_server
44-
45-
FROM install AS staging
46-
RUN go build -o run_server cmd/server/main.go && go build -o seed_db cmd/seed/main.go
47-
CMD go run cmd/migrate/main.go up && /build/seed_db && /build/run_server
48-
49-
FROM install AS testing-ci
50-
#CMD golangci-lint run && go test -v ./...
51-
CMD [ "go", "test", "-v", "./..." ]
35+
CMD ["/bin/sh", "-c", "./migrate && ./seed_db && ./run_server"]
5236

53-
FROM install AS testing-local
54-
CMD [ "gow", "test", "./..." ]

Dockerfile.test

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
FROM golang:1.23.2
2+
3+
WORKDIR /build
4+
5+
COPY scripts/install.sh .
6+
RUN chmod +x install.sh && ./install.sh && go install github.com/a-h/templ/cmd/[email protected]
7+
8+
RUN curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.61.0
9+
10+
RUN go install github.com/mitranim/gow@latest
11+
12+
COPY go.mod go.sum ./
13+
RUN go mod download
14+
COPY . .
15+
16+
CMD [ "gow", "test", "./..." ]

scripts/install.sh

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#!/bin/bash
2+
3+
case "$(uname -m)" in
4+
"x86_64") ARCH="x64" ;;
5+
"aarch64") ARCH="arm64" ;;
6+
*) echo "Unsupported architecture: $(uname -m)" && exit 1 ;;
7+
esac
8+
9+
curl -sLO https://github.com/tailwindlabs/tailwindcss/releases/download/v3.4.15/tailwindcss-linux-${ARCH}
10+
chmod +x tailwindcss-linux-${ARCH}
11+
mv tailwindcss-linux-${ARCH} /usr/local/bin/tailwindcss
12+
echo "tailwindcss installed successfully"

0 commit comments

Comments
 (0)