diff --git a/.env.example b/.env.example new file mode 100644 index 0000000..45edc24 --- /dev/null +++ b/.env.example @@ -0,0 +1,3 @@ +MYURLS_PORT=8002 +MYURLS_DOMAIN=example.com +MYURLS_TTL=90 diff --git a/.gitignore b/.gitignore index 03920b6..e827a3f 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,4 @@ .idea build/ + +.env \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..80ddfd7 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,17 @@ +FROM golang:1.13-alpine AS dependencies +WORKDIR /app +RUN go env -w GO111MODULE="on" && go env -w GOPROXY="https://goproxy.cn,direct" + +COPY go.sum go.mod ./ +RUN go mod tidy + +FROM dependencies as build +WORKDIR /app +COPY main.go ./ +RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o myurls main.go + +FROM scratch +WORKDIR /app +COPY --from=build /app/myurls ./ +EXPOSE 8002 +ENTRYPOINT ["/app/myurls"] diff --git a/README.md b/README.md index a531666..1040b5e 100644 --- a/README.md +++ b/README.md @@ -29,7 +29,16 @@ sudo apt-get install redis-server -y ## Docker -TODO +现在你可以无需安装其他服务,使用 [docker-compose](https://docs.docker.com/compose/install/) 部署本项目。注:请自行修改 .env 中参数。 + +```shell script +git clone https://github.com/CareyWang/MyUrls.git MyUrls + +cd MyUrls +cp .env.example .env + +docker-compose up -d +``` ## Install diff --git a/docker-compose.yaml b/docker-compose.yaml new file mode 100644 index 0000000..5f34cf7 --- /dev/null +++ b/docker-compose.yaml @@ -0,0 +1,19 @@ +version: "3" +services: + myurls: + build: . + container_name: myurls + restart: always + env_file: .env + ports: + - "${MYURLS_PORT}:8002" + depends_on: + - redis + entrypoint: ["/app/myurls", "-domain", "${MYURLS_DOMAIN}", "-conn", redis:6379, "-ttl", "${MYURLS_TTL}"] + + redis: + image: "redis:5" + container_name: redis + restart: always + expose: + - "6379"