Compare commits
	
		
			No commits in common. "master" and "golang-ubuntu-latest" have entirely different histories.
		
	
	
		
			master
			...
			golang-ubu
		
	
		
|  | @ -2,47 +2,28 @@ name: push | ||||||
| on: | on: | ||||||
|   push: |   push: | ||||||
|     branches: |     branches: | ||||||
|       - master |       - golang-ubuntu-latest | ||||||
| jobs: | jobs: | ||||||
|   build: |   build: | ||||||
|     runs-on: golang-ubuntu-latest |     runs-on: ubuntu-latest | ||||||
|     steps: |     steps: | ||||||
|       - name: Check out repository code |       - name: Check out repository code | ||||||
|         uses: actions/checkout@focs |         uses: actions/checkout@focs | ||||||
|       - name: Display Go version |  | ||||||
|         run: go version |  | ||||||
|       - name: Prepare |  | ||||||
|         run: | |  | ||||||
|           go env -w GO111MODULE=on |  | ||||||
|           go env -w GOPROXY=https://goproxy.cn,direct |  | ||||||
|           mkdir -p ~/.ssh |  | ||||||
|           echo "${{ secrets.DEPLOY_PRIVATE_KEY }}" > ~/.ssh/id_ed25519 |  | ||||||
|           echo "${{ secrets.DEPLOY_KEY }}" > ~/.ssh/id_ed25519.pub |  | ||||||
|           chmod 600 ~/.ssh/id_ed25519 |  | ||||||
|           chmod 600 ~/.ssh/id_ed25519.pub |  | ||||||
|           ssh-keyscan -p 2222 focs.ji.sjtu.edu.cn >> ~/.ssh/known_hosts |  | ||||||
|           ssh -T git@focs.ji.sjtu.edu.cn -p 2222 |  | ||||||
|         shell: bash |  | ||||||
|       - name: Determine build command |       - name: Determine build command | ||||||
|         id: build_command |         id: build_command | ||||||
|         run: | |         run: | | ||||||
|           if echo "${{ gitea.event.head_commit.message }}" | grep -q "force build"; then |           if echo "${{ github.event.head_commit.message }}" | grep -q "force build"; then | ||||||
|             echo "build_command=make force-build" >> $GITEA_ENV |             echo "build_command=make force-build" >> $GITHUB_ENV | ||||||
|           else |           else | ||||||
|             echo "build_command=make build" >> $GITEA_ENV |             echo "build_command=make build" >> $GITHUB_ENV | ||||||
|           fi |           fi | ||||||
|       - name: Build |       - name: Build | ||||||
|         env: |  | ||||||
|           TZ: Asia/Shanghai |  | ||||||
|         run: ${{ env.build_command }} |         run: ${{ env.build_command }} | ||||||
|       - name: Test |  | ||||||
|         run: make test |  | ||||||
|       - name: Check images |       - name: Check images | ||||||
|         run: docker images |         run: docker images | ||||||
|       - name: Remove dangling images |       - name: Remove dangling images | ||||||
|         run: docker image prune -f |         run: docker image prune -f | ||||||
|       - name: Docker Login |       - name: Docker Login | ||||||
|         run: | |         run: "echo \"${{ secrets.DOCKER_PASSWORD }}\" | docker login -u ${{ secrets.DOCKER_USERNAME }} --password-stdin focs.ji.sjtu.edu.cn:5000          \n" | ||||||
|           echo "${{ secrets.DOCKER_PASSWORD }}" | docker login -u ${{ secrets.DOCKER_USERNAME }} --password-stdin focs.ji.sjtu.edu.cn:5000 |  | ||||||
|       - name: Docker Push |       - name: Docker Push | ||||||
|         run: make push |         run: make push | ||||||
|  |  | ||||||
							
								
								
									
										2
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										2
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							|  | @ -1,2 +0,0 @@ | ||||||
| /bin/joj3 |  | ||||||
| /bin/repo-health-checker |  | ||||||
							
								
								
									
										3
									
								
								.gitmodules
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										3
									
								
								.gitmodules
									
									
									
									
										vendored
									
									
								
							|  | @ -1,3 +0,0 @@ | ||||||
| [submodule "JOJ3"] |  | ||||||
| 	path = JOJ3 |  | ||||||
| 	url = ssh://git@focs.ji.sjtu.edu.cn:2222/JOJ/JOJ3.git |  | ||||||
							
								
								
									
										41
									
								
								Dockerfile
									
									
									
									
									
								
							
							
						
						
									
										41
									
								
								Dockerfile
									
									
									
									
									
								
							|  | @ -1,33 +1,22 @@ | ||||||
| FROM focs.ji.sjtu.edu.cn:5000/gitea/runner-images:ubuntu-latest-slim | FROM focs.ji.sjtu.edu.cn:5000/gitea/runner-images:ubuntu-latest | ||||||
| 
 | 
 | ||||||
| ENV TZ="Asia/Shanghai" | ARG GO_VERSION=1.24.1 | ||||||
|  | ARG GOLANGCI_LINT_VERSION=2.2.2 | ||||||
|  | ENV PATH=$PATH:/usr/local/go/bin:/root/go/bin | ||||||
| 
 | 
 | ||||||
| # install packages | RUN sed -i s@/archive.ubuntu.com/@/mirrors.tuna.tsinghua.edu.cn/@g /etc/apt/sources.list && \ | ||||||
| RUN sed -i s@/deb.debian.org/@/mirrors.tuna.tsinghua.edu.cn/@g /etc/apt/sources.list.d/debian.sources && \ |  | ||||||
|     apt-get update && \ |     apt-get update && \ | ||||||
|     apt-get install -y --no-install-recommends sudo python3-minimal python3-pip git git-lfs openssh-client rsync && \ |     apt-get install -y --no-install-recommends upx && \ | ||||||
|     apt-get clean && \ |     apt-get clean && \ | ||||||
|     rm -rf /var/lib/apt/lists/* |     rm -rf /var/lib/apt/lists/* | ||||||
| 
 | 
 | ||||||
| # install joint-teapot && joj3-forge | RUN wget -q https://studygolang.com/dl/golang/go${GO_VERSION}.linux-amd64.tar.gz && \ | ||||||
| RUN pip install --no-cache-dir --break-system-packages \ |     rm -rf /usr/local/go && \ | ||||||
|     --index-url https://pypi.tuna.tsinghua.edu.cn/simple \ |     tar -C /usr/local -xzf go${GO_VERSION}.linux-amd64.tar.gz && \ | ||||||
|     git+https://focs.ji.sjtu.edu.cn/git/JOJ/Joint-Teapot \ |     rm go${GO_VERSION}.linux-amd64.tar.gz | ||||||
|     git+https://focs.ji.sjtu.edu.cn/git/JOJ/JOJ3-config-generator |  | ||||||
| 
 | 
 | ||||||
| # install joj3 & repo-health-checker & joj3-forge-convert | RUN wget -q https://ghfast.top/https://github.com/golangci/golangci-lint/releases/download/v${GOLANGCI_LINT_VERSION}/golangci-lint-${GOLANGCI_LINT_VERSION}-linux-amd64.tar.gz && \ | ||||||
| COPY bin/joj3 bin/repo-health-checker bin/joj3-forge-convert /usr/local/bin/ |     tar -C /tmp -xzf golangci-lint-${GOLANGCI_LINT_VERSION}-linux-amd64.tar.gz && \ | ||||||
| RUN chmod +x /usr/local/bin/joj3 /usr/local/bin/repo-health-checker /usr/local/bin/joj3-forge-convert |     rm -rf golangci-lint-${GOLANGCI_LINT_VERSION}-linux-amd64.tar.gz && \ | ||||||
| 
 |     mkdir -p /root/go/bin && \ | ||||||
| # set permissions |     mv /tmp/golangci-lint-${GOLANGCI_LINT_VERSION}-linux-amd64/golangci-lint /root/go/bin | ||||||
| RUN userdel -r node && \ |  | ||||||
|     useradd -u 1000 -ms /bin/bash tt && \ |  | ||||||
|     useradd -u 1001 -ms /bin/bash student && \ |  | ||||||
|     usermod -aG student tt && \ |  | ||||||
|     chmod 700 /home/tt /home/student && \ |  | ||||||
|     echo "student ALL=(tt) NOPASSWD:SETENV:/usr/local/bin/joj3,/usr/local/bin/joj3-forge-convert\ntt ALL=(student) NOPASSWD:SETENV:ALL" > /etc/sudoers.d/joj && \ |  | ||||||
|     chmod 440 /etc/sudoers.d/joj |  | ||||||
| 
 |  | ||||||
| # entry setup |  | ||||||
| USER student |  | ||||||
| WORKDIR /home/student |  | ||||||
|  |  | ||||||
							
								
								
									
										1
									
								
								JOJ3
									
									
									
									
									
								
							
							
								
								
								
								
								
								
							
						
						
									
										1
									
								
								JOJ3
									
									
									
									
									
								
							|  | @ -1 +0,0 @@ | ||||||
| Subproject commit d316a179f27fb97c76b5e7c12e1a2b4108747270 |  | ||||||
							
								
								
									
										26
									
								
								Makefile
									
									
									
									
									
								
							
							
						
						
									
										26
									
								
								Makefile
									
									
									
									
									
								
							|  | @ -1,26 +1,12 @@ | ||||||
| .PHONY: all prepare force-build build test push | .PHONY: all force-build build push | ||||||
| 
 |  | ||||||
| IMAGE_NAME := focs.ji.sjtu.edu.cn:5000/gitea/runner-images:focs-ubuntu-latest-slim |  | ||||||
| 
 | 
 | ||||||
| all: build | all: build | ||||||
| 
 | 
 | ||||||
| prepare: | force-build: | ||||||
| 	git submodule update --init --remote | 	docker build --no-cache -t focs.ji.sjtu.edu.cn:5000/gitea/runner-images:golang-ubuntu-latest . | ||||||
| 	go env -w GOPROXY=https://goproxy.io,direct |  | ||||||
| 	$(MAKE) -C JOJ3 |  | ||||||
| 	cp JOJ3/build/joj3 JOJ3/build/repo-health-checker bin/ |  | ||||||
| 	ls -lha bin |  | ||||||
| 	# upx --best bin/joj3 bin/repo-health-checker |  | ||||||
| 	# ls -lha bin |  | ||||||
| 
 | 
 | ||||||
| force-build: prepare | build: | ||||||
| 	docker build --no-cache -t $(IMAGE_NAME) . | 	docker build -t focs.ji.sjtu.edu.cn:5000/gitea/runner-images:golang-ubuntu-latest . | ||||||
| 
 |  | ||||||
| build: prepare |  | ||||||
| 	docker build -t $(IMAGE_NAME) . |  | ||||||
| 
 |  | ||||||
| test: |  | ||||||
| 	docker run --rm $(IMAGE_NAME) sudo -u tt -E joj3 --help |  | ||||||
| 
 | 
 | ||||||
| push: | push: | ||||||
| 	docker push $(IMAGE_NAME) | 	docker push focs.ji.sjtu.edu.cn:5000/gitea/runner-images:golang-ubuntu-latest | ||||||
|  |  | ||||||
|  | @ -1,7 +1,3 @@ | ||||||
| # Runner Images | # Runner Images with Golang | ||||||
| 
 | 
 | ||||||
| FOCS docker images used by [act_runner](https://gitea.com/gitea/act_runner) to run workflows. | Actions for this branch will build and push `focs.ji.sjtu.edu.cn:5000/gitea/runner-images:golang-ubuntu-latest` image. | ||||||
| 
 |  | ||||||
| Check <https://gitea.com/gitea/runner-images> for information about base images. |  | ||||||
| 
 |  | ||||||
| Actions for this branch will build and push `focs.ji.sjtu.edu.cn:5000/gitea/runner-images:focs-ubuntu-latest-slim` image. And everything is handled in actions. |  | ||||||
|  |  | ||||||
|  | @ -1,98 +0,0 @@ | ||||||
| #!/usr/bin/env bash |  | ||||||
| 
 |  | ||||||
| set -euo pipefail |  | ||||||
| 
 |  | ||||||
| export PATH="/usr/bin:/bin:/usr/local/bin" |  | ||||||
| unset IFS |  | ||||||
| unset PYTHONPATH |  | ||||||
| unset PYTHONHOME |  | ||||||
| unset HTTP_PROXY |  | ||||||
| unset HTTPS_PROXY |  | ||||||
| 
 |  | ||||||
| main() { |  | ||||||
|     set -x |  | ||||||
|     local org_name |  | ||||||
|     local repo_name |  | ||||||
|     local course |  | ||||||
|     org_name=$(basename "$(dirname "$(pwd)")") |  | ||||||
|     repo_name=$(basename "$(pwd)") |  | ||||||
|     course=${repo_name%-*} |  | ||||||
|     if ! [[ "$course" =~ ^[a-zA-Z0-9_-]+$ ]]; then |  | ||||||
|         echo "FATAL: Invalid course name: $course" >&2 |  | ||||||
|         exit 1 |  | ||||||
|     fi |  | ||||||
| 
 |  | ||||||
|     local config_repo_path="/home/tt/.cache/$course-config" |  | ||||||
|     local grading_repo_path="/home/tt/.cache/$course-joj" |  | ||||||
|     local git_user="bot-$course" |  | ||||||
|     local git_email="bot-$course@focs.ji.sjtu.edu.cn" |  | ||||||
|     local git_server="ssh://git@focs.ji.sjtu.edu.cn:2222" |  | ||||||
| 
 |  | ||||||
|     # init repos if not exist |  | ||||||
|     if ! [ -d "$config_repo_path" ]; then |  | ||||||
|         git clone "$git_server/$course/$course-joj.git" "$config_repo_path" |  | ||||||
|         git -C "$config_repo_path" config user.name "$git_user" |  | ||||||
|         git -C "$config_repo_path" config user.email "$git_email" |  | ||||||
|     fi |  | ||||||
| 
 |  | ||||||
|     if ! [ -d "$grading_repo_path" ]; then |  | ||||||
|         git clone "$git_server/$course/$course-joj.git" "$grading_repo_path" |  | ||||||
|         git -C "$grading_repo_path" config user.name "$git_user" |  | ||||||
|         git -C "$grading_repo_path" config user.email "$git_email" |  | ||||||
|         git -C "$grading_repo_path" switch --orphan grading |  | ||||||
|         cat >"$grading_repo_path/Readme.md" <<EOF |  | ||||||
| # $course JOJ grading |  | ||||||
| 
 |  | ||||||
| This branch is automatically updated by JOJ, **never edit any file in this branch!** |  | ||||||
| EOF |  | ||||||
|         git -C "$grading_repo_path" add Readme.md |  | ||||||
|         git -C "$grading_repo_path" commit -m"docs: readme" |  | ||||||
|         git -C "$grading_repo_path" push -u origin grading |  | ||||||
|     fi |  | ||||||
| 
 |  | ||||||
|     # sync config repo |  | ||||||
|     git -C "$config_repo_path" reset --hard |  | ||||||
|     git -C "$config_repo_path" pull --rebase |  | ||||||
|     if [ -e "$config_repo_path/home/tt/.config/teapot/teapot.env" ]; then |  | ||||||
|         echo "FATAL: Forbidden file found in '/home/tt/.config/teapot/teapot.env'. Check the latest README to set TEAPOT_GITEA_TOKEN in secrets instead." >&2 |  | ||||||
|         exit 1 |  | ||||||
|     fi |  | ||||||
|     rsync -a "$config_repo_path/home/tt/.ssh/" "/home/tt/.ssh" |  | ||||||
|     rsync -a --delete "$config_repo_path/home/tt/.config/" "/home/tt/.config" |  | ||||||
|     joj3-forge convert "/home/tt/.config/joj" |  | ||||||
|     rsync -a --delete "/home/tt/.config/joj/" "$config_repo_path/home/tt/.config/joj" |  | ||||||
| 
 |  | ||||||
|     # enforce correct permissions |  | ||||||
|     chmod 751 "/home/tt/" |  | ||||||
|     chmod 750 "/home/tt/.cache/" || true |  | ||||||
|     chmod 750 "/home/tt/.cache/joj3" || true |  | ||||||
|     chmod 700 "/home/tt/.ssh/" || true |  | ||||||
|     chmod 700 "/home/tt/.config/" |  | ||||||
| 
 |  | ||||||
|     # commit config changes |  | ||||||
|     git -C "$config_repo_path" add home/tt/.config/joj |  | ||||||
|     if ! git -C "$config_repo_path" diff --staged --quiet; then |  | ||||||
|         commit_hash=$(git -C "$config_repo_path" rev-parse HEAD) |  | ||||||
|         git -C "$config_repo_path" commit -m "chore: $commit_hash trigger joj3-forge convert [skip ci]" |  | ||||||
|         git -C "$config_repo_path" push |  | ||||||
|     fi |  | ||||||
| 
 |  | ||||||
|     # check gitea token |  | ||||||
|     if [ -n "${TEAPOT_GITEA_TOKEN:-}" ]; then |  | ||||||
|         local teapot_config_dir="/home/tt/.config/teapot" |  | ||||||
|         mkdir -p "$teapot_config_dir" |  | ||||||
|         cat >"$teapot_config_dir/teapot.env" <<EOF |  | ||||||
| GITEA_ORG_NAME=$org_name |  | ||||||
| GITEA_ACCESS_TOKEN=$TEAPOT_GITEA_TOKEN |  | ||||||
| EOF |  | ||||||
|         if ! (cd /tmp && joint-teapot joj3-check-gitea-token "$teapot_config_dir/teapot.env"); then |  | ||||||
|             echo "FATAL: TEAPOT_GITEA_TOKEN invalid, ask admin to update it" >&2 |  | ||||||
|             exit 1 |  | ||||||
|         fi |  | ||||||
|     else |  | ||||||
|         echo "FATAL: TEAPOT_GITEA_TOKEN not set, ask admin to set it" >&2 |  | ||||||
|         exit 1 |  | ||||||
|     fi |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| main "$@" |  | ||||||
		Loading…
	
		Reference in New Issue
	
	Block a user