Skip to content

Commit 407b385

Browse files
committed
Create deployment action
1 parent 16ce3a3 commit 407b385

File tree

11 files changed

+164
-128
lines changed

11 files changed

+164
-128
lines changed

.docker/nginx/Dockerfile

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,4 @@
11
FROM nginx:latest
22
LABEL authors="[email protected]"
33

4-
COPY ./ssl /etc/nginx/ssl
5-
WORKDIR /etc/nginx
6-
#
7-
# This requires to have these commands run inside the nginx-folder to create the CA certificates
8-
#
9-
# > openssl genrsa -out ssl/ca.key 4096; \
10-
# > openssl req -x509 -new -nodes -subj "/C=ug/O=php/CN=development certificates;" -key ssl/ca.key -sha512 -days 3650 -out ssl/ca.crt;
11-
#
12-
RUN apt-get update && apt-get install -y openssl && \
13-
openssl genrsa -out "ssl/php.ug.lo.key" 2048 && \
14-
openssl req -new -subj "/C=ug/O=php/CN=php.ug.lo.lo" -key "ssl/php.ug.lo.key" -out "ssl/php.ug.lo.csr" && \
15-
openssl x509 -req -in "ssl/php.ug.lo.csr" -extfile "ssl/php.ug.lo.ext" -CA "ssl/ca.crt" -CAkey "ssl/ca.key" -CAcreateserial -out "ssl/php.ug.lo.crt" -days=365 -sha512 && \
16-
rm "ssl/php.ug.lo.csr" "ssl/ca.key" && \
17-
apt-get remove -y openssl
18-
19-
WORKDIR /var/www/php.ug/public
20-
21-
22-
4+
COPY build/ /var/www/html

.docker/nginx/default.conf

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,15 @@
11
server {
22

33
# Set the port to listen on and the server name
4-
listen 80;
5-
listen [::]:80;
6-
server_name php.ug php.ug.lo;
4+
listen 80 default_server;
5+
listen [::]:80 default_server;
6+
server_name _;
77

8-
return 301 https://$server_name$request_uri;
9-
}
10-
11-
server {
12-
listen [::]:443 ssl;
13-
listen 443 ssl;
14-
server_name php.ug php.ug.lo;
15-
# Set the document root of the project
168
root /var/www/php.ug/public;
179

1810
# Set the directory index files
1911
index index.html index.php;
2012

21-
ssl_certificate /etc/nginx/ssl/php.ug.lo.crt;
22-
ssl_certificate_key /etc/nginx/ssl/php.ug.lo.key;
23-
24-
ssl_protocols TLSv1 TLSv1.1 TLSv1.2 TLSv1.3;
25-
ssl_ciphers HIGH:!aNULL:!MD5;
26-
2713
# Specify the default character set
2814
charset utf-8;
2915

@@ -58,7 +44,7 @@ server {
5844

5945
sendfile off;
6046

61-
client_max_body_size 100m;
47+
client_max_body_size 20m;
6248

6349
# Specify what happens what .ht files are requested
6450
location ~ /\.ht {

.docker/nginx/ssl/ca.crt

Lines changed: 0 additions & 31 deletions
This file was deleted.

.docker/nginx/ssl/ca.key

Lines changed: 0 additions & 51 deletions
This file was deleted.

.docker/nginx/ssl/php.ug.lo.ext

Lines changed: 0 additions & 8 deletions
This file was deleted.

.docker/php/Dockerfile

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM php:8.4-fpm
1+
FROM php:8.4-fpm AS base
22
LABEL authors="[email protected]"
33

44
COPY --from=ghcr.io/php/pie:bin /pie /usr/bin/pie
@@ -7,3 +7,9 @@ RUN bash -c "/tmp/php-build.sh"
77
RUN bash -c "/tmp/php-install-composer.sh"
88
RUN bash -c "/tmp/php-install-phive.sh"
99
WORKDIR "/var/www/php.ug"
10+
11+
FROM base AS prod
12+
13+
RUN rm /usr/bin/pie usr/local/bin/composer /usr/local/bin/phive
14+
COPY build /var/www/php.ug
15+

.gitattributes

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
tests export-ignore
2+
.justfiles export-ignore
3+
.docker export-ignore
4+
.editorconfig export-ignore
5+
.gitattributes export-ignore
6+
.gitignore export-ignore
7+
Justfile export-ignore

.github/workflows/build.yml

Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
name: Build and deploy
2+
3+
on:
4+
push:
5+
release:
6+
types: [published]
7+
jobs:
8+
buildBackend:
9+
name: Build backend
10+
runs-on: ubuntu-latest
11+
environment: deploy_on_release
12+
steps:
13+
- name: "Checkout"
14+
uses: "actions/checkout@v4"
15+
with:
16+
ref: ${{ github.head_ref || github.ref_name }}
17+
fetch-depth: 100
18+
- name: "install PHP and composer"
19+
uses: "shivammathur/setup-php@v2"
20+
with:
21+
coverage: "none"
22+
extensions: "intl, zip, xml, apcu"
23+
ini-values: "memory_limit=-1"
24+
php-version: "8.4"
25+
tools: "composer"
26+
- name: "Export Git repo"
27+
run: |
28+
# Remove a possibly existing extraction folder
29+
rm -rf extract
30+
# No that we are sure it's not there, create an empty extraction folder
31+
mkdir extract
32+
# Create an archive from the repository based on the given tag
33+
# and extract that into the just created extraction folder.
34+
git archive --prefix="./" --format=tar ${{ github.head_ref || github.ref_name }} .| tar xv -C extract/
35+
# Do some shell magic to replace occurrences of the string '%release-tag%'
36+
# with the current release tag in all files within the extraction folder
37+
find extract/ -type f -exec sed -i "s/%release-tag%/:${{ github.head_ref || github.ref_name }}/" {} \;
38+
# Move into the extraction folder
39+
cd extract
40+
# Call composer install to add all your dependencies, prefer the
41+
# distribution ones and create an authoritative and optimized autoloader
42+
composer install --no-dev --prefer-dist -a
43+
# Go back one level
44+
rm -rf frontend compose*
45+
cd ..
46+
# Create the actual archive that you want to deploy
47+
tar cvzf backend-${{ github.head_ref || github.ref_name }}.tgz -C extract/ .
48+
# clean up the extraction folder
49+
rm -rf extract
50+
- uses: actions/upload-artifact@v4
51+
with:
52+
name: backend
53+
path: backend-${{ github.head_ref || github.ref_name }}.tgz
54+
retention-days: 1
55+
56+
buildFrontend:
57+
name: "Build Frontend"
58+
runs-on: ubuntu-latest
59+
environment: deploy_on_release
60+
steps:
61+
- name: "Checkout"
62+
uses: "actions/checkout@v4"
63+
with:
64+
ref: ${{ github.head_ref || github.ref_name }}
65+
fetch-depth: 100
66+
- name: "install Node"
67+
uses: actions/setup-node@v4
68+
with:
69+
node-version: '20.x'
70+
- name: "Export Git repo"
71+
run: |
72+
# Remove a possibly existing extraction folder
73+
rm -rf extract
74+
# No that we are sure it's not there, create an empty extraction folder
75+
mkdir extract
76+
# Create an archive from the repository based on the given tag
77+
# and extract that into the just created extraction folder.
78+
git archive --prefix="./" --format=tar ${{ github.head_ref || github.ref_name }} .| tar xv -C extract/
79+
# Do some shell magic to replace occurrences of the string '%release-tag%'
80+
# with the current release tag in all files within the extraction folder
81+
find extract/ -type f -exec sed -i "s/%release-tag%/:${{ github.head_ref || github.ref_name }}/" {} \;
82+
# Move into the extraction folder
83+
cd extract/frontend
84+
# Call Node.js install to add all your dependencies, prefer the
85+
npm ci
86+
npm run build
87+
# Go back one level
88+
cd ..
89+
rm -rf config src templates vendor frontend compose*
90+
cd ..
91+
# Create the actual archive that you want to deploy
92+
tar cvzf frontend-${{ github.head_ref || github.ref_name }}.tgz -C extract/ .
93+
# clean up the extraction folder
94+
rm -rf extract
95+
- uses: actions/upload-artifact@v4
96+
with:
97+
name: frontend
98+
path: frontend-${{ github.head_ref || github.ref_name }}.tgz
99+
retention-days: 1
100+
101+
buildFrontendContainer:
102+
needs: buildFrontend
103+
name: "Build Frontend-COntainer"
104+
105+
runs-on: ubuntu-latest
106+
steps:
107+
- name: 'Checkout GitHub Action'
108+
uses: actions/checkout@main
109+
110+
- name: 'Login to GitHub Container Registry'
111+
uses: docker/login-action@v1
112+
with:
113+
registry: ghcr.io
114+
username: ${{github.actor}}
115+
password: ${{secrets.GITHUB_TOKEN}}
116+
117+
- uses: actions/download-artifact@v4
118+
with:
119+
name: frontend
120+
- name: Display structure of downloaded files
121+
run: ls -R
122+
- name: 'Build Inventory Image'
123+
run: |
124+
ls -al
125+
tar xvzf frontend-${{ github.head_ref || github.ref_name }}.tgz -C .docker/nginx/build
126+
pwd
127+
docker compose build nginx
128+
docker images ls
129+
# docker push ghcr.io/<your-GitHub-username>/store:latest

.justfiles/build.Justfile

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Start the local instance
2+
[group("Build")]
3+
extract-php tag:
4+
docker compose exec php bash -c <<- DELIMITER
5+
rm -rf extract \
6+
mkdir extract \
7+
git archive --prefix=\"./\" --format=tar {{tag}} .| tar xv -C extract/ \
8+
find extract/ -type f -exec sed -i \"s/%release-tag%/:{{tag}}/\" {} \; \
9+
cd extract \
10+
composer install --no-dev --prefer-dist -a \
11+
cd .. \
12+
tar cvzf archive.tgz -C extract/ . \
13+
rm -rf extract \
14+
DELIMITER

Justfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
export COMPOSE_BAKE := "true"
44

5+
import '.justfiles/build.Justfile'
56
import '.justfiles/docker.Justfile'
67
import '.justfiles/init.Justfile'
78

0 commit comments

Comments
 (0)