Skip to content

Commit

Permalink
feat: Integrate build process into Dockerfile and enable multi-platfo…
Browse files Browse the repository at this point in the history
…rm builds in GitHub Actions
  • Loading branch information
HalcyonAzure committed Oct 27, 2023
1 parent 18305c8 commit 8a57929
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 44 deletions.
30 changes: 11 additions & 19 deletions .github/workflows/dev-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
30 changes: 11 additions & 19 deletions .github/workflows/update-docker.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
21 changes: 20 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -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
# 安装相关拓展
Expand Down Expand Up @@ -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 /
Expand Down
11 changes: 6 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 # 可作为"数据库名称/路径"
Expand Down
1 change: 1 addition & 0 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ services:
networks:
- lsky-net

# 注:arm64的无法使用该镜像,请选择sqlite或自建数据库
mysql-lsky:
image: mysql:5.7.22
restart: unless-stopped
Expand Down

0 comments on commit 8a57929

Please sign in to comment.