Skip to content

Commit

Permalink
Merge pull request #1 from inovector/develop
Browse files Browse the repository at this point in the history
Develop Dockerfile fix permissions. Readme complete
  • Loading branch information
lao9s authored Mar 7, 2023
2 parents 6cf5cd4 + 4d3c8f8 commit a944a6a
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 7 deletions.
4 changes: 4 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ APP_KEY=
APP_DEBUG=true
APP_URL=http://localhost

APP_PORT=80
UID=1000
GID=1000

LOG_CHANNEL=stack
LOG_DEPRECATIONS_CHANNEL=null
LOG_LEVEL=debug
Expand Down
30 changes: 30 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,10 @@ You can create a docker image that will have all server configurations and start

Download the latest version of Mixpost Lite from [here](https://github.com/inovector/MixpostApp/releases), copy .env.example to `.env`, and fill in all the necessary values:
```env
APP_PORT=80
UID=1000 // Your local user id, you can find it this way: id -u
GID=1000 // Your local group id, you can find it this way: id -g
DB_HOST=127.0.0.1
DB_DATABASE=laravel
DB_USERNAME=root
Expand All @@ -205,6 +209,22 @@ REDIS_PASSWORD=null
docker-compose up -d
```

IMORTANT NOTE!

If you are logged in as the **root** user on your machine, you must make sure that the user in the container is the owner of the files:

```bash
docker-compose exec -it app bash

# If the command above cannot log you into the container:
# `docker ps`, and identify the mixpost container name
# docker exec -it {mixpost_container_name} bash

chown -R mixpost:mixpost /var/www/html

exit
```

### 2. Make the binary `mixpost` file executable:
```bash
chmod +x ./docker/mixpost
Expand All @@ -219,8 +239,18 @@ This binary will help you to avoid the long command `docker-compose exec -it -u
./docker/mixpost php artisan mixpost:setup-gitignore
./docker/mixpost php artisan queue:batches-table
./docker/mixpost php artisan storage:link
./docker/mixpost php artisan queue:restart
```

If you are reading for production, you cache the config and routes:

```bash
./docker/mixpost php artisan config:cache
./docker/mixpost php artisan route:cache
```

Do not forget to restart the queue after caching: `./docker/mixpost php artisan queue:restart`

### 4. And then you can migrate all tables:

```bash
Expand Down
19 changes: 14 additions & 5 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,21 @@ RUN php -r "unlink('composer-setup.php');"
RUN delgroup dialout

# Add user for mixpost application
RUN groupadd -g ${GID} --system mixpost
RUN useradd -g mixpost --system -N -ms /bin/bash -u ${UID} mixpost

# Tell php8.2-fpm to use mixpost user instead of www-data user
RUN sed -i "s/user = www-data/user = mixpost/g" /etc/php/8.2/fpm/pool.d/www.conf
RUN sed -i "s/group = www-data/group = mixpost/g" /etc/php/8.2/fpm/pool.d/www.conf

RUN if [ "$GID" -ne 0 ] && [ "$UID" -ne 0 ]; then \
groupadd -g ${GID} --system mixpost && \
useradd -g mixpost --system -N -ms /bin/bash -u ${UID} mixpost && \
sed -i "s/user = www-data/user = mixpost/g" /etc/php/8.2/fpm/pool.d/www.conf && \
sed -i "s/group = www-data/group = mixpost/g" /etc/php/8.2/fpm/pool.d/www.conf; \
else \
groupadd -g 1000 --system mixpost && \
useradd -g mixpost --system -N -ms /bin/bash -u 1000 mixpost && \
sed -i "s/user = www-data/user = mixpost/g" /etc/php/8.2/fpm/pool.d/www.conf && \
sed -i "s/group = www-data/group = mixpost/g" /etc/php/8.2/fpm/pool.d/www.conf && \
mkdir -p /home/mixpost/.composer && \
chown -R mixpost:mixpost /home/mixpost;\
fi

EXPOSE 80

Expand Down
2 changes: 1 addition & 1 deletion docker/mixpost
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env sh
#!/usr/bin/env bash

# Check if the operating system supports it
UNAMEOUT="$(uname -s)"
Expand Down
2 changes: 1 addition & 1 deletion docker/supervisord.conf
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ process_name=%(program_name)s_%(process_num)02d
command=php /var/www/html/artisan horizon
autostart=true
autorestart=true
user=www-data
user=mixpost
redirect_stderr=true
stdout_logfile=/var/www/html/storage/logs/horizon.log
stopwaitsecs=3600

0 comments on commit a944a6a

Please sign in to comment.