-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
optimize: using alpine and builder stages in dockerfile
- Loading branch information
1 parent
196f150
commit 13830a1
Showing
8 changed files
with
50 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,50 +1,50 @@ | ||
FROM centos:7.8.2003 | ||
# Author: ProgramZmh | ||
# License: Apache-2.0 | ||
# Description: Dockerfile for chatnio | ||
|
||
# Install dependencies | ||
RUN yum -y update && \ | ||
yum install -y epel-release gcc make libgcc libstdc++ wget | ||
|
||
# Install golang | ||
RUN wget https://go.dev/dl/go1.21.5.linux-amd64.tar.gz && \ | ||
rm -rf /usr/local/go && tar -C /usr/local -xzf go1.21.5.linux-amd64.tar.gz && \ | ||
rm -rf go1.21.5.linux-amd64.tar.gz | ||
|
||
# Install nodejs | ||
RUN wget https://nodejs.org/dist/v16.14.0/node-v16.14.0-linux-x64.tar.xz && \ | ||
rm -rf /usr/local/node && tar -C /usr/local -xJf node-v16.14.0-linux-x64.tar.xz && \ | ||
rm -rf node-v16.14.0-linux-x64.tar.xz && \ | ||
mv /usr/local/node-v16.14.0-linux-x64 /usr/local/node | ||
|
||
ENV PATH=$PATH:/usr/local/go/bin:/usr/local/node/bin | ||
FROM golang:1.20 AS backend | ||
|
||
|
||
# Copy source code | ||
WORKDIR /backend | ||
COPY . . | ||
|
||
# Set ulimit in container and max open files | ||
RUN ulimit -n 65535 && \ | ||
echo "* soft nofile 65535" >> /etc/security/limits.conf && \ | ||
echo "* hard nofile 65535" >> /etc/security/limits.conf && \ | ||
echo "ulimit -n 65535" >> /etc/profile && \ | ||
echo "ulimit -n 65535" >> /etc/rc.local | ||
|
||
# set go proxy to https://goproxy.cn (open for vps in China Mainland) | ||
# Set go proxy to https://goproxy.cn (open for vps in China Mainland) | ||
# RUN go env -w GOPROXY=https://goproxy.cn,direct | ||
ENV GOOS=linux GOARCH=amd64 GO111MODULE=on CGO_ENABLED=1 | ||
|
||
# Build backend | ||
RUN go install && \ | ||
go build . | ||
|
||
# Build frontend | ||
FROM node:18 AS frontend | ||
|
||
WORKDIR /app | ||
COPY ./app . | ||
|
||
RUN npm install -g pnpm && \ | ||
cd /app && \ | ||
pnpm install && \ | ||
pnpm run build && \ | ||
rm -rf node_modules | ||
rm -rf node_modules src | ||
|
||
|
||
FROM alpine | ||
|
||
# Install dependencies | ||
RUN apk update && \ | ||
apk upgrade && \ | ||
apk add --no-cache wget ca-certificates tzdata && \ | ||
update-ca-certificates 2>/dev/null || true && \ | ||
rm -rf /var/cache/apk/* | ||
|
||
# Set timezone | ||
RUN echo "Asia/Shanghai" > /etc/timezone && \ | ||
ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime | ||
|
||
# Copy dist | ||
COPY --from=backend /backend / | ||
COPY --from=frontend /app/dist /app/dist | ||
|
||
# Expose port | ||
EXPOSE 8094 | ||
|
||
# Start backend | ||
# Run application | ||
CMD ["./chat"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters