build: remove Makefile and update Docker build steps (#6980)

This commit is contained in:
Joe Chen 2022-05-29 19:45:25 +08:00 committed by GitHub
parent 8356dc7774
commit d7bda9ac0e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 60 additions and 91 deletions

View File

@ -4,7 +4,6 @@ scripts
scripts/**
.github/
.github/**
config.codekit
.dockerignore
*.yml
*.md
@ -12,3 +11,5 @@ config.codekit
.gitignore
Dockerfile*
gogs
!Taskfile.yml

View File

@ -17,7 +17,7 @@ All notable changes to Gogs are documented in this file.
- The default branch has been changed to `main`. [#6285](https://github.com/gogs/gogs/pull/6285)
- MSSQL as database backend is deprecated, installation page no longer shows it as an option. Existing installations and manually craft configuration file continue to work. [#6295](https://github.com/gogs/gogs/pull/6295)
- Use [Task](https://github.com/go-task/task) as the default build tool for development. [#6297](https://github.com/gogs/gogs/pull/6297)
- Use [Task](https://github.com/go-task/task) as the build tool. [#6297](https://github.com/gogs/gogs/pull/6297)
- The required Go version to compile source code changed to 1.16.
### Fixed
@ -42,6 +42,7 @@ All notable changes to Gogs are documented in this file.
- Configuration option `[server] LANDING_PAGE` is no longer used, please use `[server] LANDING_URL`.
- Configuration option `[database] DB_TYPE` is no longer used, please use `[database] TYPE`.
- Configuration option `[database] PASSWD` is no longer used, please use `[database] PASSWORD`.
- Remove option to use Makefile as the build tool. [#6980](https://github.com/gogs/gogs/pull/6980)
## 0.12.7

View File

@ -7,20 +7,12 @@ RUN apk --no-cache --no-progress add --virtual \
WORKDIR /gogs.io/gogs
COPY . .
RUN make build TAGS="cert pam"
RUN ./docker/build/install-task.sh
RUN TAGS="cert pam" task build
FROM alpine:3.14
RUN if [ `uname -m` == "aarch64" ] ; then \
export arch="arm64" ; \
elif [ `uname -m` == "armv7l" ] ; then \
export arch="armhf"; \
else \
export arch="amd64" ; \
fi \
&& wget https://github.com/tianon/gosu/releases/download/1.11/gosu-$arch -O /usr/sbin/gosu \
&& chmod +x /usr/sbin/gosu \
&& echo http://dl-2.alpinelinux.org/alpine/edge/community/ >> /etc/apk/repositories \
&& apk --no-cache --no-progress add \
RUN apk --no-cache --no-progress add \
bash \
ca-certificates \
curl \
@ -42,7 +34,7 @@ WORKDIR /app/gogs
COPY docker ./docker
COPY --from=binarybuilder /gogs.io/gogs/gogs .
RUN ./docker/finalize.sh
RUN ./docker/build/finalize.sh
# Configure Docker Container
VOLUME ["/data", "/backup"]

View File

@ -1,59 +0,0 @@
LDFLAGS += -X "gogs.io/gogs/internal/conf.BuildTime=$(shell date -u '+%Y-%m-%d %I:%M:%S %Z')"
LDFLAGS += -X "gogs.io/gogs/internal/conf.BuildCommit=$(shell git rev-parse HEAD)"
CONF_FILES := $(shell find conf | sed 's/ /\\ /g')
TEMPLATES_FILES := $(shell find templates | sed 's/ /\\ /g')
PUBLIC_FILES := $(shell find public | sed 's/ /\\ /g')
LESS_FILES := $(wildcard public/less/*.less)
TAGS = ""
BUILD_FLAGS = "-v"
RELEASE_ROOT = "release"
RELEASE_GOGS = "release/gogs"
NOW = $(shell date -u '+%Y%m%d%I%M%S')
.PHONY: check dist build build-no-gen pack release generate less clean test fixme todo legacy
.IGNORE: public/css/gogs.css
all: build
check: test
dist: release
web: build
./gogs web
build:
go build $(BUILD_FLAGS) -ldflags '$(LDFLAGS)' -tags '$(TAGS)' -trimpath -o gogs
pack:
rm -rf $(RELEASE_GOGS)
mkdir -p $(RELEASE_GOGS)
cp -r gogs LICENSE README.md README_ZH.md scripts $(RELEASE_GOGS)
cd $(RELEASE_ROOT) && zip -r gogs.$(NOW).zip "gogs"
release: build pack
less: clean public/css/gogs.min.css
public/css/gogs.min.css: $(LESS_FILES)
@type lessc >/dev/null 2>&1 && lessc --clean-css --source-map "public/less/gogs.less" $@ || echo "lessc command not found or failed"
clean:
find . -name "*.DS_Store" -type f -delete
test:
go test -cover -race ./...
fixme:
grep -rnw "FIXME" internal
todo:
grep -rnw "TODO" internal
# Legacy code should be removed by the time of release
legacy:
grep -rnw "\(LEGACY\|Deprecated\)" internal

View File

@ -61,7 +61,7 @@ $ docker run --name=gogs -p 10022:22 -p 10880:3000 -v gogs-data:/data gogs/gogs
Most of the settings are obvious and easy to understand, but there are some settings can be confusing by running Gogs inside Docker:
- **Repository Root Path**: keep it as default value `/home/git/gogs-repositories` because `start.sh` already made a symbolic link for you.
- **Run User**: keep it as default value `git` because `finalize.sh` already setup a user with name `git`.
- **Run User**: keep it as default value `git` because `build/finalize.sh` already setup a user with name `git`.
- **Domain**: fill in with Docker container IP (e.g. `192.168.99.100`). But if you want to access your Gogs instance from a different physical machine, please fill in with the hostname or IP address of the Docker host machine.
- **SSH Port**: Use the exposed port from Docker container. For example, your SSH server listens on `22` inside Docker, **but** you expose it by `10022:22`, then use `10022` for this value. **Builtin SSH server is not recommended inside Docker Container**
- **HTTP Port**: Use port you want Gogs to listen on inside Docker container. For example, your Gogs listens on `3000` inside Docker, **and** you expose it by `10880:3000`, but you still use `3000` for this value.

30
docker/build/finalize.sh Executable file
View File

@ -0,0 +1,30 @@
#!/bin/sh
set -xe
# Install gosu
if [ "$(uname -m)" = "aarch64" ]; then
export arch='arm64'
export checksum='73244a858f5514a927a0f2510d533b4b57169b64d2aa3f9d98d92a7a7df80cea'
elif [ "$(uname -m)" = "armv7l" ]; then
export arch='armhf'
export checksum='abb1489357358b443789571d52b5410258ddaca525ee7ac3ba0dd91d34484589'
else
export arch='amd64'
export checksum='bd8be776e97ec2b911190a82d9ab3fa6c013ae6d3121eea3d0bfd5c82a0eaf8c'
fi
wget --quiet https://github.com/tianon/gosu/releases/download/1.14/gosu-${arch} -O /usr/sbin/gosu
echo "${checksum} /usr/sbin/gosu" | sha256sum -cs
chmod +x /usr/sbin/gosu
# Create git user for Gogs
addgroup -S git
adduser -G git -H -D -g 'Gogs Git User' git -h /data/git -s /bin/bash && usermod -p '*' git && passwd -u git
echo "export GOGS_CUSTOM=${GOGS_CUSTOM}" >> /etc/profile
# Final cleaning
rm -rf /app/gogs/build
rm -rf /app/gogs/docker/build
rm /app/gogs/docker/nsswitch.conf
rm /app/gogs/docker/README.md

20
docker/build/install-task.sh Executable file
View File

@ -0,0 +1,20 @@
#!/bin/sh
set -xe
if [ "$(uname -m)" = "aarch64" ]; then
export arch='arm64'
export checksum='44fad3d61ad39d0abff33f90fdbb99a666524dbeab08dc9d138d5d3a532ff68a'
elif [ "$(uname -m)" = "armv7l" ]; then
export arch='arm'
export checksum='b10ae7d85749025740097b0c349b946fbabd417c7ee4d2df8ccc5604750accd9'
else
export arch='amd64'
export checksum='b9c5986f33a53094751b5e22ccc33e050b4a0a485658442121331cbb724e631e'
fi
wget --quiet https://github.com/go-task/task/releases/download/v3.12.1/task_linux_${arch}.tar.gz -O task_linux_${arch}.tar.gz
echo "${checksum} task_linux_${arch}.tar.gz" | sha256sum -cs
tar -xzf task_linux_${arch}.tar.gz
mv task /usr/local/bin/task

View File

@ -1,16 +0,0 @@
#!/bin/sh
# Finalize the build
set -x
set -e
# Create git user for Gogs
addgroup -S git
adduser -G git -H -D -g 'Gogs Git User' git -h /data/git -s /bin/bash && usermod -p '*' git && passwd -u git
echo "export GOGS_CUSTOM=${GOGS_CUSTOM}" >> /etc/profile
# Final cleaning
rm -rf /app/gogs/build
rm /app/gogs/docker/finalize.sh
rm /app/gogs/docker/nsswitch.conf
rm /app/gogs/docker/README.md