feat: 新增gitea action功能
This commit is contained in:
parent
f16457bef5
commit
c3fda4c8b5
|
|
@ -0,0 +1,39 @@
|
|||
name: Gitea Action for docker build
|
||||
run-name: ${{ gitea.actor }} is testing out Gitea Actions 🚀
|
||||
on:
|
||||
push:
|
||||
branches: [master]
|
||||
paths-ignore:
|
||||
- 'requirements.txt'
|
||||
- 'RuntimeDockerfile'
|
||||
- '.gitignore'
|
||||
- 'README.md'
|
||||
- '.gitea/workflows/**'
|
||||
|
||||
|
||||
jobs:
|
||||
build-app:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- run: echo "This job is now running on a ${{ runner.os }} server hosted by Gitea!"
|
||||
- name: Check out repository code
|
||||
uses: https://git.airpig.cn/actions/checkout@v4
|
||||
- name: Login to hub.airpig.cn
|
||||
uses: https://git.airpig.cn/actions/login-action@v3
|
||||
with:
|
||||
registry: hub.airpig.cn
|
||||
username: admin
|
||||
password: Chenweijia113!
|
||||
- run: |
|
||||
var=${{ gitea.repository }}
|
||||
repo=${var##*/}
|
||||
url="https://hub.airpig.cn/api/v2.0/projects/library/repositories/${repo}/artifacts?page=1&page_size=10&with_tag=true&with_label=false&with_scan_overview=false&with_signature=false&with_immutable_status=false&with_accessory=false"
|
||||
version=$(curl -X 'GET' $url \
|
||||
-H 'accept: application/json' \
|
||||
-H 'X-Accept-Vulnerabilities: application/vnd.security.vulnerability.report; version=1.1, application/vnd.scanner.adapter.vuln.report.harbor+json; version=1.0' \
|
||||
-u 'admin:Chenweijia!' | jq '.[0].tags[0].name')
|
||||
new_version=$(echo $version | sed 's/\"//g' | awk -F. '{$NF = $NF + 1;} 1' OFS=.)
|
||||
docker build -t hub.airpig.cn/library/$repo:$new_version .
|
||||
docker push hub.airpig.cn/library/$repo:$new_version
|
||||
docker rmi hub.airpig.cn/library/$repo:$new_version
|
||||
- run: echo "This job's status is ${{ job.status }}."
|
||||
|
|
@ -0,0 +1,36 @@
|
|||
name: Gitea Action for docker build runtime
|
||||
run-name: ${{ gitea.actor }} is testing out Gitea Actions 🚀
|
||||
on:
|
||||
push:
|
||||
branches: [master]
|
||||
paths:
|
||||
- 'requirements.txt'
|
||||
- 'RuntimeDockerfile'
|
||||
|
||||
jobs:
|
||||
build-runtime:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- run: echo "This job is now running on a ${{ runner.os }} server hosted by Gitea!"
|
||||
- name: Check out repository code
|
||||
uses: https://git.airpig.cn/actions/checkout@v4
|
||||
- name: Login to hub.airpig.cn
|
||||
uses: https://git.airpig.cn/actions/login-action@v3
|
||||
with:
|
||||
registry: hub.airpig.cn
|
||||
username: admin
|
||||
password: Chenweijia113!
|
||||
- run: |
|
||||
var=${{ gitea.repository }}
|
||||
repo=${var##*/}"-runtime"
|
||||
echo $repo
|
||||
url="https://hub.airpig.cn/api/v2.0/projects/library/repositories/${repo}/artifacts?page=1&page_size=10&with_tag=true&with_label=false&with_scan_overview=false&with_signature=false&with_immutable_status=false&with_accessory=false"
|
||||
version=$(curl -X 'GET' $url \
|
||||
-H 'accept: application/json' \
|
||||
-H 'X-Accept-Vulnerabilities: application/vnd.security.vulnerability.report; version=1.1, application/vnd.scanner.adapter.vuln.report.harbor+json; version=1.0' \
|
||||
-u 'admin:Chenweijia!' | jq '.[0].tags[0].name')
|
||||
new_version=$(echo $version | sed 's/\"//g' | awk -F. '{$NF = $NF + 1;} 1' OFS=.)
|
||||
docker build -t hub.airpig.cn/library/$repo:$new_version -f RuntimeDockerfile .
|
||||
docker push hub.airpig.cn/library/$repo:$new_version
|
||||
docker rmi hub.airpig.cn/library/$repo:$new_version
|
||||
- run: echo "This job's status is ${{ job.status }}."
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
variables:
|
||||
PROJECT_NAME: fastapi_app_template
|
||||
DOCKER_IMAGE_DOMAIN: 192.168.2.237:8088
|
||||
DOCKER_IMAGE_DOMAIN: hub.airpig.cn
|
||||
LATEST_VERSION: latest
|
||||
K8S_NS: default
|
||||
DEPLOYMENT_NAME: fastapi-app-template
|
||||
|
|
|
|||
29
Dockerfile
29
Dockerfile
|
|
@ -1,29 +1,10 @@
|
|||
# 安装依赖阶段
|
||||
FROM python:3.8.6-slim as build
|
||||
FROM busybox
|
||||
|
||||
RUN mkdir /install
|
||||
RUN mkdir -p /data /app
|
||||
|
||||
WORKDIR /install
|
||||
WORKDIR /data
|
||||
|
||||
COPY requirements.txt .
|
||||
COPY . /data
|
||||
|
||||
RUN sed -i s@/deb.debian.org/@/mirrors.aliyun.com/@g /etc/apt/sources.list
|
||||
ENTRYPOINT [ "/bin/cp", "-r", "/data/*", "/app"]
|
||||
|
||||
RUN apt-get update \
|
||||
&& apt-get install gcc -y \
|
||||
&& apt-get clean
|
||||
|
||||
RUN pip install -r requirements.txt -i https://mirrors.aliyun.com/pypi/simple/ --prefix=/install
|
||||
|
||||
# 应用启动
|
||||
FROM python:3.8.6-slim
|
||||
|
||||
COPY --from=build /install /usr/local
|
||||
|
||||
COPY . /app
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
ENV FAST_API_ENV=dev
|
||||
|
||||
CMD ["/usr/local/bin/uvicorn", "main:fast_api_app", "--reload", "--host", "0.0.0.0", "--port", "21021"]
|
||||
|
|
|
|||
|
|
@ -0,0 +1,31 @@
|
|||
# 安装依赖阶段
|
||||
FROM python:3.11-slim as build
|
||||
|
||||
RUN mkdir /install
|
||||
|
||||
WORKDIR /install
|
||||
|
||||
COPY requirements.txt .
|
||||
|
||||
RUN sed -i s@/deb.debian.org/@/mirrors.aliyun.com/@g /etc/apt/sources.list
|
||||
|
||||
RUN apt-get update \
|
||||
&& apt-get install gcc -y \
|
||||
&& apt-get clean
|
||||
|
||||
RUN pip install -r requirements.txt -i https://mirrors.aliyun.com/pypi/simple/ --prefix=/install
|
||||
|
||||
# 应用启动
|
||||
FROM python:3.11-slim
|
||||
|
||||
COPY --from=build /install /usr/local
|
||||
|
||||
RUN mkdir -p /app
|
||||
|
||||
# COPY . /app
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
ENV FAST_API_ENV=prod
|
||||
|
||||
CMD ["/usr/local/bin/uvicorn", "main:fast_api_app", "--reload", "--host", "0.0.0.0", "--port", "80"]
|
||||
Loading…
Reference in New Issue