Skip to content

Commit

Permalink
updates the container to separate grav cms solution from the skeleton…
Browse files Browse the repository at this point in the history
… installation
  • Loading branch information
SonOfLope committed Nov 19, 2023
1 parent c5db891 commit 2e828db
Show file tree
Hide file tree
Showing 6 changed files with 143 additions and 71 deletions.
113 changes: 57 additions & 56 deletions .github/workflows/deployment.yaml
Original file line number Diff line number Diff line change
@@ -1,67 +1,68 @@
name: Docker
# disabled until further notice. we are currently pushing images manually
# name: Docker

on:
push:
tags:
- 'v*.*.*-*'
# on:
# push:
# tags:
# - 'v*.*.*-*'

jobs:
build-on-release:
runs-on: ubuntu-latest
steps:
- name: Check Out Repo
uses: actions/checkout@v4
# jobs:
# build-on-release:
# runs-on: ubuntu-latest
# steps:
# - name: Check Out Repo
# uses: actions/checkout@v4

- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v3
# - name: Set up Docker Buildx
# id: buildx
# uses: docker/setup-buildx-action@v3

- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_HUB_USERNAME }}
password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }}
# - name: Login to Docker Hub
# uses: docker/login-action@v3
# with:
# username: ${{ secrets.DOCKER_HUB_USERNAME }}
# password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }}

- name: Cache Docker layers
uses: actions/cache@v3
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-${{ github.sha }}
restore-keys: ${{ runner.os }}-buildx
# - name: Cache Docker layers
# uses: actions/cache@v3
# with:
# path: /tmp/.buildx-cache
# key: ${{ runner.os }}-buildx-${{ github.sha }}
# restore-keys: ${{ runner.os }}-buildx

- name: Get Tag Version
id: tag
run: |
FULL_VERSION=${GITHUB_REF#refs/tags/}
echo "Full version: $FULL_VERSION"
# - name: Get Tag Version
# id: tag
# run: |
# FULL_VERSION=${GITHUB_REF#refs/tags/}
# echo "Full version: $FULL_VERSION"

VERSION=${FULL_VERSION#v}
VERSION=${VERSION%-grav*}
echo "Version to be used: $VERSION"
echo "VERSION=$VERSION" >> $GITHUB_ENV
# VERSION=${FULL_VERSION#v}
# VERSION=${VERSION%-grav*}
# echo "Version to be used: $VERSION"
# echo "VERSION=$VERSION" >> $GITHUB_ENV

# Extract project name after '-'
SUFFIX=${FULL_VERSION#*-}
echo "Suffix: $SUFFIX"
echo "PROJECT_DIR=$SUFFIX" >> $GITHUB_ENV
# # Extract project name after '-'
# SUFFIX=${FULL_VERSION#*-}
# echo "Suffix: $SUFFIX"
# echo "PROJECT_DIR=$SUFFIX" >> $GITHUB_ENV

- name: Build and push
id: docker_build
uses: docker/build-push-action@v5
with:
context: ./${{ env.PROJECT_DIR }}
file: ./${{ env.PROJECT_DIR }}/Dockerfile
push: true
tags: |
${{ secrets.DOCKER_HUB_NAMESPACE }}/${{ env.PROJECT_DIR }}:${{ env.VERSION }}
${{ secrets.DOCKER_HUB_NAMESPACE }}/${{ env.PROJECT_DIR }}:latest
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,mode=max,dest=/tmp/.buildx-cache-new
# - name: Build and push
# id: docker_build
# uses: docker/build-push-action@v5
# with:
# context: ./${{ env.PROJECT_DIR }}
# file: ./${{ env.PROJECT_DIR }}/Dockerfile
# push: true
# tags: |
# ${{ secrets.DOCKER_HUB_NAMESPACE }}/${{ env.PROJECT_DIR }}:${{ env.VERSION }}
# ${{ secrets.DOCKER_HUB_NAMESPACE }}/${{ env.PROJECT_DIR }}:latest
# cache-from: type=local,src=/tmp/.buildx-cache
# cache-to: type=local,mode=max,dest=/tmp/.buildx-cache-new

- name: Refresh Cache
run: |
rm -rf /tmp/.buildx-cache
mv /tmp/.buildx-cache-new /tmp/.buildx-cache
# - name: Refresh Cache
# run: |
# rm -rf /tmp/.buildx-cache
# mv /tmp/.buildx-cache-new /tmp/.buildx-cache

- name: Image digest
run: echo ${{ steps.docker_build.outputs.digest }}
# - name: Image digest
# run: echo ${{ steps.docker_build.outputs.digest }}
17 changes: 7 additions & 10 deletions grav/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -59,18 +59,12 @@ USER www-data
# Define Grav specific version of Grav or use latest stable
ARG GRAV_VERSION=latest

ARG GRAV_SKELETON_URL=https://github.com/getgrav/grav-skeleton-gateway-site/releases/download/1.0.1/grav-skeleton-gateway-site+admin-1.0.1.zip

# Install grav
WORKDIR /var/www
RUN wget -O grav-admin.zip $GRAV_SKELETON_URL && \
unzip grav-admin.zip -d grav-admin && \
mv -T /var/www/grav-admin /var/www/html && \
rm grav-admin.zip

# Install Git Sync plugin
RUN cd /var/www/html && \
RUN git clone https://github.com/getgrav/grav.git /var/www/html/grav && \
cd /var/www/html/grav && \
bin/gpm install git-sync

RUN chown -R www-data:www-data /var/www/html

# Create cron job for Grav maintenance scripts
RUN (crontab -l; echo "* * * * * cd /var/www/html;/usr/local/bin/php bin/grav scheduler 1>> /dev/null 2>&1") | crontab -
Expand All @@ -84,6 +78,9 @@ USER root
# provide container inside image for data persistence
VOLUME ["/var/www/html"]

# Set ServerName to localhost to avoid FQDN warning
RUN echo "ServerName localhost" >> /etc/apache2/apache2.conf

# ENTRYPOINT ["/entrypoint.sh"]
# CMD ["apache2-foreground"]
CMD ["sh", "-c", "cron && apache2-foreground"]
21 changes: 19 additions & 2 deletions grav/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,26 @@
Ce répertoire contient un Dockerfile personnalisé conçu pour déployer une instance Grav CMS avec un thème squelette spécifié. C'est la solution standardisée que nous offrons aux autres clubs étudiants souhaitant héberger leur site web chez nous.

## Utilisation
Pour utiliser cette configuration, suivez les étapes ci-dessous :

Pour construire l'image Docker Grav avec une URL de squelette spécifique:
### Construire les Images Docker

1. Construire l'Image du Conteneur d'Initilisation (grav-init): Ce conteneur est responsable de la préparation du squelette du thème Grav choisi.

```bash
docker build --build-arg GRAV_SKELETON_URL=<VOTRE_URL> -t <NOM_DE_VOTRE_IMAGE> .
cd ./init-grav
docker build -t grav-init .
```

2. Construire l'Image Principale de Grav CMS: Cette image contient le CMS Grav. À partir du dossier grav, exécuter :
```bash
docker build --build-arg GRAV_SKELETON_URL=<VOTRE_URL> -t grav .
```

### Docker Compose

Utilisez docker-compose pour lancer les conteneurs :
```bash
docker-compose up --build
```

13 changes: 10 additions & 3 deletions grav/docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -1,16 +1,23 @@
version: '3.8'

services:
grav-init:
depends_on:
- grav
build:
context: ./init-grav
dockerfile: Dockerfile
container_name: grav_init
volumes:
- grav_data:/var/www/html

grav:
build: .
container_name: grav_cms
ports:
- "8080:80"
volumes:
- grav_data:/var/www/html
environment:
- GRAV_VERSION=latest
- GRAV_SKELETON_URL=https://github.com/getgrav/grav-skeleton-gateway-site/releases/download/1.0.1/grav-skeleton-gateway-site+admin-1.0.1.zip

volumes:
grav_data:
19 changes: 19 additions & 0 deletions grav/init-grav/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Use a base image that has necessary tools (e.g., wget, rsync)
FROM alpine:latest

# Install necessary packages
RUN apk add --no-cache wget unzip rsync

# Define Grav theme/skeleton URL
ARG GRAV_SKELETON_URL=https://github.com/getgrav/grav-skeleton-gateway-site/releases/download/1.0.1/grav-skeleton-gateway-site+admin-1.0.1.zip

# Download and unzip the theme
WORKDIR /initial-content
RUN wget "$GRAV_SKELETON_URL" -O theme.zip \
&& unzip theme.zip \
&& rm theme.zip

# Add and prepare the script to copy content if necessary
COPY copy-theme.sh /copy-theme.sh
RUN chmod +x /copy-theme.sh
ENTRYPOINT ["/copy-theme.sh"]
31 changes: 31 additions & 0 deletions grav/init-grav/copy-theme.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/bin/sh
# copy-theme.sh

THEMES_DIR=/var/www/html/user/themes

# Function to check if Grav is ready
is_grav_ready() {
[ -d /var/www/html/grav ]
}

# Wait for Grav to be ready
while ! is_grav_ready; do
echo "Waiting for Grav to be ready..."
sleep 10
done

echo "Grav is ready. Copying theme..."

# Create the themes directory if it does not exist
[ ! -d "$THEMES_DIR" ] && mkdir -p "$THEMES_DIR"

# Use rsync to copy the initial content
if [ -z "$(ls -A "$THEMES_DIR")" ]; then
rsync -av /initial-content/ /var/www/html/
# Change ownership of the copied content to www-data
chown -R 33:33 /var/www/html
else
echo "Themes directory is not empty. Skipping copying initial content."
fi


0 comments on commit 2e828db

Please sign in to comment.