From 8977d5fdecfb314b48ac89da155026ff9d9cf6ad Mon Sep 17 00:00:00 2001 From: CareyWong Date: Wed, 29 Mar 2023 17:35:27 +0800 Subject: [PATCH] fix: docker build --- .gitignore | 3 ++- Dockerfile | 16 ++++++---------- README.md | 22 ++++++++++++++-------- 3 files changed, 22 insertions(+), 19 deletions(-) diff --git a/.gitignore b/.gitignore index 3a80a21..606d02f 100644 --- a/.gitignore +++ b/.gitignore @@ -3,4 +3,5 @@ build/ logs/ data/ -.env \ No newline at end of file +.env +dist/ diff --git a/Dockerfile b/Dockerfile index 582c2a6..c65033b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,14 +1,10 @@ -FROM golang:1.19-alpine AS dependencies +FROM golang:1.20-alpine AS build WORKDIR /app -RUN go env -w GO111MODULE="on" && go env -w GOPROXY="https://goproxy.cn,direct" - -COPY go.sum go.mod main.go ./ -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 +COPY main.go go.mod go.sum . +RUN go mod tidy +RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags="-s -w" -o myurls main.go +RUN apk update && apk add upx +RUN upx myurls FROM scratch WORKDIR /app diff --git a/README.md b/README.md index 5eb55de..0cea0be 100644 --- a/README.md +++ b/README.md @@ -1,18 +1,24 @@ # MyUrls -基于 golang1.15 与 Redis 实现的本地短链接服务,用于缩短请求链接与短链接还原。 +基于 Go 1.20 与 Redis 实现的本地短链接服务,用于缩短请求链接与短链接还原。 ## Table of Contents +- [MyUrls](#myurls) + - [Table of Contents](#table-of-contents) - [Update](#update) - [Dependencies](#dependencies) -- [Docker](#Docker) -- [Install](#install) -- [Usage](#usage) -- [API](#api) -- [Maintainers](#maintainers) -- [Contributing](#contributing) -- [License](#license) + - [Docker](#docker) + - [Deploy Online](#deploy-online) + - [Deploy on Railway](#deploy-on-railway) + - [部署](#部署) + - [添加域名](#添加域名) + - [Install](#install) + - [Usage](#usage) + - [API](#api) + - [Maintainers](#maintainers) + - [Contributing](#contributing) + - [License](#license) # Update