From 8a5792903ab15c3b53e3569be02bffae5c4e996b Mon Sep 17 00:00:00 2001 From: HalcyonAzure Date: Fri, 27 Oct 2023 12:57:27 +0800 Subject: [PATCH] feat: Integrate build process into Dockerfile and enable multi-platform builds in GitHub Actions --- .github/workflows/dev-test.yaml | 30 ++++++++++------------------ .github/workflows/update-docker.yaml | 30 ++++++++++------------------ Dockerfile | 21 ++++++++++++++++++- README.md | 11 +++++----- docker-compose.yaml | 1 + 5 files changed, 49 insertions(+), 44 deletions(-) diff --git a/.github/workflows/dev-test.yaml b/.github/workflows/dev-test.yaml index 40089608..ea2a62ce 100644 --- a/.github/workflows/dev-test.yaml +++ b/.github/workflows/dev-test.yaml @@ -16,23 +16,11 @@ jobs: - name: Checkout uses: actions/checkout@v2 - - name: Download and Unzip Upstream Source Code - run: | - curl -OL https://github.com/lsky-org/lsky-pro/archive/refs/heads/master.zip - unzip *.zip - mv ./lsky-pro-master/* ./ - mv ./lsky-pro-master/.env.example ./ - rm -rf master.zip lsky-pro-master + - name: Set up QEMU + uses: docker/setup-qemu-action@v1 - - uses: shivammathur/setup-php@15c43e89cdef867065b0213be354c2841860869e - with: - php-version: '8.1' - - - name: Copy .env - run: php -r "file_exists('.env') || copy('.env.example', '.env');" - - - name: Install Dependencies - run: composer install + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v1 - name: Login to DockerHub uses: docker/login-action@v1 @@ -41,6 +29,10 @@ jobs: password: ${{ secrets.DOCKERHUB_TOKEN }} - name: Build and push - run: | - docker build -t halcyonazure/lsky-pro-docker:dev . - docker push halcyonazure/lsky-pro-docker:dev + uses: docker/build-push-action@v2 + with: + context: . + file: ./Dockerfile + platforms: linux/amd64,linux/arm64 + push: true + tags: halcyonazure/lsky-pro-docker:dev diff --git a/.github/workflows/update-docker.yaml b/.github/workflows/update-docker.yaml index 3d4864aa..aac41795 100644 --- a/.github/workflows/update-docker.yaml +++ b/.github/workflows/update-docker.yaml @@ -14,23 +14,11 @@ jobs: - name: Checkout uses: actions/checkout@v2 - - name: Download and Unzip Upstream Source Code - run: | - curl -OL https://github.com/lsky-org/lsky-pro/archive/refs/heads/master.zip - unzip *.zip - mv ./lsky-pro-master/* ./ - mv ./lsky-pro-master/.env.example ./ - rm -rf master.zip lsky-pro-master + - name: Set up QEMU + uses: docker/setup-qemu-action@v1 - - uses: shivammathur/setup-php@15c43e89cdef867065b0213be354c2841860869e - with: - php-version: '8.1' - - - name: Copy .env - run: php -r "file_exists('.env') || copy('.env.example', '.env');" - - - name: Install Dependencies - run: composer install + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v1 - name: Login to DockerHub uses: docker/login-action@v1 @@ -39,6 +27,10 @@ jobs: password: ${{ secrets.DOCKERHUB_TOKEN }} - name: Build and push - run: | - docker build -t halcyonazure/lsky-pro-docker:latest . - docker push halcyonazure/lsky-pro-docker:latest + uses: docker/build-push-action@v2 + with: + context: . + file: ./Dockerfile + platforms: linux/amd64,linux/arm64 + push: true + tags: halcyonazure/lsky-pro-docker:dev diff --git a/Dockerfile b/Dockerfile index e91af1a6..efef5720 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,23 @@ +FROM php:8.1 AS build +WORKDIR /build + +# 安装必要的依赖 +RUN apt-get update && \ + apt-get install -y curl unzip && \ + curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer && \ + apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* + +RUN curl -OL https://github.com/lsky-org/lsky-pro/archive/refs/heads/master.zip \ + && unzip *.zip \ + && mv ./lsky-pro-master/* ./ \ + && mv ./lsky-pro-master/.env.example ./ \ + && rm -rf master.zip lsky-pro-master + +RUN php -r "file_exists('.env') || copy('.env.example', '.env');" \ + && composer install + FROM php:8.1-apache + # 如果构建速度慢可以换源 # RUN sed -i -E "s@http://.*.debian.org@http://mirrors.cloud.tencent.com@g" /etc/apt/sources.list # 安装相关拓展 @@ -33,7 +52,7 @@ RUN apt-get update && \ chown -R www-data:root /var/www; \ chmod -R g=u /var/www -COPY ./ /var/www/lsky/ +COPY --from=build /build /var/www/lsky/ COPY ./000-default.conf.template /etc/apache2/sites-enabled/ COPY ./ports.conf.template /etc/apache2/ COPY entrypoint.sh / diff --git a/README.md b/README.md index 55c96b56..7217d48f 100644 --- a/README.md +++ b/README.md @@ -47,12 +47,13 @@ services: environment: - WEB_PORT=8089 volumes: - - /data/lsky/web:/var/www/html/ + - $PWD/web:/var/www/html/ ports: - - "8089:8089" + - "9080:8089" networks: - lsky-net + # 注:arm64的无法使用该镜像,请选择sqlite或自建数据库 mysql-lsky: image: mysql:5.7.22 restart: unless-stopped @@ -63,9 +64,9 @@ services: # 修改加密规则 command: --default-authentication-plugin=mysql_native_password volumes: - - /data/lsky/mysql/data:/var/lib/mysql - - /data/lsky/mysql/conf:/etc/mysql - - /data/lsky/mysql/log:/var/log/mysql + - $PWD/mysql/data:/var/lib/mysql + - $PWD/mysql/conf:/etc/mysql + - $PWD/mysql/log:/var/log/mysql environment: MYSQL_ROOT_PASSWORD: lAsWjb6rzSzENUYg # 数据库root用户密码,自行修改 MYSQL_DATABASE: lsky-data # 可作为"数据库名称/路径" diff --git a/docker-compose.yaml b/docker-compose.yaml index ef61afd2..db098027 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -14,6 +14,7 @@ services: networks: - lsky-net + # 注:arm64的无法使用该镜像,请选择sqlite或自建数据库 mysql-lsky: image: mysql:5.7.22 restart: unless-stopped