Skip to content

Commit 2c9d6e7

Browse files
authored
ci: #144 build and push to docker hub
1 parent 7044846 commit 2c9d6e7

File tree

6 files changed

+142
-42
lines changed

6 files changed

+142
-42
lines changed

.github/workflows/laravel-11.yml

+45-17
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
name: Laravel 11
22
on:
33
push:
4+
tags:
5+
- v*
46
paths-ignore:
57
- "**.md"
68
branches:
@@ -16,34 +18,60 @@ jobs:
1618
container:
1719
image: laravelfans/laravel:11-dev
1820
steps:
19-
- name: Checkout
20-
uses: actions/checkout@v2
21-
22-
- name: GitHub Environment Variables Action
23-
uses: FranzDiebold/[email protected]
24-
25-
- name: Prepare
21+
-
22+
name: Checkout
23+
uses: actions/checkout@v4
24+
-
25+
name: Prepare
2626
run: |
2727
composer install
2828
npm install
2929
npm run build
30-
31-
- name: PHPUnit
30+
-
31+
name: PHPUnit
3232
env:
3333
XDEBUG_MODE: coverage
34-
run: |
35-
php artisan test
36-
37-
- name: Upload test results to Codecov
34+
run: php artisan test
35+
-
36+
name: Upload test results to Codecov
3837
if: ${{ !cancelled() }}
3938
uses: codecov/test-results-action@v1
4039
with:
4140
token: ${{ secrets.CODECOV_TOKEN }}
42-
43-
- name: Upload coverage to Codecov
41+
-
42+
name: Upload coverage to Codecov
4443
uses: codecov/codecov-action@v4
4544
env:
4645
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
47-
48-
- name: Lint PHP
46+
-
47+
name: Lint PHP
4948
run: php artisan lint:code
49+
-
50+
uses: hadolint/[email protected]
51+
52+
buildx:
53+
if: startsWith(github.ref, 'refs/tags/v')
54+
runs-on: ubuntu-latest
55+
steps:
56+
-
57+
name: Set up QEMU
58+
uses: docker/setup-qemu-action@v3
59+
-
60+
name: Set up Docker Buildx
61+
uses: docker/setup-buildx-action@v3
62+
-
63+
name: Login to Docker Hub
64+
uses: docker/login-action@v3
65+
with:
66+
username: ${{ secrets.DOCKERHUB_USERNAME }}
67+
password: ${{ secrets.DOCKERHUB_TOKEN }}
68+
-
69+
name: Get Version from Tag
70+
id: tagver
71+
uses: ChrSchu90/[email protected]
72+
-
73+
name: Build and push
74+
uses: docker/build-push-action@v6
75+
with:
76+
push: true
77+
tags: wifidog/wifidog-auth-laravel:latest,wifidog/wifidog-auth-laravel:${{ steps.tagver.outputs.version }}

Dockerfile

+7-12
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,16 @@ WORKDIR /var/www/laravel
55
RUN curl -o /usr/local/bin/composer https://getcomposer.org/download/latest-stable/composer.phar \
66
&& chmod +x /usr/local/bin/composer
77

8+
SHELL ["/bin/bash", "-o", "pipefail", "-c"]
89
# hadolint ignore=DL3008
9-
RUN apt-get update \
10+
RUN curl -sL https://deb.nodesource.com/setup_22.x | bash - \
1011
&& apt-get install --no-install-recommends -y \
1112
cron \
1213
icu-devtools \
1314
jq \
1415
libfreetype6-dev libicu-dev libjpeg62-turbo-dev libpng-dev libpq-dev \
1516
libsasl2-dev libssl-dev libwebp-dev libxpm-dev libzip-dev libzstd-dev \
17+
nodejs \
1618
unzip \
1719
zlib1g-dev \
1820
&& apt-get clean \
@@ -30,24 +32,17 @@ RUN cp /usr/local/etc/php/php.ini-production /usr/local/etc/php/php.ini \
3032
COPY composer.json composer.lock ./
3133
RUN composer install --no-autoloader --no-scripts --no-dev
3234

35+
COPY package*.json ./
36+
RUN npm install
37+
3338
COPY docker/ /
3439
RUN a2enmod rewrite headers \
3540
&& a2ensite laravel \
3641
&& a2dissite 000-default \
3742
&& chmod +x /usr/local/bin/docker-laravel-entrypoint
3843

39-
RUN curl -sL https://deb.nodesource.com/setup_22.x | bash - \
40-
&& apt-get install -y \
41-
nodejs \
42-
&& apt-get clean \
43-
&& apt-get autoclean \
44-
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
45-
46-
COPY package.json package-lock.json ./
47-
RUN npm install
48-
4944
COPY . /var/www/laravel
5045
RUN composer install --optimize-autoloader --no-dev \
51-
&& npm run build
46+
&& npm run build
5247

5348
CMD ["docker-laravel-entrypoint"]

composer.json

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
},
1313
"require-dev": {
1414
"fakerphp/faker": "^1.23",
15+
"laravel-fans/docker": "^1.0",
1516
"laravel-fans/lint": "^1.1",
1617
"laravel/breeze": "^2.2",
1718
"laravel/pail": "^1.1",

composer.lock

+53-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docker/etc/apache2/sites-available/laravel.conf

+3-2
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,11 @@
1111
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
1212
RewriteRule ^(.*)$ https://%1$1 [L,R=permanent]
1313

14-
# optional: redirect http to https
14+
# optional: redirect domain url http to https
15+
RewriteCond %{HTTP_HOST} ^.*\.[a-z].*
1516
RewriteCond %{HTTP:X-Forwarded-Proto} =http
1617
RewriteRule .* https://%{HTTP:Host}%{REQUEST_URI} [L,R=permanent]
17-
18+
1819
# RewriteCond %{HTTP:Authorization} .
1920
# RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
2021

docker/usr/local/bin/docker-laravel-entrypoint

+33-10
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,38 @@
11
#!/usr/bin/env bash
22

33
set -e
4+
cd /var/www/laravel
45

56
role=${CONTAINER_ROLE:-app}
6-
env=${APP_ENV:-production}
7+
if [[ -z "$APP_ENV" ]]; then
8+
export APP_ENV=local
9+
echo -e "\e[33mENV undefined: APP_ENV,\e[0m use default $APP_ENV"
10+
fi
711

8-
cd /var/www/laravel
12+
if [[ -z "$DB_CONNECTION" ]]; then
13+
export DB_CONNECTION=sqlite
14+
echo -e "\e[33mENV undefined: DB_CONNECTION,\e[0m use default $DB_CONNECTION"
15+
fi
16+
17+
if [[ -z "$APP_KEY" ]]; then
18+
msg="ENV undefined: APP_KEY"
19+
if [[ "$APP_ENV" = "local" ]]; then
20+
APP_KEY=$(php artisan key:generate --show)
21+
export APP_KEY
22+
echo -e "\e[33m${msg},\e[0m generated $APP_KEY"
23+
else
24+
echo -e "\e[31m${msg}\e[0m"
25+
exit 1
26+
fi
27+
fi
28+
29+
if [[ "$APP_ENV" = "local" ]]; then
30+
cp /usr/local/etc/php/php.ini-development /usr/local/etc/php/php.ini
31+
else
32+
echo "Caching configuration..."
33+
php artisan config:cache
34+
php artisan route:cache
35+
fi
936

1037
chown www-data:www-data bootstrap/cache
1138
chown -R www-data:www-data storage/
@@ -16,26 +43,22 @@ if [[ "$DB_CONNECTION" = "sqlite" ]]; then
1643
fi
1744
php artisan migrate --force
1845

19-
if [[ "$env" != "local" ]]; then
20-
echo "Caching configuration..."
21-
php artisan config:cache
22-
php artisan route:cache
23-
fi
24-
2546
if [[ "$role" = "app" ]]; then
2647

2748
exec apache2-foreground
2849

2950
elif [[ "$role" = "scheduler" ]]; then
3051

31-
echo "start cron"
52+
echo -e "\e[33mSUGGESTION: use K8s Job instead of docker cron\e[0m"
53+
echo -e "\e[33m https://kubernetes.io/docs/concepts/workloads/controllers/job/\e[0m"
54+
echo "Running the cron..."
3255
crontab /var/spool/cron/crontabs/root
3356
cron -f
3457

3558
elif [[ "$role" = "queue" ]]; then
3659

3760
echo "Running the queue..."
38-
php artisan queue:work --queue={default} --verbose --tries=3 --timeout=90
61+
php artisan queue:work --queue="{default}" --verbose --tries=3 --timeout=90
3962

4063
else
4164
echo "Could not match the container role: $role"

0 commit comments

Comments
 (0)