Skip to content

Commit 6f86aba

Browse files
committed
update templates latest automation
1 parent bbd74eb commit 6f86aba

File tree

10 files changed

+197
-27
lines changed

10 files changed

+197
-27
lines changed

.github/workflows/.main.yml

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,3 @@
1-
env:
2-
AWS_REGION: us-east-2
3-
ECR_REPOSITORY: savantly
4-
SHA_TAG: ${{ github.sha }}
5-
IMAGE_TAG: $(cat VERSION)
6-
71
on:
82
push:
93
branches:
@@ -20,7 +14,7 @@ jobs:
2014
with:
2115
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
2216
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
23-
aws-region: ${{ env.AWS_REGION }}
17+
aws-region: us-east-2
2418

2519
- name: Login to Amazon ECR
2620
id: login-ecr
@@ -29,11 +23,32 @@ jobs:
2923
- name: Build, tag, and push image to Amazon ECR
3024
env:
3125
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
32-
ECR_REPOSITORY: ${{ env.ECR_REPOSITORY }}
33-
SHA_TAG: ${{ github.sha }}
3426
run: |
35-
export IMAGE_TAG=${{ env.IMAGE_TAG }}
36-
docker buildx build --platform linux/amd64 -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG -t $ECR_REGISTRY/$ECR_REPOSITORY:$SHA_TAG -t $ECR_REGISTRY/$ECR_REPOSITORY:latest .
27+
export IMAGE_TAG=$(cat VERSION)
28+
export SHORT_SHA=$(echo $GITHUB_SHA | cut -c1-7)
29+
ECR_REPOSITORY=$(cat project.mk | grep ECR_REPOSITORY | cut -d'=' -f2)
30+
ECR_REPOSITORY=$(echo $ECR_REPOSITORY | cut -d' ' -f1)
31+
docker buildx build --platform linux/amd64 \
32+
-t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG \
33+
-t $ECR_REGISTRY/$ECR_REPOSITORY:$SHORT_SHA \
34+
-t $ECR_REGISTRY/$ECR_REPOSITORY:latest .
3735
docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG
38-
docker push $ECR_REGISTRY/$ECR_REPOSITORY:$SHA_TAG
36+
docker push $ECR_REGISTRY/$ECR_REPOSITORY:$SHORT_SHA
3937
docker push $ECR_REGISTRY/$ECR_REPOSITORY:latest
38+
39+
- name: Set outputs for kubernetes deployment
40+
id: set-k8s-outputs
41+
run: |
42+
export K8S_NAMESPACE=$(cat project.mk | grep K8S_NAMESPACE_DEV | cut -d'=' -f2)
43+
export K8S_DEPLOYMENT=$(cat project.mk | grep K8S_DEPLOYMENT_DEV | cut -d'=' -f2)
44+
echo "::set-output name=K8S_NAMESPACE::$K8S_NAMESPACE"
45+
echo "::set-output name=K8S_DEPLOYMENT::$K8S_DEPLOYMENT"
46+
47+
- name: Rollout deployment
48+
uses: ianbelcher/eks-kubectl-action@master
49+
with:
50+
aws_access_key_id: ${{ secrets.AWS_ACCESS_KEY_ID }}
51+
aws_secret_access_key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
52+
aws_region: us-east-2
53+
cluster_name: production
54+
args: rollout restart deployment ${{ steps.set-k8s-outputs.outputs.K8S_DEPLOYMENT }} -n ${{ steps.set-k8s-outputs.outputs.K8S_NAMESPACE }}

.github/workflows/scan.yml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
name: Run PHPStan
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
9+
jobs:
10+
phpstan:
11+
name: Static Analysis
12+
runs-on: ubuntu-latest
13+
steps:
14+
- name: Checkout
15+
uses: actions/checkout@v4
16+
17+
- name: Setup PHP
18+
uses: shivammathur/setup-php@v2
19+
with:
20+
php-version: "latest"
21+
coverage: none
22+
tools: composer, cs2pr
23+
24+
- name: Install PHP dependencies
25+
uses: ramsey/composer-install@v2
26+
with:
27+
composer-options: "--prefer-dist --no-scripts"
28+
29+
- name: PHPStan
30+
run: composer phpstan

.gitignore

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
uploads/
2+
3+
# ignore log files and databases
4+
db
5+
*.log
6+
*.sql
7+
*.sqlite
8+
.env
9+
10+
**/.DS_Store
11+
.DS_Store
12+
13+
14+
**/*disabled
15+
16+
**/*.bak
17+
**/*.zip
18+
**/*.gz
19+
**/*.tar
20+
**/*.rar
21+
**/*.7z
22+
**/*.tgz
23+
**/*.bz2
24+
**/*.iso
25+
**/*.dmg
26+
**/*.bin
27+
**/*.exe
28+
**/*.msi
29+
**/*.apk
30+
**/*.ipa
31+
**/*.deb
32+
**/*.rpm
33+
34+
wflogs/
35+
backup/
36+
./vendor/
37+
docker-compose.prod.yml

Dockerfile

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
ARG BASE_IMAGE=savantly/wordpress
2-
ARG BASE_TAG=6.6.1-apache
2+
ARG BASE_TAG=6.6-php8.1-fpm
33
FROM ${BASE_IMAGE}:${BASE_TAG}
44

55
WORKDIR /usr/src/wordpress
6-
RUN set -eux; \
7-
find /etc/apache2 -name '*.conf' -type f -exec sed -ri -e "s!/var/www/html!$PWD!g" -e "s!Directory /var/www/!Directory $PWD!g" '{}' +; \
8-
cp -s wp-config-docker.php wp-config.php
96

107

118
COPY --chown=www-data:www-data plugins/ ./wp-content/plugins/
12-
COPY --chown=www-data:www-data themes/ ./wp-content/themes/
9+
COPY --chown=www-data:www-data themes/ ./wp-content/themes/
10+
COPY --chown=www-data:www-data config/.user.ini /usr/src/wordpress/.user.ini

Makefile

Lines changed: 66 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,44 @@
1+
# Makefile version 1.0
2+
3+
# Load the project configuration
4+
include project.mk
5+
6+
17
PROJECT_DIR := $(shell dirname $(realpath $(lastword $(MAKEFILE_LIST))))
28
BASE_IMAGE := "savantly/wordpress"
3-
BASE_TAG := "6.6.1-apache"
9+
BASE_TAG := "6.6.1-php8.1-fpm"
410

511
VERSION := $(shell cat VERSION)
612
TAGGED_VERSION := $(VERSION)
713
NEXT_VERSION := $(shell echo $(VERSION) | awk -F. '{$$NF = $$NF + 1;} 1' | sed 's/ /./g')
814

9-
IMAGE_NAME := "savantly/my-wordpress"
15+
# IMAGE_NAME - from project.mk
1016
IMAGE_TAG := "$(IMAGE_NAME):$(BASE_TAG)-$(TAGGED_VERSION)"
1117

1218
GIT_COMMIT := $(shell git rev-parse --short HEAD)
1319

1420
IMAGE_TAG_LATEST := "$(IMAGE_NAME):$(BASE_TAG)"
1521

16-
K8S_NAMESPACE := 'default'
17-
K8S_DEPLOYMENT := 'wordpress'
22+
# Define a variable to check if Composer is installed
23+
COMPOSER_CHECK := $(shell command -v composer > /dev/null 2>&1 && echo "yes" || echo "no")
24+
25+
26+
.PHONY: setup
27+
setup:
28+
@echo "Checking for composer..."
29+
@if [ "$(COMPOSER_CHECK)" = "no" ]; then \
30+
echo "Composer is not installed. Please install composer and try again."; \
31+
exit 1; \
32+
fi
33+
@echo "Setting up..."
34+
@command composer require --dev phpstan/phpstan
35+
36+
37+
.PHONY: analyze
38+
analyze:
39+
@echo "Analyzing..."
40+
@vendor/bin/phpstan --memory-limit=1024M analyse themes
41+
1842

1943
.PHONY: build
2044
build:
@@ -72,5 +96,41 @@ dev:
7296
download-pod:
7397
@echo "Downloading from pod..."
7498
export POD_NAME=$(shell kubectl get pods -n $(K8S_NAMESPACE) -l app.kubernetes.io/instance=$(K8S_DEPLOYMENT) -o jsonpath='{.items[0].metadata.name}') && \
75-
kubectl cp $(K8S_NAMESPACE)/$$POD_NAME:/var/www/html/wp-content/plugins $(PROJECT_DIR)/plugins/ && \
76-
kubectl cp $(K8S_NAMESPACE)/$$POD_NAME:/var/www/html/wp-content/themes $(PROJECT_DIR)/themes/
99+
kubectl cp $(K8S_NAMESPACE)/$$POD_NAME:/usr/src/wordpress/wp-content/plugins/ $(PROJECT_DIR)/plugins/ && \
100+
kubectl cp $(K8S_NAMESPACE)/$$POD_NAME:/usr/src/wordpress/wp-content/uploads/ $(PROJECT_DIR)/uploads/ && \
101+
kubectl cp $(K8S_NAMESPACE)/$$POD_NAME:/usr/src/wordpress/wp-content/themes/ $(PROJECT_DIR)/themes/
102+
103+
104+
.PHONY: upload-pod
105+
upload-pod:
106+
@echo "Uploading to pod..."
107+
export POD_NAME=$(shell kubectl get pods -n $(K8S_NAMESPACE) -l app.kubernetes.io/instance=$(K8S_DEPLOYMENT) -o jsonpath='{.items[0].metadata.name}') && \
108+
kubectl cp $(PROJECT_DIR)/plugins $(K8S_NAMESPACE)/$$POD_NAME:/usr/src/wordpress/wp-content/ --no-preserve=true && \
109+
kubectl cp $(PROJECT_DIR)/uploads $(K8S_NAMESPACE)/$$POD_NAME:/usr/src/wordpress/wp-content/ --no-preserve=true && \
110+
kubectl cp $(PROJECT_DIR)/themes $(K8S_NAMESPACE)/$$POD_NAME:/usr/src/wordpress/wp-content/ --no-preserve=true
111+
112+
113+
.PHONY: upload-pod-themes
114+
upload-pod-themes:
115+
@echo "Uploading to pod..."
116+
export POD_NAME=$(shell kubectl get pods -n $(K8S_NAMESPACE) -l app.kubernetes.io/instance=$(K8S_DEPLOYMENT) -o jsonpath='{.items[0].metadata.name}') && \
117+
kubectl cp $(PROJECT_DIR)/themes $(K8S_NAMESPACE)/$$POD_NAME:/usr/src/wordpress/wp-content/ --no-preserve=true
118+
119+
.PHONY: pod-shell
120+
pod-shell:
121+
@echo "Opening shell in pod..."
122+
export POD_NAME=$(shell kubectl get pods -n $(K8S_NAMESPACE) -l app.kubernetes.io/instance=$(K8S_DEPLOYMENT) -o jsonpath='{.items[0].metadata.name}') && \
123+
kubectl exec -it $$POD_NAME -n $(K8S_NAMESPACE) -- /bin/bash
124+
125+
.PHONY: pod-logs
126+
pod-logs:
127+
@echo "Getting logs from pod..."
128+
export POD_NAME=$(shell kubectl get pods -n $(K8S_NAMESPACE) -l app.kubernetes.io/instance=$(K8S_DEPLOYMENT) -o jsonpath='{.items[0].metadata.name}') && \
129+
kubectl logs -f $$POD_NAME -n $(K8S_NAMESPACE)
130+
131+
# uses kubectl to get the secret and decode the base64 encoded values
132+
.PHONY: reveal-cicd-creds
133+
reveal-cicd-creds:
134+
@echo "Revealing cicd creds..."
135+
@kubectl get secret cicd -n $(K8S_NAMESPACE) -o jsonpath="{.data.AWS_ACCESS_KEY_ID}" | base64 --decode
136+
@kubectl get secret cicd -n $(K8S_NAMESPACE) -o jsonpath="{.data.AWS_SECRET_ACCESS_KEY}" | base64 --decode

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# wordpress-hosted
22

3+
---
4+
5+
These instructions should be updated to reflect the current state of the project.
6+
7+
---
8+
39
Template repository for Savantly Wordpress Enterprise hosting
410

511
Savantly provide a container based Wordpress hosting solution that is designed to be scalable, secure and easy to manage.

composer.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"require-dev": {
3+
"phpstan/phpstan": "^1.12",
4+
"szepeviktor/phpstan-wordpress": "^1.3"
5+
}
6+
}

config/.user.ini

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
memory_limit = 512M
2+
max_input_vars = 3000

docker-compose.yml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
version: "3.9"
22
services:
33
webapp:
4-
image: savantly/wordpress:6.6.1-apache
4+
image: savantly/wordpress:6.6-php8.1-fpm
55
build:
66
context: .
77
dockerfile: Dockerfile
88
ports:
99
- "8080:80"
1010
volumes:
11-
- ./plugins:/var/www/html/wp-content/plugins
12-
- ./themes:/var/www/html/wp-content/themes
13-
- ./uploads:/var/www/html/wp-content/uploads
11+
- ./plugins:/usr/src/wordpress/wp-content/plugins
12+
- ./themes:/usr/src/wordpress/wp-content/themes
13+
- ./uploads:/usr/src/wordpress/wp-content/uploads
14+
- ./test/info.php:/usr/src/wordpress/info.php
1415
environment:
1516
SERVER_NAME: localhost
1617
WORDPRESS_CONFIG_EXTRA: |

project.mk.example

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
ECR_REPOSITORY := xyz
2+
IMAGE_NAME := "123.dkr.ecr.us-east-2.amazonaws.com/$(ECR_REPOSITORY)"
3+
K8S_NAMESPACE_DEV := abc
4+
K8S_DEPLOYMENT_DEV := xyz
5+
K8S_NAMESPACE_PROD := abc
6+
K8S_DEPLOYMENT_PROD := xyz
7+
PROFILE := 'dev'
8+
9+
ifeq ($(PROFILE),'dev')
10+
K8S_NAMESPACE := $(K8S_NAMESPACE_DEV)
11+
K8S_DEPLOYMENT := $(K8S_DEPLOYMENT_DEV)
12+
else
13+
K8S_NAMESPACE := $(K8S_NAMESPACE_PROD)
14+
K8S_DEPLOYMENT := $(K8S_DEPLOYMENT_PROD)
15+
endif

0 commit comments

Comments
 (0)