Skip to content

Commit b3f1431

Browse files
committed
php mysql example
1 parent 54b8c33 commit b3f1431

17 files changed

Lines changed: 314 additions & 6 deletions

File tree

examples/kaniko-minikube/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,4 +76,4 @@ Furthermore a bi-directional sync was started between the local folder `/go-work
7676

7777
You can start the server now with `go run main.go` in the open terminal. Now navigate in your browser to `localhost:8080` and you should see the output 'Hello World!'.
7878

79-
Change something in `main.go` and re-run `go run main.go`. Now just refresh your browser and you should see the changes immediately.
79+
Change something in `main.go` locally and re-run `go run main.go`. Now just refresh your browser and you should see the changes immediately.

examples/kaniko/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,4 +108,4 @@ Furthermore a bi-directional sync was started between the local folder `/go-work
108108

109109
You can start the server now with `go run main.go` in the open terminal. Now navigate in your browser to `localhost:8080` and you should see the output 'Hello World!'.
110110

111-
Change something in `main.go` and re-run `go run main.go`. Now just refresh your browser and you should see the changes immediately.
111+
Change something in `main.go` locally and re-run `go run main.go`. Now just refresh your browser and you should see the changes immediately.

examples/minikube/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ Furthermore a bi-directional sync was started between the local folder `/go-work
7272

7373
You can start the server now with `npm start` in the open terminal. Now navigate in your browser to `localhost:3000` and you should see the output 'Hello World!'.
7474

75-
Change something in `index.js` and you should see something like this:
75+
Change something in `index.js` locally and you should see something like this:
7676

7777
```
7878
[nodemon] 1.18.4

examples/offline-development/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ Furthermore a bi-directional sync was started between the local folder `/go-work
7272

7373
You can start the server now with `npm start` in the open terminal. Now navigate in your browser to `localhost:3000` and you should see the output 'Hello World!'.
7474

75-
Change something in `index.js` and you should see something like this:
75+
Change something in `index.js` locally and you should see something like this:
7676

7777
```
7878
[nodemon] 1.18.4
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
logs/
2+
overwrite.yaml
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
version: v1alpha1
2+
cluster:
3+
cloudProvider: devspace-cloud
4+
devSpace:
5+
deployments:
6+
- helm:
7+
chartPath: ./chart
8+
name: devspace-default
9+
ports:
10+
- labelSelector:
11+
release: devspace-default
12+
portMappings:
13+
- localPort: 3000
14+
remotePort: 80
15+
sync:
16+
- containerPath: /var/www/html
17+
labelSelector:
18+
release: devspace-default
19+
localSubPath: ./
20+
uploadExcludePaths:
21+
- Dockerfile
22+
- .devspace/
23+
- chart/
24+
images:
25+
default:
26+
name: fabian1991/devspace
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Dockerfile
2+
.devspace/
3+
chart/
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
FROM php:7.1-apache-stretch
2+
3+
ENV PORT 80
4+
EXPOSE 80
5+
6+
RUN docker-php-ext-install mysqli && docker-php-ext-enable mysqli
7+
8+
COPY . /var/www/html
9+
10+
RUN usermod -u 1000 www-data; \
11+
a2enmod rewrite; \
12+
chown -R www-data:www-data /var/www/html
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
# Php Mysql example
2+
3+
This example shows you how to develop a small php web application that uses mysql as a database.
4+
5+
# Step 0: Prerequisites
6+
7+
In order to use this example, make sure you have docker installed and a docker registry where you can push to (hub.docker.com, gcr.io etc.). Make sure you are logged in to the registry via `docker login`.
8+
9+
Exchange the image name in `.devspace/config.yaml` under `images.default.name` with the image name you want to use. Do **not** add a tag to this image name, because this will be done at runtime automatically.
10+
11+
## Optional: Use self hosted cluster (minikube, GKS etc.) instead of devspace-cloud
12+
13+
By default, this example will deploy to the devspace-cloud, a free managed kubernetes cluster. If you want to use your own cluster instead of the devspace-cloud as deployment target, make sure `kubectl` is configured correctly to access resources on the cluster. Then just erase the `cluster` section in the `.devspace/config.yaml` and devspace will use your current `kubectl` context as deployment target.
14+
15+
# Step 1: Start the devspace
16+
17+
To deploy the application to the devspace-cloud simply run `devspace up`. The output of the command should look similar to this:
18+
19+
```
20+
INFO] Building image 'fabian1991/devspace' with engine 'docker'
21+
[DONE] √ Authentication successful (hub.docker.com)
22+
Sending build context to Docker daemon 7.168kB
23+
Step 1/6 : FROM php:7.1-apache-stretch
24+
---> 93e6fb4b13e1
25+
Step 2/6 : ENV PORT 80
26+
---> Using cache
27+
---> 788a58416826
28+
Step 3/6 : EXPOSE 80
29+
---> Using cache
30+
---> b01729d4ade9
31+
Step 4/6 : RUN docker-php-ext-install mysqli && docker-php-ext-enable mysqli
32+
---> Running in 1dbd0ba85b71
33+
Configuring for:
34+
PHP Api Version: 20160303
35+
Zend Module Api No: 20160303
36+
Zend Extension Api No: 320160303
37+
[...]
38+
warning: mysqli (mysqli.so) is already loaded!
39+
40+
---> d4942a93c915
41+
Step 5/6 : COPY . /var/www/html
42+
---> dbb818ed4318
43+
Step 6/6 : RUN usermod -u 1000 www-data; a2enmod rewrite; chown -R www-data:www-data /var/www/html
44+
---> Running in 1c90fe728588
45+
Enabling module rewrite.
46+
To activate the new configuration, you need to run:
47+
service apache2 restart
48+
---> 99eb800d832d
49+
Successfully built 99eb800d832d
50+
Successfully tagged fabian1991/devspace:HKgauKH
51+
The push refers to repository [docker.io/fabian1991/devspace]
52+
aff6c1858e21: Pushed
53+
d1bd441544af: Pushed
54+
60f45585ecc1: Pushed
55+
bc0dfe6b56ad: Layer already exists
56+
f82ba3fb9cea: Layer already exists
57+
c6a1866bd1a0: Layer already exists
58+
c9b57a1cfeb1: Layer already exists
59+
1e97bcb161b3: Layer already exists
60+
369e6fd590f3: Layer already exists
61+
1805144065e1: Layer already exists
62+
b6311cdc5fb6: Layer already exists
63+
e30181a94bbf: Layer already exists
64+
481da43a1302: Layer already exists
65+
a4ace4ed0385: Layer already exists
66+
fd29e0f8792a: Layer already exists
67+
687dad24bb36: Layer already exists
68+
237472299760: Layer already exists
69+
HKgauKH: digest: sha256:6530af9474b2e9b8b1bfc6986288b4dcd34fca5365ffee60a2f6f63de4327b80 size: 3868
70+
[INFO] Image pushed to registry (hub.docker.com)
71+
[DONE] √ Done building and pushing image 'fabian1991/devspace'
72+
[INFO] Deploying devspace-default with helm
73+
[DONE] √ Deployed helm chart (Release revision: 2)
74+
[DONE] √ Successfully deployed devspace-default
75+
[DONE] √ Port forwarding started on 3000:80
76+
[DONE] √ Sync started on /go-workspace/src/github.com/covexo/devspace/examples/php-mysql-example <-> /var/www/html (Pod: test/devspace-default-55c89799d5-x8rvl)
77+
root@devspace-default-55c89799d5-x8rvl:/var/www/html#
78+
```
79+
80+
The command built your Dockerfile and pushed it to the target docker registry. Afterwards, it created a new kubernetes namespace for you in the devspace-cloud and deployed the `kube/deployment.yaml` to that namespace. It also created a new kubectl context for you. If you want to access kubernetes resources via kubectl in the devspace-cloud you can simply change your kubectl context via `devspace up --switch-context`. Now you can check the running pods via `kubectl get po`.
81+
82+
Furthermore a bi-directional sync was started between the local folder `/go-workspace/src/github.com/covexo/devspace/examples/php-mysql-example` and `/var/www/html` within the docker container. Whenever you change a file in either of those two folders the change will be synchronized. In addition the container port 80 was forwarded to your local port 3000.
83+
84+
# Step 2: Start developing
85+
86+
Navigate in your browser to `localhost:3000` and you should a signin page. If you submit the form, the application will insert a new entry in the `Users` table of the mysql database. Try changing the `index.php` locally and reload the webpage and you should be able to see the changes immediately.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
name: my-app
2+
version: v0.0.1
3+
description: A Kubernetes-Native Application

0 commit comments

Comments
 (0)