Skip to content

Commit

Permalink
ci: test
Browse files Browse the repository at this point in the history
  • Loading branch information
wouiSB committed Jul 24, 2024
1 parent b5a1fce commit d11eebc
Show file tree
Hide file tree
Showing 6 changed files with 219 additions and 0 deletions.
14 changes: 14 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
version: 2
updates:
- package-ecosystem: "npm"
directory: "/mainpage"
target-branch: "dev"
schedule:
interval: "daily"
open-pull-requests-limit: 10
- package-ecosystem: "pip"
directory: "/"
target-branch: "dev"
schedule:
interval: "daily"
open-pull-requests-limit: 10
27 changes: 27 additions & 0 deletions .github/workflows/build-image-dev.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Build and push dev Docker image

on:
push:
branches:
- main
- dev
paths:
- '.github/workflows/build-image.yml'
- '.github/workflows/build-image-dev.yml'
- 'Dockerfile'
- '**.py'
- 'static/**'
- 'requirements.txt'
workflow_dispatch:

permissions:
contents: read
packages: write

jobs:
build-and-push:
if: github.repository == 'SubConv/SubConv-sing-box'
uses: ./.github/workflows/build-image.yml
secrets: inherit
with:
tags: dev
72 changes: 72 additions & 0 deletions .github/workflows/build-image.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
name: Build and Push Container Image

on:
workflow_call:
inputs:
tags:
description: 'Tag to use for the image'
type: string
required: true
default: 'dev'

permissions:
contents: read
packages: write

env:
IMAGE_REPOSITORY: wouisb/subconv-sing-box

jobs:
setup:
runs-on: ubuntu-latest
outputs:
tags: ${{ steps.tag.outputs.TAG_NAME }}
steps:
- id: tag
run: |
# get tag from input (comma separated) and image_repository
new_tag=""
for tag in $(echo ${{ inputs.tags }} | tr "," "\n"); do
new_tag="$new_tag,${{ env.IMAGE_REPOSITORY }}:$tag"
done
# outupt
echo "TAG_NAME=$new_tag" >> $GITHUB_OUTPUT
build-and-push:
runs-on: ubuntu-latest
needs: setup

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

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

- name: Log in to GitHub Container Registry
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Cache Nuitka cache
uses: actions/cache@v4
with:
path: nuitka-cache
key: nuitka-cache

- name: Inject Nuitka cache into Docker
uses: reproducible-containers/[email protected]
with:
cache-source: nuitka-cache
cache-target: /root/.cache/Nuitka

- name: Build and push Docker image
uses: docker/build-push-action@v5
with:
context: .
push: true
tags: ${{ needs.setup.outputs.tags }}
platforms: |
linux/amd64
linux/arm64
64 changes: 64 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
name: Build

on:
push:
branches:
- '**'
tags-ignore:
- '**'
paths:
- '.github/workflows/build.yml'
- '**.py'
- 'static/**'
- 'main.py'
- 'requirements.txt'
workflow_call:


jobs:
build:
if: github.repository == 'SubConv/SubConv-sing-box'
strategy:
matrix:
os: [windows-latest, ubuntu-latest, macos-latest]
arch: [x64]
include:
- os: macos-latest
arch: arm64

runs-on: ${{ matrix.os }}

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

- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: '3.11'
architecture: ${{ matrix.arch }}
cache: 'pip'
cache-dependency-path: requirements.txt

- name: Install Dependencies
run: |
pip install -r requirements.txt
- name: Build Executable
uses: Nuitka/Nuitka-Action@main
with:
nuitka-version: main
script-name: main.py
onefile: true

- name: Copy Files
run: |
mkdir output
cp build/main${{ matrix.os == 'windows-latest' && '.exe' || '.bin' }} output/main${{ matrix.os == 'windows-latest' && '.exe' || '' }}
cp -r static output/static
- name: Upload Artifacts
uses: actions/upload-artifact@v4
with:
name: subconv-sing-box-${{ matrix.os }}-${{ matrix.arch }}
path: output/
33 changes: 33 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
FROM --platform=$BUILDPLATFORM python:3.11.8-alpine3.19 AS builder
LABEL name="subconv-sing-box"

WORKDIR /app

COPY . .

# Install dependencies
RUN apk add --update-cache ca-certificates tzdata patchelf clang ccache

# Insall python and dependencies
RUN pip3 install -r requirements.txt && \
pip3 install nuitka

# Use nuikta to compile the python code
RUN --mount=type=cache,target=/root/.cache/Nuitka \
python3 -m nuitka --clang --onefile --standalone main.py && \
chmod +x main.bin


FROM alpine

WORKDIR /app

COPY --from=builder /app/main.bin /app/main.bin
COPY --from=builder /usr/share/zoneinfo /usr/share/zoneinfo
COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
COPY static /app/static
COPY config.yaml /app/config.yaml

EXPOSE 8080

ENTRYPOINT ["/app/main.bin"]
9 changes: 9 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
services:
subconv:
image: wouisb/subconv-sing-box:latest
container_name: subconv-sing-box
restart: unless-stopped
ports:
- "8080:8080"
volumes:
- ./config.yml:/app/config.yml

0 comments on commit d11eebc

Please sign in to comment.