Skip to content

Commit

Permalink
Merge pull request #138 from UniversalOJ/docker-compose
Browse files Browse the repository at this point in the history
变更 Docker 镜像发布方式
  • Loading branch information
renbaoshuo authored Jul 2, 2024
2 parents d4cebd9 + d23c207 commit 9ed28d6
Show file tree
Hide file tree
Showing 19 changed files with 280 additions and 284 deletions.
4 changes: 4 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.github/
.git/

uoj_data/
68 changes: 68 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
name: Build & Push Docker Images

on:
push:
branches:
- master
pull_request:
branches:
- master
workflow_dispatch:

env:
REGISTRY: ghcr.io
IMAGE_BASENAME: uoj

jobs:
build:
name: Build Image
runs-on: ubuntu-latest

permissions:
contents: read
packages: write

strategy:
matrix:
include:
- image_name: db
context: db
dockerfile: db/Dockerfile
- image_name: judger
context: judger
dockerfile: judger/Dockerfile
- image_name: web
context: .
dockerfile: web/Dockerfile
fail-fast: false

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Log in to the Container registry
uses: docker/[email protected]
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/[email protected]
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_BASENAME }}-${{ matrix.image_name }}
tags: |
latest
type=ref,event=branch
type=ref,event=pr
type=sha,prefix=
- name: Build and push Docker image
uses: docker/[email protected]
with:
context: ${{ matrix.context }}
file: ${{ matrix.dockerfile }}
push: ${{ github.event_name == 'push' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
.idea
uoj_data/
12 changes: 12 additions & 0 deletions db/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
FROM mysql:5.7
MAINTAINER Baoshuo <[email protected]>
LABEL org.opencontainers.image.source=https://github.com/UniversalOJ/UOJ-System
LABEL org.opencontainers.image.description="UOJ Database"
LABEL org.opencontainers.image.licenses=MIT

ADD . /opt/uoj_db
WORKDIR /opt/uoj_db

RUN sh install.sh

ENV LANG=C.UTF-8 TZ=Asia/Shanghai
2 changes: 2 additions & 0 deletions db/add_judger.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
USE `app_uoj233`;
insert into judger_info (judger_name, password) values ('compose_judger', '_judger_password_');
File renamed without changes.
4 changes: 2 additions & 2 deletions install/db/install.sh → db/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ setWebConf(){
cat >/docker-entrypoint-initdb.d/000-native_password.sql <<UOJEOF
ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY 'root';
UOJEOF
curl $RAW_URL/install/db/app_uoj233.sql >/docker-entrypoint-initdb.d/001-app_uoj233.sql
curl $RAW_URL/install/judger/add_judger.sql >/docker-entrypoint-initdb.d/002-add_judger.sql
cp app_uoj233.sql /docker-entrypoint-initdb.d/001-app_uoj233.sql
cp add_judger.sql /docker-entrypoint-initdb.d/002-add_judger.sql
}

echo 'Preparing UOJ System db environment...'
Expand Down
66 changes: 66 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
version: '3'

services:
uoj-db:
image: ghcr.io/UniversalOJ/uoj-db:latest
build:
context: ./db/
dockerfile: Dockerfile
container_name: uoj-db
restart: always
volumes:
- ./uoj_data/db/mysql:/var/lib/mysql
environment:
- MYSQL_DATABASE=app_uoj233
- MYSQL_ROOT_PASSWORD=root

uoj-judger:
image: ghcr.io/UniversalOJ/uoj-judger:latest
build:
context: ./judger/
dockerfile: Dockerfile
container_name: uoj-judger
restart: always
stdin_open: true
tty: true
cap_add:
- SYS_PTRACE
volumes:
- ./uoj_data/judger/log:/opt/uoj_judger/log
environment:
- UOJ_PROTOCOL=http
- UOJ_HOST=uoj-web
- JUDGER_NAME=compose_judger
- JUDGER_PASSWORD=_judger_password_
- SOCKET_PORT=2333
- SOCKET_PASSWORD=_judger_socket_password_

uoj-web:
image: ghcr.io/UniversalOJ/uoj-web:latest
build:
context: ./
dockerfile: web/Dockerfile
container_name: uoj-web
restart: always
stdin_open: true
tty: true
cap_add:
- SYS_PTRACE
depends_on:
- uoj-db
- uoj-judger
volumes:
- ./uoj_data/web/data:/var/uoj_data
ports:
- "80:80"
- "3690:3690"
environment:
- DATABASE_HOST=uoj-db
- DATABASE_PASSWORD=root
- JUDGER_SOCKET_PORT=2333
- JUDGER_SOCKET_PASSWORD=_judger_socket_password_
- SALT_0=_salt_0_
- SALT_1=_salt_1_
- SALT_2=_salt_2_
- SALT_3=_salt_3_
- UOJ_PROTOCOL=http
27 changes: 0 additions & 27 deletions install/bundle/Dockerfile

This file was deleted.

6 changes: 0 additions & 6 deletions install/bundle/hooks/build

This file was deleted.

165 changes: 0 additions & 165 deletions install/bundle/install.sh

This file was deleted.

9 changes: 0 additions & 9 deletions install/db/Dockerfile

This file was deleted.

Loading

0 comments on commit 9ed28d6

Please sign in to comment.