Skip to content

Commit e8393d4

Browse files
authored
Merge upstream (#2)
* Refactors project (read below) - Moves Dockerfile, docker-compose.yaml, & .dockerignore to project root - Fixes bugs in docker-entrypoint - Makes k8s work in minikube in prod mode * Fix image job * disable running image * Improves docker entry point, disables image action
1 parent 8059ac5 commit e8393d4

File tree

18 files changed

+336
-239
lines changed

18 files changed

+336
-239
lines changed

.docker/.dockerignore

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

.docker/README.md

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

3-
It's expected that you will use your own Dockerfile for production. All docker-related configurations are stored
4-
in this directory. See [docker-compose.yml](docker-compose.yml) and [Dockerfile](Dockerfile).
3+
It's expected that you will use your own Dockerfile for production.
54

65
## NGINX
76

.docker/php/docker-entrypoint.sh

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -32,21 +32,18 @@ if [ "$1" = 'php-fpm' ] || [ "$1" = 'php' ] || [ "$1" = 'bin/cakephp' ]; then
3232
composer require mixerapi/mixerapi
3333
bin/cake plugin load MixerApi
3434
bin/cake mixerapi install --auto Y
35-
36-
if [ "$APP_ENV" = 'dev' ]; then
37-
chown -R cakephp:www-data .
38-
fi
39-
40-
setfacl -R -m u:www-data:rwX -m u:"$(whoami)":rwX logs
41-
setfacl -dR -m u:www-data:rwX -m u:"$(whoami)":rwX tmp
4235
fi
4336

44-
if [ "$APP_ENV" = 'prod' ]; then
45-
composer install --prefer-dist --no-interaction --no-dev
46-
else
37+
if [ "$APP_ENV" != 'prod' ]; then
4738
composer install --prefer-dist --no-interaction
4839
fi
4940

41+
mkdir -p logs tmp
42+
setfacl -R -m u:www-data:rwX -m u:"$(whoami)":rwX logs
43+
setfacl -R -m u:www-data:rwX -m u:"$(whoami)":rwX tmp
44+
setfacl -R -m g:nginx:rwX /srv/app
45+
chown -R cakephp:www-data .
46+
chmod 774 -R .
5047
fi
5148

5249
exec docker-php-entrypoint "$@"

.dockerignore

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
app/vendor/
2+
app/logs/
3+
app/tmp/
4+
app/config/.env
5+
app/config/app_local.php
6+
app/.git
7+
app/.cache
8+
app/.editorconfig
9+
app/.gitattributes
10+
app/.gitignore
11+
app/.gitkeep

.github/workflows/build.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@ jobs:
1414
cp .docker/php.env.development .docker/php.env
1515
cp .docker/mysql.env.development .docker/mysql.env
1616
- name: Pull images
17-
run: docker-compose -f .docker/docker-compose.yml pull
17+
run: docker-compose pull
1818
- name: Build
19-
run: docker-compose -f .docker/docker-compose.yml build --build-arg UID=$(id -u) --build-arg ENV=dev
19+
run: docker-compose build --build-arg UID=$(id -u) --build-arg ENV=dev
2020
- name: Start
21-
run: docker-compose -f .docker/docker-compose.yml up -d
21+
run: docker-compose up -d
2222
- name: Wait for services
2323
run: sleep 5
2424
- name: HTTP Check
25-
run: curl -v -o /dev/null http://localhost:8080
25+
run: curl -v -o /dev/null http://localhost:8080
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
name: Image
2+
3+
on:
4+
create:
5+
tags:
6+
- "v*.*.*"
7+
8+
jobs:
9+
build:
10+
11+
runs-on: ubuntu-latest
12+
13+
steps:
14+
- name: Checkout
15+
uses: actions/checkout@v2
16+
17+
- name: Prepare
18+
id: prep
19+
run: |
20+
DOCKER_IMAGE=cnizzardini/cakephp-docker
21+
VERSION=edge
22+
if [[ $GITHUB_REF == refs/tags/* ]]; then
23+
VERSION=${GITHUB_REF#refs/tags/v}
24+
fi
25+
TAGS="${DOCKER_IMAGE}:${VERSION}"
26+
if [[ $VERSION =~ ^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ ]]; then
27+
TAGS="$TAGS,${DOCKER_IMAGE}:4.2-latest"
28+
fi
29+
echo ::set-output name=tags::${TAGS}
30+
-
31+
name: Login to DockerHub
32+
uses: docker/login-action@v1
33+
with:
34+
username: ${{ secrets.DOCKERHUB_USERNAME }}
35+
password: ${{ secrets.DOCKERHUB_PASSWORD }}
36+
-
37+
name: Build and push
38+
id: docker_build
39+
uses: docker/build-push-action@v2
40+
with:
41+
context: ./
42+
push: ${{ github.event_name != 'pull_request' }}
43+
tags: ${{ steps.prep.outputs.tags }}
44+
build-args: ENV=prod
45+
-
46+
name: Image digest
47+
run: echo ${{ steps.docker_build.outputs.digest }}

.kube/README.md

Lines changed: 36 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,52 @@
33
This is provided as a starter/example setup. You can run kubernetes locally with an orchestration tool such as
44
[minikube](https://minikube.sigs.k8s.io/docs/) and [kubectl](https://kubernetes.io/docs/tasks/tools/).
55

6+
Starting minikube:
7+
68
```console
79
minikube start
10+
```
11+
12+
Apply configs:
13+
14+
```console
815
kubectl apply -f .kube/namespace.yaml
916
kubectl apply -f .kube/mysql-secret.yaml
1017
kubectl apply -f .kube/php-secret.yaml
11-
kubectl apply -f .
12-
minikube service nginx-service -n cakephp-docker
18+
kubectl apply -f .kube/.
19+
```
20+
21+
Minikube dashboard:
22+
23+
```console
24+
minikube dashboard --url
25+
```
26+
27+
Create services:
28+
29+
```console
30+
minikube service nginx -n cakephp-docker
31+
minikube service mysql -n cakephp-docker
1332
```
1433

15-
## Using local image
34+
Browse to the given nginx url:
35+
36+
```console
37+
minikube service list
38+
```
1639

17-
You may find it helpful to work with a local image instead of continually deploying to a container registry.
40+
MySQL:
1841

1942
```console
20-
eval (minikube docker-env)
21-
docker run -d -p 5005:5005 --restart=always --name registry registry:2
22-
docker build . -f .docker/Dockerfile -t localhost:5005/cakephp-docker:4.2-latest
43+
mysql -u cakephp -h 192.168.49.2 -p --port 32089
2344
```
2445

25-
In [php.yaml](php.yaml) change the image to `localhost:5005/cakephp-docker:4.2-latest`.
46+
> Password is `cakephp`
47+
48+
Docker build / push commands:
49+
50+
```console
51+
docker build . -t cnizzardini/cakephp-docker:latest
52+
docker push cnizzardini/cakephp-docker:latest
53+
```
2654

27-
> Source: https://shashanksrivastava.medium.com/how-to-set-up-minikube-to-use-your-local-docker-registry-10a5b564883

.kube/mysql-secret.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ metadata:
55
namespace: cakephp-docker
66
type: Opaque
77
data:
8+
# root
89
mysql-root-password: cm9vdA==
10+
# cakephp
911
mysql-user: Y2FrZXBocA==
1012
mysql-password: Y2FrZXBocA==

.kube/mysql.yaml

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
1+
apiVersion: v1
2+
kind: ConfigMap
3+
metadata:
4+
name: mysql-config
5+
namespace: cakephp-docker
6+
labels:
7+
app: mysql
8+
data:
9+
default_auth: |
10+
[mysqld]
11+
default_authentication_plugin= mysql_native_password
12+
sql-mode=""
13+
14+
---
115
apiVersion: apps/v1
216
kind: Deployment
317
metadata:
@@ -38,7 +52,14 @@ spec:
3852
secretKeyRef:
3953
name: mysql-secret
4054
key: mysql-password
55+
volumeMounts:
56+
- name: mysql-config-volume
57+
mountPath: /etc/mysql/conf.d/default_auth.cnf
58+
subPath: default_auth
4159
volumes:
60+
- name: mysql-config-volume
61+
configMap:
62+
name: mysql-config
4263
- name: mysql
4364
persistentVolumeClaim:
4465
claimName: mysql-pv-claim
@@ -60,12 +81,14 @@ spec:
6081
apiVersion: v1
6182
kind: Service
6283
metadata:
63-
name: mysql-service
84+
name: mysql
6485
namespace: cakephp-docker
6586
spec:
87+
type: NodePort
6688
selector:
6789
app: mysql
6890
ports:
6991
- protocol: TCP
7092
port: 3306
7193
targetPort: 3306
94+
nodePort: 32089

.kube/nginx.yaml

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

0 commit comments

Comments
 (0)