Skip to content

Commit

Permalink
Merge branch 'staging' into chore/merge-master-to-staging-a17s26
Browse files Browse the repository at this point in the history
  • Loading branch information
darcywong00 committed Nov 23, 2023
2 parents 6a97d3f + 3860532 commit 3c335b0
Show file tree
Hide file tree
Showing 19 changed files with 179 additions and 239 deletions.
3 changes: 3 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@

Dockerfile text eol=lf
*.sh eol=lf
65 changes: 65 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
name: CI

on: [pull_request]

jobs:

build-test:
runs-on: ubuntu-20.04
env:
KEYMANHOSTS_TIER: TIER_TEST

steps:
- name: Checkout
uses: actions/checkout@v3

# Build the docker image
- name: Build the Docker image
shell: bash
run: |
echo "TIER_TEST" > tier.txt
./build.sh build start
env:
fail-fast: true

#
# Finally, run the tests; note that this is almost all replicated in build.sh; here logging is reduced (TODO sync)
#
- name: Lint
shell: bash
run: |
( set +e; set +o pipefail; find . -name '*.php' | grep -v '/vendor/' | xargs -n 1 -d '\n' php -l | grep -v "No syntax errors detected"; exit ${PIPESTATUS[2]} )
# Link checker not needed. No html files to verify

- name: Check PHP errors
shell: bash
run: |
CONTAINER=`docker container ls -l -q`
if docker container logs $CONTAINER 2>&1 | grep -q 'php7'; then
echo 'PHP reported errors or warnings:'
docker container logs $CONTAINER 2>&1 | grep 'php7'
exit 1
else
echo 'No PHP errors found'
exit 0
fi
- name: Check static file generated
shell: bash
run: |
pwd
if [ ! -f ./metadata/kmwversions.json ]; then
echo "Failed to generate static file"
exit 1
fi
#
# If any of the tests fail, let's grab a bit more detail on the environment
#
- name: Report errors
if: ${{ failure() }}
shell: bash
run: |
CONTAINER=`docker container ls -l -q`
echo "--- PHP errors in Docker log ---"
docker container logs $CONTAINER 2>&1 | grep 'php7'
18 changes: 0 additions & 18 deletions .github/workflows/deploy.yml

This file was deleted.

9 changes: 8 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
.idea/

# Ignore CI-generated static file of kmwversions
metadata/
metadata/

/vendor

# Shared files are bootstrapped:
resources/bootstrap.inc.sh
resources/.bootstrap-version
_common/
14 changes: 13 additions & 1 deletion .htaccess
Original file line number Diff line number Diff line change
@@ -1,8 +1,20 @@
<IfModule mod_headers.c>
Header set Access-Control-Allow-Origin "*"
</IfModule>
<IfModule mod_mime.c>
AddType font/ttf .ttf
AddType font/woff .woff
AddType font/woff2 .woff2
AddType font/otf .otf
AddType application/vnd.ms-fontobject .eot
AddType application/x-apple-aspen-config .mobileconfig
AddType image/svg+xml .svg
AddType application/javascript .js

AddCharset UTF-8 .js
</IfModule>
<IfModule mod_rewrite.c>
RewriteEngine on

RewriteRule ^(cdnrefresh.php|Dockerfile|web.config|.git|App_Data)$ - [R=404,L]
RewriteRule ^(build.sh|Dockerfile|.git|resources/)$ - [R=404,L]
</IfModule>
23 changes: 0 additions & 23 deletions App_Data/jobs/continuous/deploy/README.md

This file was deleted.

25 changes: 0 additions & 25 deletions App_Data/jobs/continuous/deploy/run.bat

This file was deleted.

3 changes: 0 additions & 3 deletions App_Data/jobs/continuous/deploy/settings.job

This file was deleted.

13 changes: 11 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,2 +1,11 @@
FROM php:5.6-apache
RUN a2enmod rewrite
# syntax=docker/dockerfile:1
# Site
FROM php:7.4-apache

# Install jq
RUN apt-get update && apt-get install -y \
jq
RUN cp /usr/local/etc/php/php.ini-production /usr/local/etc/php/php.ini
RUN chown -R www-data:www-data /var/www/html/

RUN a2enmod headers mime rewrite
18 changes: 0 additions & 18 deletions api/deploy.php

This file was deleted.

61 changes: 0 additions & 61 deletions api/webhooks.php

This file was deleted.

63 changes: 63 additions & 0 deletions build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
#!/usr/bin/env bash
## START STANDARD SITE BUILD SCRIPT INCLUDE
readonly THIS_SCRIPT="$(readlink -f "${BASH_SOURCE[0]}")"
readonly BOOTSTRAP="$(dirname "$THIS_SCRIPT")/resources/bootstrap.inc.sh"
readonly BOOTSTRAP_VERSION=chore/v0.4
[ -f "$BOOTSTRAP" ] && source "$BOOTSTRAP" || source <(curl -fs https://raw.githubusercontent.com/keymanapp/shared-sites/$BOOTSTRAP_VERSION/bootstrap.inc.sh)
## END STANDARD SITE BUILD SCRIPT INCLUDE

readonly S_KEYMAN_CONTAINER_NAME=s-keyman-website
readonly S_KEYMAN_CONTAINER_DESC=s-keyman-com-app
readonly S_KEYMAN_IMAGE_NAME=s-keyman-website
readonly HOST_S_KEYMAN_COM=s.keyman.com.localhost

source _common/keyman-local-ports.inc.sh
source _common/docker.inc.sh

################################ Main script ################################

builder_describe \
"Setup s.keyman.com site to run via Docker." \
configure \
clean \
build \
start \
stop \
test \

builder_parse "$@"

function test_docker_container() {
# Note: ci.yml replicates these

# TODO: Run unit tests
#docker exec $S_KEYMAN_CONTAINER_DESC sh -c "vendor/bin/phpunit --testdox"

# Lint .php files for obvious errors
docker exec $S_KEYMAN_CONTAINER_DESC sh -c "find . -name '*.php' | grep -v '/vendor/' | xargs -n 1 -d '\\n' php -l"

# Link checker not needed. No html files to verify

# Verify static file generated
if [ ! -f ./metadata/kmwversions.json ]; then
builder_die "Failed to generate static file"
fi
}

# Custom cleanup of static file
function clean_docker_container_s() {
clean_docker_container $S_KEYMAN_IMAGE_NAME $S_KEYMAN_CONTAINER_NAME

# Cleanup static file
if [ -f ./metadata/kmwversions.json ]; then
rm ./metadata/kmwversions.json
fi
}

builder_run_action configure bootstrap_configure
builder_run_action clean clean_docker_container_s
builder_run_action stop stop_docker_container $S_KEYMAN_IMAGE_NAME $S_KEYMAN_CONTAINER_NAME
builder_run_action build build_docker_container $S_KEYMAN_IMAGE_NAME $S_KEYMAN_CONTAINER_NAME
builder_run_action start start_docker_container $S_KEYMAN_IMAGE_NAME $S_KEYMAN_CONTAINER_NAME $S_KEYMAN_CONTAINER_DESC $HOST_S_KEYMAN_COM $PORT_S_KEYMAN_COM

builder_run_action test test_docker_container
Binary file removed deploy/jq-win64.exe
Binary file not shown.
32 changes: 0 additions & 32 deletions deploy/jq.inc.sh

This file was deleted.

10 changes: 4 additions & 6 deletions deploy/kmwversion.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@

set -eu

. ./jq.inc.sh

# Sort the versions in descending order
# https://stackoverflow.com/questions/65315720/how-to-sort-release-version-string-in-descending-order-with-bash
function _sortVersions () {
Expand All @@ -29,11 +27,11 @@ function _search () {
# Write result to JSON file
function _emit () {
if [ ! -z "$sorted" ]; then
$JQ -nc '{versions: $ARGS.positional}' --args ${sorted[@]} | \
$JQ --indent 4 > ../metadata/kmwversions.json
jq -nc '{versions: $ARGS.positional}' --args ${sorted[@]} | \
jq --indent 4 > ../metadata/kmwversions.json
else
$JQ -nc '{error: "No releases found"}' | \
$JQ --indent 4 > ../metadata/kmwversions.json
jq -nc '{error: "No releases found"}' | \
jq --indent 4 > ../metadata/kmwversions.json
fi
}

Expand Down
Loading

0 comments on commit 3c335b0

Please sign in to comment.