fix: docker build

This commit is contained in:
CareyWong 2023-03-29 17:35:27 +08:00
parent d2173a4302
commit 8977d5fdec
3 changed files with 22 additions and 19 deletions

1
.gitignore vendored
View File

@ -4,3 +4,4 @@ logs/
data/ data/
.env .env
dist/

View File

@ -1,14 +1,10 @@
FROM golang:1.19-alpine AS dependencies FROM golang:1.20-alpine AS build
WORKDIR /app WORKDIR /app
RUN go env -w GO111MODULE="on" && go env -w GOPROXY="https://goproxy.cn,direct" COPY main.go go.mod go.sum .
COPY go.sum go.mod main.go ./
RUN go mod tidy RUN go mod tidy
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags="-s -w" -o myurls main.go
FROM dependencies as build RUN apk update && apk add upx
WORKDIR /app RUN upx myurls
COPY main.go ./
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o myurls main.go
FROM scratch FROM scratch
WORKDIR /app WORKDIR /app

View File

@ -1,18 +1,24 @@
# MyUrls # MyUrls
基于 golang1.15 与 Redis 实现的本地短链接服务,用于缩短请求链接与短链接还原。 基于 Go 1.20 与 Redis 实现的本地短链接服务,用于缩短请求链接与短链接还原。
## Table of Contents ## Table of Contents
- [MyUrls](#myurls)
- [Table of Contents](#table-of-contents)
- [Update](#update) - [Update](#update)
- [Dependencies](#dependencies) - [Dependencies](#dependencies)
- [Docker](#Docker) - [Docker](#docker)
- [Install](#install) - [Deploy Online](#deploy-online)
- [Usage](#usage) - [Deploy on Railway](#deploy-on-railway)
- [API](#api) - [部署](#部署)
- [Maintainers](#maintainers) - [添加域名](#添加域名)
- [Contributing](#contributing) - [Install](#install)
- [License](#license) - [Usage](#usage)
- [API](#api)
- [Maintainers](#maintainers)
- [Contributing](#contributing)
- [License](#license)
# Update # Update