Skip to content

Commit

Permalink
Version v1.2.0
Browse files Browse the repository at this point in the history
upgrade: upgrade CI & add Makefile
upgrade: move the authentication API to backend
  • Loading branch information
llaoj committed Mar 16, 2024
1 parent e93ac72 commit 61f2b7d
Show file tree
Hide file tree
Showing 1,440 changed files with 768,074 additions and 554 deletions.
20 changes: 3 additions & 17 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,7 @@ jobs:
steps:
- uses: actions/checkout@v3

- name: Variables
- name: Build gcopy & gcopy-frontend image
run: |
echo "REGISTRY=registry.cn-beijing.aliyuncs.com" >> $GITHUB_ENV
echo "GIT_TAG=${GITHUB_REF#refs/tags/}" >> $GITHUB_ENV
- name: Build server image
run: |
IMAGE=${{ env.REGISTRY }}/llaoj/gcopy-server:${{ env.GIT_TAG }}
docker build -t $IMAGE -f build/server/Dockerfile .
docker login -u ${{ secrets.REGISTRY_USERNAME }} -p ${{ secrets.REGISTRY_PASSWORD }} ${{ env.REGISTRY }}
docker push $IMAGE
- name: Build frontend image
run: |
IMAGE=${{ env.REGISTRY }}/llaoj/gcopy-frontend:${{ env.GIT_TAG }}
docker build -t $IMAGE -f build/frontend/Dockerfile .
docker login -u ${{ secrets.REGISTRY_USERNAME }} -p ${{ secrets.REGISTRY_PASSWORD }} ${{ env.REGISTRY }}
docker push $IMAGE
docker login -u ${{ secrets.REGISTRY_USERNAME }} -p ${{ secrets.REGISTRY_PASSWORD }} registry.cn-beijing.aliyuncs.com
make push-container
25 changes: 25 additions & 0 deletions .github/workflows/release-tag.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: release-tag

on:
push:
branches:
- main
paths:
- version.txt

jobs:
tag:
if: ${{ github.repository == 'llaoj/gcopy' }}
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- run: /usr/bin/git config --global user.email actions@github.com
- run: /usr/bin/git config --global user.name 'GitHub Actions Release Tagger'
- run: hack/release-tag.sh
id: release_tag
outputs:
release_tag: ${{ steps.release_tag.outputs.release_tag }}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.gcopy
dist/
frontend/.env
output/
76 changes: 76 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
.PHONY: all \
vet fmt version test \
push-container release clean gomod

# PLATFORMS is the set of OS_ARCH that NPD can build against.
LINUX_PLATFORMS=linux_amd64
DOCKER_PLATFORMS=linux/amd64
PLATFORMS=$(LINUX_PLATFORMS) windows_amd64

# VERSION is the version of the binary.
VERSION=$(shell cat version.txt)

# TAG is the tag of the container image, default to binary version.
TAG?=$(VERSION)

# REGISTRY is the container registry to push into.
REGISTRY?=registry.cn-beijing.aliyuncs.com/llaoj

# PKG is the package name of gcopy repo.
PKG:=github.com/llaoj/gcopy

# GCOPY_IMAGE is the image name of the gcopy container image.
GCOPY_IMAGE:=$(REGISTRY)/gcopy:$(TAG)
# GCOPY_FRONTEND_IMAGE is the image name of the gcopy web client container image.
GCOPY_FRONTEND_IMAGE:=$(REGISTRY)/gcopy-frontend:$(TAG)

# Disable cgo by default to make the binary statically linked.
CGO_ENABLED:=0

version:
@echo $(VERSION)

vet:
go list -tags "" ./... | grep -v "./vendor/*" | xargs go vet -tags ""

fmt:
find . -type f -name "*.go" | grep -v "./vendor/*" | xargs gofmt -s -w -l

test: vet fmt
go test -timeout=1m -v -race -short ./...

output/linux_amd64/bin/%:
GOOS=linux GOARCH=amd64 CGO_ENABLED=$(CGO_ENABLED) \
CC=x86_64-linux-gnu-gcc go build \
-o $@ \
-ldflags '-X $(PKG)/pkg/version.version=$(VERSION)' \
./cmd
touch $@

output/windows_amd64/bin/%.exe:
GOOS=windows GOARCH=amd64 CGO_ENABLED=$(CGO_ENABLED) go build \
-o $@ \
-ldflags '-X $(PKG)/pkg/version.version=$(VERSION)' \
./cmd
touch $@

output/darwin_amd64/bin/%:
GOOS=darwin GOARCH=amd64 CGO_ENABLED=$(CGO_ENABLED) go build \
-o $@ \
-ldflags '-X $(PKG)/pkg/version.version=$(VERSION)' \
./cmd
touch $@

push-container: clean
docker buildx create --platform $(DOCKER_PLATFORMS) --use
docker buildx build --push --platform $(DOCKER_PLATFORMS) -t $(GCOPY_IMAGE) -f build/gcopy/Dockerfile .
docker buildx build --push --platform $(DOCKER_PLATFORMS) -t $(GCOPY_FRONTEND_IMAGE) -f build/frontend/Dockerfile .

clean:
rm -rf output/
rm -f coverage.out

gomod:
go mod tidy
go mod vendor
go mod verify
1 change: 0 additions & 1 deletion build/Dockerfile

This file was deleted.

16 changes: 16 additions & 0 deletions build/gcopy/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
FROM golang

WORKDIR /app
COPY . .

RUN make output/linux_amd64/bin/gcopy

From alpine
LABEL maintainer="Llaoj <hmmmbiubiubiu@gmail.com>"

WORKDIR /
COPY --from=0 /app/output/linux_amd64/bin/gcopy .

EXPOSE 3376

ENTRYPOINT ["/gcopy"]
18 changes: 0 additions & 18 deletions build/server/Dockerfile

This file was deleted.

6 changes: 5 additions & 1 deletion cmd/gcopy.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ import (
)

func main() {
cfg := config.Get()
if cfg == nil {
return
}

fmt.Println(`
__ _ ___ ___ _ __ _ _
/ _ |/ __/ _ \| '_ \| | | |
Expand All @@ -19,7 +24,6 @@ func main() {
|___/ |_| |___/ `)
fmt.Println()

cfg := config.Get()
log := logrus.New()
log.SetOutput(os.Stdout)
if cfg.Debug {
Expand Down
11 changes: 6 additions & 5 deletions deploy/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
version: '3.8'
services:
gcopy-server:
container_name: gcopy-server
image: registry.cn-beijing.aliyuncs.com/llaoj/gcopy-server:v1.1.2
gcopy:
container_name: gcopy
image: registry.cn-beijing.aliyuncs.com/llaoj/gcopy:v1.1.5
restart: always
command: ["--app-key=<app-key>", "--smtp-host=<smtp-host>", "--smtp-username=<smtp-username>", "--smtp-password=<smtp-password>", "--smtp-ssl"]

gcopy-frontend:
container_name: gcopy-frontend
image: registry.cn-beijing.aliyuncs.com/llaoj/gcopy-frontend:v1.1.2
image: registry.cn-beijing.aliyuncs.com/llaoj/gcopy-frontend:v1.1.5
restart: always
ports:
- "3375:3375"
volumes:
- ./frontend/.env.production:/app/.env.production
depends_on:
- gcopy-server
- gcopy

11 changes: 9 additions & 2 deletions docs/how-to-deploy.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,19 @@ You can refer to the Nginx configuration file: `deploy/nginx-example.conf`

Using docker compose:

1. Create docker-compose.yml file, refer: `deploy/docker-compose.yml`
1. Create docker-compose.yml file, modify the params `<var-name>`, refer: `deploy/docker-compose.yml`. For the `<app-key>` param, use the following command:

```sh
sed -i "s#^<app-key>#$(openssl rand -base64 16)#" docker-compose.yml
```



2. Create configuration file of frontend, refer: `frontend/.env.sample`
3. Start the containers:

```sh
sed -i "s#^IRON_SESSION_PASSWORD=.*#IRON_SESSION_PASSWORD=$(openssl rand -base64 32)#" frontend/.env.production

docker-compose up -d
```

Expand Down
8 changes: 1 addition & 7 deletions frontend/.env.sample
Original file line number Diff line number Diff line change
@@ -1,7 +1 @@
SERVER_URL=http://gcopy-server:3376
IRON_SESSION_PASSWORD=<at-least-32-characters-long>
SMTP_HOST=
SMTP_PORT=587
SMTP_USERNAME=
SMTP_PASSWORD=
SMTP_SENDER=
SERVER_URL=http://gcopy:3376
10 changes: 7 additions & 3 deletions frontend/app/[locale]/user/email-code/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,12 @@ export default function EmailCode({
setClicked(true);
const formData = new FormData(event.currentTarget as HTMLFormElement);
const email = formData.get("email") as string;
const res = await fetch("/api/user/email-code", {
if (!/^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i.test(email)) {
setErrorMessage(t("invalidEmail"));
setClicked(false);
return;
}
const res = await fetch("/api/v1/user/email-code", {
headers: {
accept: "application/json",
"content-type": "application/json",
Expand All @@ -34,8 +39,7 @@ export default function EmailCode({
router.push(`/${locale}/user/login?email=${email}`);
return;
}
const body = await res.json();
setErrorMessage(body.message);
setErrorMessage(t("sendEmailFailed"));
setClicked(false);
};

Expand Down
21 changes: 16 additions & 5 deletions frontend/app/[locale]/user/login/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,27 @@ export default function Login({
event.preventDefault();
setClicked(true);
const formData = new FormData(event.currentTarget as HTMLFormElement);
const res = await fetch("/api/user/login", {
const email = formData.get("email") as string;
const code = formData.get("code") as string;
if (!/^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i.test(email)) {
setErrorMessage(t("invalidEmail"));
setClicked(false);
return;
}
if (!/\d{6}/i.test(code)) {
setErrorMessage(t("incorrectCode"));
setClicked(false);
return;
}
const res = await fetch("/api/v1/user/login", {
headers: {
accept: "application/json",
"content-type": "application/json",
},
method: "POST",
body: JSON.stringify({
email: formData.get("email") as string,
code: formData.get("code") as string,
email: email,
code: code,
}),
});

Expand All @@ -38,8 +50,7 @@ export default function Login({
return;
}

const body = await res.json();
setErrorMessage(body.message);
setErrorMessage(t("authenticationFailed"));
setClicked(false);
};

Expand Down
23 changes: 0 additions & 23 deletions frontend/app/api/session/route.ts

This file was deleted.

Loading

0 comments on commit 61f2b7d

Please sign in to comment.