Skip to content

Commit

Permalink
Merge pull request #3 from a645162/dev
Browse files Browse the repository at this point in the history
fix(CI/CD): Fix build script
  • Loading branch information
a645162 authored Sep 11, 2024
2 parents 1e27d4b + 589ee54 commit 146be03
Show file tree
Hide file tree
Showing 11 changed files with 138 additions and 10 deletions.
Empty file added .github/Disable/.gitignore
Empty file.
Empty file added .github/workflows/.gitignore
Empty file.
3 changes: 3 additions & 0 deletions .github/workflows/docker-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ jobs:
- name: Build .jar file
run: python build_with_docker.py

- name: Check is Build Success
run: ls group-center-docker.jar

- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker BuildX
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,5 @@ out/

### Kotlin ###
.kotlin

.env.act
25 changes: 25 additions & 0 deletions .run/act.docker.run.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="act.docker" type="PythonConfigurationType" factoryName="Python" nameIsGenerated="true">
<module name="group-center" />
<option name="ENV_FILES" value="" />
<option name="INTERPRETER_OPTIONS" value="" />
<option name="PARENT_ENVS" value="true" />
<envs>
<env name="PYTHONUNBUFFERED" value="1" />
</envs>
<option name="SDK_HOME" value="" />
<option name="WORKING_DIRECTORY" value="$PROJECT_DIR$" />
<option name="IS_MODULE_SDK" value="true" />
<option name="ADD_CONTENT_ROOTS" value="true" />
<option name="ADD_SOURCE_ROOTS" value="true" />
<EXTENSION ID="PythonCoverageRunConfigurationExtension" runner="coverage.py" />
<option name="SCRIPT_NAME" value="$PROJECT_DIR$/act.docker.py" />
<option name="PARAMETERS" value="" />
<option name="SHOW_COMMAND_LINE" value="false" />
<option name="EMULATE_TERMINAL" value="false" />
<option name="MODULE_MODE" value="false" />
<option name="REDIRECT_INPUT" value="false" />
<option name="INPUT_FILE" value="" />
<method v="2" />
</configuration>
</component>
25 changes: 25 additions & 0 deletions .run/build-clear.run.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="build-clear" type="PythonConfigurationType" factoryName="Python">
<module name="group-center" />
<option name="ENV_FILES" value="" />
<option name="INTERPRETER_OPTIONS" value="" />
<option name="PARENT_ENVS" value="true" />
<envs>
<env name="PYTHONUNBUFFERED" value="1" />
</envs>
<option name="SDK_HOME" value="" />
<option name="WORKING_DIRECTORY" value="$PROJECT_DIR$" />
<option name="IS_MODULE_SDK" value="true" />
<option name="ADD_CONTENT_ROOTS" value="true" />
<option name="ADD_SOURCE_ROOTS" value="true" />
<EXTENSION ID="PythonCoverageRunConfigurationExtension" runner="coverage.py" />
<option name="SCRIPT_NAME" value="$PROJECT_DIR$/build.py" />
<option name="PARAMETERS" value="--clean-cache" />
<option name="SHOW_COMMAND_LINE" value="false" />
<option name="EMULATE_TERMINAL" value="false" />
<option name="MODULE_MODE" value="false" />
<option name="REDIRECT_INPUT" value="false" />
<option name="INPUT_FILE" value="" />
<method v="2" />
</configuration>
</component>
9 changes: 8 additions & 1 deletion Docker/Dockerfile-Build
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,14 @@ ENV RUN_IN_DOCKER=True

WORKDIR "$BASE_PATH"

# Install Software
RUN yum update -y \
&& yum install -y git python3 python3-pip
&& yum install -y git python3 python3-pip bash tzdata net-tools \
&& yum clean all

# Set the timezone
ENV TZ=Asia/Shanghai
RUN ln -snf /usr/share/zoneinfo/${TZ} /etc/localtime \
&& echo ${TZ} > /etc/timezone

ENTRYPOINT ["python3", "/usr/local/group-center/build.py", "--clean-cache"]
17 changes: 17 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,23 @@ FROM dragonwell-registry.cn-hangzhou.cr.aliyuncs.com/dragonwell/dragonwell:21-an
# MAINTAINER Haomin Kong
LABEL maintainer="Haomin Kong"

# https://mirrors.nwafu.edu.cn/help/local-repository/anolis/
#RUN sed -e 's|^mirrorlist=|#mirrorlist=|g' \
# -e 's|^#http://mirrors.openanolis.cn/|https://mirrors.nwafu.edu.cn/|g' \
# -i.bak \
# /etc/yum.repos.d/AnolisOS-AppStream.repo \
# /etc/yum.repos.d/AnolisOS-DDE.repo \
# /etc/yum.repos.d/AnolisOS-HighAvailability.repo \
# /etc/yum.repos.d/AnolisOS-PowerTools.repo \
# /etc/yum.repos.d/AnolisOS-BaseOS.repo \
# /etc/yum.repos.d/AnolisOS-Plus.repo \
# && sed -e 's|^mirrorlist=|#mirrorlist=|g' \
# -e 's|^#https://mirrors.openanolis.cn/|https://mirrors.nwafu.edu.cn/|g' \
# -i.bak \
# /etc/yum.repos.d/AnolisOS-Debuginfo.repo \
# /etc/yum.repos.d/AnolisOS-Source.repo \
# && yum makecache

# Install Software
RUN yum update -y \
&& yum install -y tzdata net-tools \
Expand Down
8 changes: 8 additions & 0 deletions act.docker.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import os

command = """
act push\
--secret-file .env.act
"""

os.system(command.strip())
14 changes: 8 additions & 6 deletions build.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,16 +70,12 @@ def main():
print("Build failed!!!")
exit(1)

if opt.clean_cache:
print("Cleaning Cache")
for cache_dir in cache_dir_list:
if os.path.exists(cache_dir):
shutil.rmtree(cache_dir)

jar_path = get_jar_path()
if jar_path == "":
print("Jar not found")
return
else:
print(f"Jar Path: {jar_path}")

# Remove Old
if os.path.exists(target_path):
Expand All @@ -88,6 +84,12 @@ def main():
# Copy to ./group-center-docker.jar
shutil.copy(jar_path, target_path)

if opt.clean_cache:
print("Cleaning Cache")
for cache_dir in cache_dir_list:
if os.path.exists(cache_dir):
shutil.rmtree(cache_dir)


if __name__ == '__main__':
main()
45 changes: 42 additions & 3 deletions build_with_docker.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,24 @@
import os
import subprocess


def run_command(command):
command_list = command.split(" ")
command_list = [
item.strip()
for item in command_list
if len(item.strip()) > 0
]
print("Run Command: ", command_list)
with subprocess.Popen(command_list, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, bufsize=1,
universal_newlines=True) as process:
for line in process.stdout:
print(line, end='') # 实时打印输出

exit_code = process.wait()

return exit_code == 0


image_name = "group-center-builder"
print("=" * 20)
Expand All @@ -8,17 +28,36 @@
# Build Image
print("=" * 20)
print("== Build Image")
os.system(f"docker build -t {image_name} -f Docker/Dockerfile-Build .")
if not run_command(f"docker build -t {image_name} -f ./Docker/Dockerfile-Build ."):
print("Build Image Failed")
exit(1)

# Check Build Scripts
print("=" * 20)
print("== Check Build Scripts")
if os.path.exists("./build.py"):
print("Build Scripts Exists")
else:
print("Build Scripts Not Exists")
exit(1)

# Run Containers
print("=" * 20)
print("== Run Containers")
os.system(f"docker run --rm -v .:/usr/local/group-center {image_name}")
# Get Work Dir
# work_dir = os.getcwd()
# py_file_path = os.path.abspath(__file__)
# work_dir = os.path.dirname(py_file_path)
# print("Work Dir: ", work_dir)
# if not run_command(f"docker run --rm -v {work_dir}:/usr/local/group-center {image_name}"):
if not run_command(f"docker run --rm -v .:/usr/local/group-center {image_name}"):
print("Run Containers Failed")
exit(1)

# Remove Image
print("=" * 20)
print("== Remove Image")
os.system(f"docker rmi {image_name}")
run_command(f"docker rmi {image_name}")

# Done
print("=" * 20)
Expand Down

0 comments on commit 146be03

Please sign in to comment.