Skip to content

Commit

Permalink
prepare to use in prod (#633)
Browse files Browse the repository at this point in the history
  • Loading branch information
talyguryn authored Sep 4, 2021
1 parent 15804de commit 6e46e8b
Show file tree
Hide file tree
Showing 6 changed files with 92 additions and 50 deletions.
5 changes: 5 additions & 0 deletions .env.sample
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Port for application
APP_PORT=8885

# MySQL root's password
MYSQL_PASSWORD=root
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@
.DS_Store
sftp-config.json
.cache
dump/
.env
48 changes: 22 additions & 26 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,54 +3,50 @@ version: '2'
services:
mysql:
image: 'mysql:5.7'
ports:
- '3306:3306'
restart: on-failure
volumes:
- './dump/mysql:/dump'
- 'mysql-data:/var/lib/mysql'
environment:
MYSQL_ROOT_PASSWORD: root
MYSQL_ROOT_PASSWORD: ${MYSQL_PASSWORD}

memcached:
image: 'memcached:alpine'
ports:
- '11211:11211'
restart: on-failure

redis:
image: 'redis:alpine'
ports:
- '6379:6379'
restart: on-failure
command: ["redis-server", "--save 900 1", "--save 300 10", "--save 60 10000"]
volumes:
- './dump/redis:/data'

php:
build: docker/php
build:
dockerfile: 'docker/php/Dockerfile'
context: '.'
restart: on-failure
links:
- mysql
- memcached
- redis
volumes:
- './www:/var/www/codex'
- 'pma-data:/usr/share'

nginx:
image: 'nginx:latest'
restart: on-failure
ports:
- '8080:8080'
- '127.0.0.1:${APP_PORT}:8080'
links:
- php
volumes:
- './docker/nginx-codex.conf:/etc/nginx/conf.d/codex.conf'
volumes_from:
- php

phpmyadmin:
image: phpmyadmin/phpmyadmin
links:
- mysql
ports:
- '8081:80'
environment:
PMA_ARBITRARY: 1
MYSQL_USER: root
MYSQL_PASSWORD: root
MYSQL_ROOT_PASSWORD: root
volumes:
- mysqldata:/var/lib/mysql
- './www:/var/www/codex'
- 'pma-data:/usr/share'

volumes:
mysqldata:
mysql-data:
pma-data:

25 changes: 24 additions & 1 deletion docker/nginx-codex.conf
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,30 @@ server {
error_log /var/log/nginx/codex_error.log;
access_log /var/log/nginx/codex_access.log;

client_max_body_size 10M;
client_max_body_size 10M;

# phpMyAdmin section
location /phpmyadmin {
# Path to parent folder for phpmyadmin's sources
root /usr/share;
index index.php index.html index.html;

# Resolve static files
location ~* ^/phpmyadmin/(.+\.(jpg|jpeg|gif|css|png|js|ico|html|xml|txt))$ {
try_files $uri =404;
}

# Process php files
location ~ ^/phpmyadmin/(.+\.php)$ {
fastcgi_pass php:9000;
include fastcgi_params;

fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

try_files $uri =404;
}
}

# PATH TO DIR WITH STATIC FILES
location ~ ^/(public|upload)/ {
Expand Down
39 changes: 22 additions & 17 deletions docker/php/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,20 +1,33 @@
FROM php:7.2-fpm

MAINTAINER CodeX <github.com/codex-team>

RUN apt-get update && apt-get install -y --no-install-recommends \
git \
wget \
unzip \
libz-dev \
libjpeg-dev libpng-dev libfreetype6-dev \
libssl-dev libpcre3 libpcre3-dev \
libmagickwand-dev imagemagick

# Set the locale
RUN apt-get -qq update && apt-get -qqy install locales
RUN sed -i -e 's/# ru_RU ISO-8859-5/ru_RU ISO-8859-5/' /etc/locale.gen && \
sed -i -e 's/# ru_RU.UTF-8 UTF-8/ru_RU.UTF-8 UTF-8/' /etc/locale.gen && \
sed -i -e 's/# en_US.UTF-8 UTF-8/en_US.UTF-8 UTF-8/' /etc/locale.gen && \
locale-gen && \
update-locale LANG=ru_RU.UTF-8 && \
echo "LANGUAGE=ru_RU.UTF-8" >> /etc/default/locale && \
echo "LC_ALL=ru_RU.UTF-8" >> /etc/default/locale

# Set timezone
RUN rm /etc/localtime
RUN ln -s /usr/share/zoneinfo/Europe/Moscow /etc/localtime
RUN "date"

# Install Composer
RUN curl -sS https://getcomposer.org/installer | php
RUN mv composer.phar /usr/local/bin/composer


# Install memcache extension
RUN set -x \
&& cd /tmp \
Expand Down Expand Up @@ -47,19 +60,11 @@ RUN docker-php-ext-install \
gettext \
gd

# Set the locale
RUN apt-get -qq update && apt-get -qqy install locales
RUN sed -i -e 's/# ru_RU ISO-8859-5/ru_RU ISO-8859-5/' /etc/locale.gen && \
sed -i -e 's/# ru_RU.UTF-8 UTF-8/ru_RU.UTF-8 UTF-8/' /etc/locale.gen && \
sed -i -e 's/# en_US.UTF-8 UTF-8/en_US.UTF-8 UTF-8/' /etc/locale.gen && \
locale-gen && \
update-locale LANG=ru_RU.UTF-8 && \
echo "LANGUAGE=ru_RU.UTF-8" >> /etc/default/locale && \
echo "LC_ALL=ru_RU.UTF-8" >> /etc/default/locale

# Set timezone
RUN rm /etc/localtime
RUN ln -s /usr/share/zoneinfo/Europe/Moscow /etc/localtime
RUN "date"
# Install phpMyAdmin
RUN wget https://files.phpmyadmin.net/phpMyAdmin/5.0.2/phpMyAdmin-5.0.2-all-languages.zip
RUN unzip phpMyAdmin-5.0.2-all-languages.zip
RUN mv phpMyAdmin-5.0.2-all-languages /usr/share/phpmyadmin
RUN cp /usr/share/phpmyadmin/config.sample.inc.php /usr/share/phpmyadmin/config.inc.php && \
sed -i "s/\['host'\] = 'localhost'/\['host'\] = 'mysql'/" /usr/share/phpmyadmin/config.inc.php

WORKDIR /var/www/codex
23 changes: 17 additions & 6 deletions docs/development.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,16 @@ cd codex

## 2. In the repository's root build and run Docker containers.

Copy `.env` file for docker containers and update field inside.

```shell
cp .env.sample .env
```

Then build and run containers.

```shell
docker-compose build
docker-compose up
docker-compose up -d
```

## 3. Run composer in PHP container and install all dependencies.
Expand Down Expand Up @@ -69,13 +76,15 @@ chmod 777 cache logs

## 6. Create a MySQL database.

Open phpMyAdmin in [localhost:8081](http://localhost:8081).
Open phpMyAdmin in [localhost:8885/phpmyadmin/](http://localhost:8885/phpmyadmin/).

Check port which defined in [.env](../.env) file.

Use these credentials to sign in.

- server: `mysql`
- login: `root`
- password: `root`
- password: defined in [.env](../.env) file

Create a new database with the name, say, `codexdb` with `utf8_general_ci` collation.

Expand Down Expand Up @@ -112,6 +121,8 @@ On 10th line in `host` param you should set Memcached container's hostname `memc

Set `mysql` as a hostname of MySQL container. Type database name, username and password.

Password defined in [.env](../.env) file.

```
'hostname' => 'mysql',
'database' => 'codexdb',
Expand All @@ -134,7 +145,7 @@ Set any `Application name` and enter a correct link (with protocol) to your site
In the field `Authorization callback URL` you should type a link to your local site with `/auth/github` uri:

```
http://localhost:8080/auth/github
http://localhost:8885/auth/github
```

![](assets/create-a-new-github-app.png)
Expand All @@ -149,7 +160,7 @@ After registering an application you will be redirected to app's settings page.
...
```

## 8. Open [http://localhost:8080](http://localhost:8080). You'll see a CodeX site's homepage. Try to auth.
## 8. Open [http://localhost:8885](http://localhost:8885). You'll see a CodeX site's homepage. Try to auth.

![](assets/local-codex-site.png)

Expand Down

0 comments on commit 6e46e8b

Please sign in to comment.