Skip to content

Commit

Permalink
#80 Docker 支持优化
Browse files Browse the repository at this point in the history
  • Loading branch information
HoshinoSuzumi committed Jun 7, 2023
1 parent 6726b95 commit c14186c
Show file tree
Hide file tree
Showing 9 changed files with 154 additions and 41 deletions.
4 changes: 4 additions & 0 deletions .dockerignore
@@ -0,0 +1,4 @@
/.nuxt
/dist
/node_modules
/coverage
59 changes: 59 additions & 0 deletions .github/workflows/container.yml
@@ -0,0 +1,59 @@
name: "Make Docker Image"

on:
push:
branches: [ main ]
tags:
- *

jobs:
build:
name: "Build Image"
runs-on: ${{ matrix.os }}

strategy:
matrix:
os: [ ubuntu-latest ]
node: [ 16 ]

steps:
- name: Checkout
uses: actions/checkout@v3

- name: Set up QEMU
uses: docker/setup-qemu-action@v2

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2

- name: Login to Docker Hub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Login to GitHub Container Registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Create Dotenv File
uses: actually-colab/github-action-create-env-file@v2.3
with:
envkey_CEVER_VERSION: ${{ github.ref }}
file_name: .env
directory: .

- name: Build and push
uses: docker/build-push-action@v4
with:
context: .
platforms: linux/amd64,linux/arm64
push: true
tags: |
hoshinosuzumi/cfever:latest
hoshinosuzumi/cfever:${{ github.ref }}
ghcr.io/uniiemstudio/ctfever:latest
ghcr.io/uniiemstudio/ctfever:${{ github.ref }}
2 changes: 2 additions & 0 deletions .github/workflows/deploy-to-lighthouse.yml
Expand Up @@ -44,6 +44,8 @@ jobs:
run: yarn test

- name: Build 🛠️
env:
CEVER_RUN_MODE: static
run: |
yarn generate
ls -la
Expand Down
42 changes: 25 additions & 17 deletions Dockerfile
@@ -1,17 +1,25 @@
FROM node:14-alpine as build-stage
ADD . /build_dir

RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.ustc.edu.cn/g' /etc/apk/repositories
RUN apk add --update --no-cache gcc g++ make cmake curl jq py3-configobj py3-pip py3-setuptools python3 python3-dev

RUN cd /build_dir \
&& yarn install \
&& yarn run build \
&& yarn run generate \
&& mv dist /dist

FROM nginx:stable-alpine as production-stage
COPY nginx.conf /etc/nginx/conf.d/default.conf
COPY --from=build-stage /dist /usr/share/nginx/html
EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]
FROM node:16-alpine as build-stage

WORKDIR /build
COPY . .

RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.tuna.tsinghua.edu.cn/g' /etc/apk/repositories
RUN apk add --update --no-cache gcc g++ make cmake curl jq py3-configobj py3-pip py3-setuptools python3 python3-dev

RUN yarn install && \
yarn run build

FROM node:16-alpine as production-stage

LABEL maintainer="hoshinosuzumi"
LABEL org.opencontainers.image.source=https://github.com/UniiemStudio/CTFever

ENV CEVER_RUN_MODE=server
ENV CEVER_BACKEND_BASE=https://ctfever-service.uniiem.com

WORKDIR /app
COPY --from=build-stage /build .

EXPOSE 3000

CMD yarn start
10 changes: 10 additions & 0 deletions lang/en-US.js
Expand Up @@ -67,6 +67,16 @@ export default {
}
},
},
backend: {
label: 'Backend',
subtitle: 'Some tools require backend support',
endpoint: {
label: 'Endpoint',
},
version: {
label: 'Version',
}
},
danger_zone: {
label: 'Danger Zone',
subtitle: 'These actions may affect or clear local data',
Expand Down
10 changes: 10 additions & 0 deletions lang/zh-CN.js
Expand Up @@ -67,6 +67,16 @@ export default {
}
},
},
backend: {
label: '后端',
subtitle: '部分工具需要后端支持',
endpoint: {
label: '服务器端点',
},
version: {
label: '服务端版本',
}
},
danger_zone: {
label: '危险区',
subtitle: '这些操作可能会影响或破坏本地数据',
Expand Down
17 changes: 0 additions & 17 deletions nginx.conf

This file was deleted.

15 changes: 9 additions & 6 deletions nuxt.config.js
@@ -1,11 +1,14 @@
export default {
// Disable server-side rendering: https://go.nuxtjs.dev/ssr-mode
ssr: false,
target: "static",
// target: "server",
// server: {
// host: process.env.NODE_ENV === 'production' ? '0.0.0.0' : 'localhost'
// },
target: process.env.CEVER_RUN_MODE || "static",
server: {
host: process.env.NODE_ENV === 'production' ? '0.0.0.0' : 'localhost'
},
publicRuntimeConfig: {
version: process.env.CEVER_VERSION || 'unstable',
CEVER_BACKEND_BASE: process.env.CEVER_BACKEND_BASE
},
// Global page headers: https://go.nuxtjs.dev/config-head
head: {
title: "CTFever Toolkit by uniiem",
Expand Down Expand Up @@ -186,7 +189,7 @@ export default {
proxy: {
'/gateway/': {
// target: process.env.NODE_ENV === 'production' ? 'https://ctfever-service.uniiem.com' : 'http://127.0.0.1:8080',
target: 'https://ctfever-service.uniiem.com',
target: process.env.CEVER_BACKEND_BASE || 'https://ctfever-service.uniiem.com',
changeOrigin: true,
pathRewrite: {
'^/gateway/': '/'
Expand Down
36 changes: 35 additions & 1 deletion pages/settings.vue
Expand Up @@ -5,6 +5,14 @@ import {Icon} from "@iconify/vue2";
export default defineComponent({
name: "settings",
head() {
return {
title: "Preferences" + " - " + this.$t("app.name"),
meta: [
{hid: "description", name: "description", content: '偏好设置'},
],
};
},
components: {Icon, PrimaryContainer},
data() {
return {
Expand All @@ -26,6 +34,9 @@ export default defineComponent({
icon: 'tabler:device-desktop-cog'
},
],
server_online: 'pending...',
server_endpoint: this.$config.CEVER_BACKEND_BASE.includes('uniiem.com') ? 'Official' : this.$config.CEVER_BACKEND_BASE,

Check failure

Code scanning / CodeQL

Incomplete URL substring sanitization High

'
uniiem.com
' can be anywhere in the URL, and arbitrary hosts may come before or after it.
server_version: null
}
},
computed: {
Expand All @@ -47,6 +58,18 @@ export default defineComponent({
}
},
mounted() {
const server_status_endpoint = new URL('status', this.$config.CEVER_BACKEND_BASE);
this.$axios.get(server_status_endpoint.href).then(res => {
if (res.data.status === 'ok')
this.server_online = 'online'
else
this.server_online = 'offline'
this.server_version = res.data.version;
}).catch(err => {
this.server_online = 'offline'
this.server_version = `Failed to fetch (${err.response.status} ${err.response.data.detail})`
})
this.languageOptions = this.$i18n.locales.map(locale => ({
value: locale.code,
label: locale.name,
Expand Down Expand Up @@ -105,7 +128,7 @@ export default defineComponent({
icon="tabler:info-square-rounded">
<SettingsItem
:title="$t('settings.about.version.label').toString()"
subtitle="2.7.0">
:subtitle="$config.version">
<template #actions>
<SettingsButton ghost>{{ $t('settings.about.version.check_update_logs').toString() }}</SettingsButton>
</template>
Expand All @@ -128,6 +151,17 @@ export default defineComponent({
</template>
</SettingsItem>
</SettingsArea>
<SettingsArea
:title="$t('settings.backend.label').toString()"
:subtitle="$t('settings.backend.subtitle').toString()"
icon="tabler:server-2">
<SettingsItem
:title="$t('settings.backend.endpoint.label').toString()"
:subtitle="`${server_endpoint} - ${server_online}`"/>
<SettingsItem
:title="$t('settings.backend.version.label').toString()"
:subtitle="server_version || (server_online === 'pending...' ? 'Fetching...' : server_online === 'online' ? server_version : 'unavailable')"/>
</SettingsArea>
<SettingsDivider/>
<SettingsArea
danger
Expand Down

0 comments on commit c14186c

Please sign in to comment.