Skip to content

Commit

Permalink
Merge branch 'master' of github.com:craigk5n/webcalendar
Browse files Browse the repository at this point in the history
  • Loading branch information
craigk5n committed May 24, 2022
2 parents 1d168d8 + c97cfc2 commit 6dbbcf6
Show file tree
Hide file tree
Showing 8 changed files with 186 additions and 18 deletions.
63 changes: 50 additions & 13 deletions README.md
Expand Up @@ -25,43 +25,78 @@ web server document root, you can access the script by going to:
(Obviously, put the correct server name in above.) The toplevel URL will
automatically redirect to the installation wizard.

## Setting Up a Docker Dev Environment (PHP 7.4)
## Running WebCalendar with Docker (PHP 8.1)
You can use a prebuilt WebCalendar image rather than building it yourself locally.
You will need to shell into the MariaDb container to grant access.
Because we also need a database, we use a local network with WebCalendar
and MariaDb running that is setup with the `docker-compose` command.

You can setup a docker environment with PHP 7.4 and MariaDb with a few
steps.
- Start the containers:
`docker-compose -f docker/docker-compose-php8.yml up`
- In order to grant the proper permissions inside of MariaDb, you
will need to run a few MySQL commands. First shell into the mariadb
container: `docker-compose -f docker/docker-compose-php8.yml exec db /bin/sh`
- Start up the db client: `/bin/mariadb -p` (the password will be
"Webcalendar.1" as specified in the `docker-compose-php8.yml' file. You
can change it to make your dev environment more secure (before you
build the containers in step above).
- Run the following db commands:
```
GRANT ALL PRIVILEGES ON *.* TO webcalendar_php8@localhost IDENTIFIED BY 'Webcalendar.1' WITH GRANT OPTION;
FLUSH PRIVILEGES;
QUIT
```
- Start up your web browser and go to:
[http://localhost:8080/](http://localhost:8080/).
- Follow the guided web-based setup and choose "mysqli" as the database
type.
Be sure to use the same MariaDb credentials specified above
(Password _WebCalendar.1_ and Database Name _webcalendar_php8_.)

## Setting Up a Docker Dev Environment (PHP 8.1)

- Build the docker container with `docker-compose build`
- Start the containers with `docker-compose up`
You can setup a docker environment with PHP 8.1 and MariaDb with a few
steps. This docker setup differs from the normal WebCalendar docker image
in that the local WebCalendar files are mounted into the container so
that changes to your local filesystem will also apply to the WebCalanedar
files in the container.

- Build the docker container with
`docker-compose -f docker/docker-compose-php8-dev.yml build`
- Start the containers with
`docker-compose -f docker/docker-compose-php8-dev.yml up`
- In order to grant the proper permissions inside of MariaDb, you
will need to run a few MySQL commands. First shell into the mariadb
container: `docker-compose exec db /bin/sh`
container: `docker-compose -f docker/docker-compose-php8-dev.yml exec db /bin/sh`
- Start up the db client: `/bin/mariadb -p` (the password will be
"Webcalendar.1" as specified in the `docker-compose.yml' file. You
"Webcalendar.1" as specified in the `docker-compose-php8-dev.yml' file. You
can change it to make your dev environment more secure (before you
build the containers in step above).
- Run the following db commands:
```
GRANT ALL PRIVILEGES ON *.* TO webcalendar@localhost IDENTIFIED BY 'Webcalendar.1' WITH GRANT OPTION;
GRANT ALL PRIVILEGES ON *.* TO webcalendar_php8@localhost IDENTIFIED BY 'Webcalendar.1' WITH GRANT OPTION;
FLUSH PRIVILEGES;
QUIT
```
- Start up your web browser and go to:
[http://localhost:8080/](http://localhost:8080/).
- Follow the guided web-based setup and choose "mysqli" as the database
type.
Be sure to use the same MariaDb credentials specified above
(Password _WebCalendar.1_ and Database Name _webcalendar_php8_.)

## Setting Up a Docker Dev Environment (PHP 8)
## Setting Up a Docker Dev Environment (PHP 7.4)

You can setup a docker environment with PHP 8 and MariaDb with a few
You can setup a docker environment with PHP 7.4 and MariaDb with a few
steps.

- Build the docker container with `docker-compose -f docker-compose-php8.yml build`
- Start the containers with `docker-compose -f docker-compose-php8.yml up`
- Build the docker container with `docker-compose -f docker-compose-php7.yml build`
- Start the containers with `docker-compose -f docker-compose-php7.yml up`
- In order to grant the proper permissions inside of MariaDb, you
will need to run a few MySQL commands. First shell into the mariadb
container: `docker-compose exec db /bin/sh`
- Start up the db client: `/bin/mariadb -p` (the password will be
"Webcalendar.1" as specified in the `docker-compose.yml' file. You
"Webcalendar.1" as specified in the `docker-compose-php7.yml' file. You
can change it to make your dev environment more secure (before you
build the containers in step above).
- Run the following db commands:
Expand All @@ -74,4 +109,6 @@ steps.
[http://localhost:8080/](http://localhost:8080/).
- Follow the guided web-based setup and choose "mysqli" as the database
type.
Be sure to use the same MariaDb credentials specified above
(Password _WebCalendar.1_ and Database Name _webcalendar_.)

File renamed without changes.
28 changes: 28 additions & 0 deletions docker/Dockerfile-php8
@@ -0,0 +1,28 @@
FROM php:8.0-apache
MAINTAINER craigk5n <craig@k5n.us>
LABEL vendor "k5n.us"

RUN docker-php-ext-install mysqli

# Copy only the files included in a release rather than all files

RUN mkdir -p /var/www/html/images \
/var/www/html/pub \
/var/www/html/tools \
/var/www/html/translations \
/var/www/html/install \
/var/www/html/themes
COPY images /var/www/html/images/
COPY includes /var/www/html/includes/
# In case there was a copy in the local dev setup, remove any
# existing settings.php.
RUN rm -f /var/www/html/includes/settings.php
RUN touch /var/www/html/includes/settings.php
run chmod 777 /var/www/html/includes/settings.php
COPY install /var/www/html/install/
COPY pub /var/www/html/pub/
COPY tools /var/www/html/tools/
COPY themes /var/www/html/themes/
COPY translations /var/www/html/translations/
COPY [a-z]*php favicon.ico GPL.html /var/www/html/
COPY docs/WebCalendar-SysAdmin.html docs/newwin.gif /var/www/html/docs/
File renamed without changes.
59 changes: 59 additions & 0 deletions docker/build_and_push.sh
@@ -0,0 +1,59 @@
#!/bin/bash
# Build and push the docker image for PHP8
# If this is the "master" git branch, push tag and push 'latest' (upon user confirmation)
# Regardless of branch, also tag and push version (e.g "1.9.1").
# If not on "master", also tag and push the branch (e.g. "dev") (upon user confirmation)
# Should we build and push for different version of PHP or the base image?
# We could create an image for Ubuntu/Apache and another for Alpine/Nginx.
#
# NOTE: For now, I will use this script to manage building, tagging and pushing images
# to dockerhub. But, I may want to use a Github action to do this for me. Not sure
# if it will be this script or something else...

# prompt user for confirmation
function yes_or_no {
while true; do
read -p "$* [y/n]: " yn
case $yn in
[Yy]*) return 0 ;;
[Nn]*) return 1 ;;
esac
done
}

# Which git branch are we on?
branch=$(git branch | sed -n -e 's/^\* \(.*\)/\1/p')
echo "Git branch is '$branch'."

# If we are on master branch, do we want to include the "latest" tag?
doTagBranch=0
tagBranch=""
if [ "$branch" == "master" ]; then
yes_or_no "Do you want to use the 'latest' tag?" && doTagBranch=1 && tagBranch="latest"
else
yes_or_no "Do you want to use the '$branch' tag?" && doTagBranch=1 && tagBranch=$branch
fi

# Get version number from includes/config.php
# Should be in the format like "1.9.1"
version=`grep 'PROGRAM_VERSION = ' ../includes/config.php | awk '{ print $3 }' | tr -d "'v;"`
echo "Version: $version"
#version=1.9.1

cd ..
tagBranchParam=""
if [ "$doTagBranch" == "1" ]; then
tagBranchParam="k5nus/webcalendar:$tagBranch"
echo "Tagging and pushing '$tagBranch' tag"
fi
echo docker build $tagBranchParam -t k5nus/webcalendar:$version -f docker/Dockerfile-php8 .
docker build $tagBranchParam -t k5nus/webcalendar:$version -f docker/Dockerfile-php8 .
if [ "$doTagBranch" == "1" ]; then
echo "Pushing $tagBranch"
docker push k5nus/webcalendar:$tagBranch
fi
echo "Pushing $version"
docker push k5nus/webcalendar:$version

exit 0

File renamed without changes.
48 changes: 48 additions & 0 deletions docker/docker-compose-php8-dev.yml
@@ -0,0 +1,48 @@
# The first time you run this, you will need to grant permission
# for the webcalendar user to access mariadb (after you have run
# docker-compose up). You only need to do this once.
#
# Start a shell on the mariadb container:
# docker-compose -f docker-compose-php8.yml exec db /bin/sh
# Start the mariadb client:
# /bin/mariadb -p
# (enter the MYSQL_ROOT_PASSWORD below)
# Execute the following three db commands:
# GRANT ALL PRIVILEGES ON *.* TO webcalendar@localhost IDENTIFIED BY 'Webcalendar.1' WITH GRANT OPTION;
# FLUSH PRIVILEGES;
# QUIT
#
# If you need shell access on the webserver container running WebCalendar, you can use
# the following command:
# docker-compose -f docker-compose-php8.yml exec webcalendar-php8 /bin/sh

version: '3.1'

services:

db:
image: mariadb
container_name: webcalendar-db
volumes:
- mysql-data:/var/lib/mysql
- /etc/localtime:/etc/localtime:ro
environment:
- MYSQL_ROOT_PASSWORD=Webcalendar.1
- MYSQL_PASSWORD=Webcalendar.1
- MYSQL_DATABASE=webcalendar_php8
- MYSQL_USER=webcalendar
restart: unless-stopped

webcalendar-php8:
build:
context: ../
dockerfile: docker/Dockerfile-php8-dev
depends_on:
- db
ports:
- 8080:80
volumes:
- .:/var/www/html/

volumes:
mysql-data:
6 changes: 1 addition & 5 deletions docker-compose-php8.yml → docker/docker-compose-php8.yml
Expand Up @@ -34,15 +34,11 @@ services:
restart: unless-stopped

webcalendar-php8:
build:
context: .
dockerfile: Dockerfile-php8
image: webcalendar
depends_on:
- db
ports:
- 8080:80
volumes:
- .:/var/www/html/

volumes:
mysql-data:

0 comments on commit 6dbbcf6

Please sign in to comment.