Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gc/GitHub actions rewrite #36

Merged
merged 3 commits into from May 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
29 changes: 9 additions & 20 deletions .github/workflows/build-test.yaml
Expand Up @@ -5,31 +5,20 @@ on:
branches: "**"
pull_request:
branches: [main]
# env:
# DOCKER_ENV_FILE: ".github/workflows/docker.env"
jobs:
build-test:
runs-on: ubuntu-latest
# services:
# alpine:
# image: alpine
steps:
- uses: actions/checkout@v3
- name: docker build
uses: docker/build-push-action@v3
with:
push: false
tags: allaboutapps.dev/cra-template:${{ github.sha }}
# volumes: /var/run/docker.sock:/var/run/docker.sock
- name: docker run
run: docker run -d --name=container -it allaboutapps.dev/cra-template:${{ github.sha }}
- name: create-react-app
run: docker exec container yarn create react-app my-app-ci --template file://cra-template/
- name: build (scaffolded project)
run: docker exec container bash -c "cd my-app-ci && yarn build && yarn lint"
- name: test (scaffolded project)
run: docker exec container bash -c "cd my-app-ci && yarn test:ci"
- name: scaffold test project
run: yarn test
- name: build test project
run: cd template-test && yarn build
- name: lint
run: cd template-test && yarn lint
- name: test
run: cd template-test && yarn test:ci
- name: test docker-entrypoint.sh patching
run: docker exec container bash -c "cd my-app-ci && ./scripts/test-docker-entrypoint.sh"
run: cd template-test && ./scripts/test-docker-entrypoint.sh


26 changes: 0 additions & 26 deletions Dockerfile

This file was deleted.

16 changes: 11 additions & 5 deletions template/docker-entrypoint.sh
Expand Up @@ -5,25 +5,31 @@

set -e

if [ "$1" == "test" ]; then
NGINX_BASE=./nginx
else
NGINX_BASE=/etc/nginx
fi

# Only update config with defined env variables if we are running an nginx process so we can still attach with debugging commands
# without accidentally modifying anything
if [ "$1" == "nginx" ] || [ "$1" == "test" ]; then
if [ ! -z "${REACT_APP_API_BASE_URL}" ]; then
sed -i "/ENV_API_BASE_URL/c\var ENV_API_BASE_URL = \"${REACT_APP_API_BASE_URL}\";" /etc/nginx/html/app/config.js
sed -i "/ENV_API_BASE_URL/c\var ENV_API_BASE_URL = \"${REACT_APP_API_BASE_URL}\";" $NGINX_BASE/html/app/config.js
fi

if [ ! -z "${REACT_APP_DEPLOYMENT_ENV}" ]; then
sed -i "/ENV_DEPLOYMENT_ENV/c\var ENV_DEPLOYMENT_ENV = \"${REACT_APP_DEPLOYMENT_ENV}\";" /etc/nginx/html/app/config.js
sed -i "/ENV_DEPLOYMENT_ENV/c\var ENV_DEPLOYMENT_ENV = \"${REACT_APP_DEPLOYMENT_ENV}\";" $NGINX_BASE/html/app/config.js
fi

if [ ! -z "${REACT_APP_BASE_NAME}" ]; then
sed -i "/ENV_BASE_NAME/c\var ENV_BASE_NAME = \"${REACT_APP_BASE_NAME}\";" /etc/nginx/html/app/config.js
sed -i "s#REACT_APP_BASE_NAME#$REACT_APP_BASE_NAME#g" /etc/nginx/conf.d/default.conf | sed "s#//#/#g"
sed -i "/ENV_BASE_NAME/c\var ENV_BASE_NAME = \"${REACT_APP_BASE_NAME}\";" $NGINX_BASE/html/app/config.js
sed -i "s#REACT_APP_BASE_NAME#$REACT_APP_BASE_NAME#g" $NGINX_BASE/conf.d/default.conf | sed "s#//#/#g"

# The <base href="/"> is already set to "/". If the REACT_APP_BASE_NAME is a "/", it will change the base href to "//" which is invalid.
# Therefore we only run the command if the REACT_APP_BASE_NAME is not "/".
if [ "$REACT_APP_BASE_NAME" != "/" ]; then
sed -i "s#<base href=\"/\">#<base href=\"$REACT_APP_BASE_NAME/\">#g" /etc/nginx/html/app/index.html | sed "s#<base href=\"//\">#<base href=\"/\">#g"
sed -i "s#<base href=\"/\">#<base href=\"$REACT_APP_BASE_NAME/\">#g" $NGINX_BASE/html/app/index.html | sed "s#<base href=\"//\">#<base href=\"/\">#g"
fi
fi
fi
Expand Down
17 changes: 10 additions & 7 deletions template/scripts/test-docker-entrypoint.sh
@@ -1,15 +1,18 @@
#!/bin/bash

NGINX_BASE=./nginx

# Create fake nginx folder structure to match production
mkdir -p /etc/nginx/html/app
mkdir -p /etc/nginx/conf.d
mkdir -p $NGINX_BASE/html/app
mkdir -p $NGINX_BASE/conf.d


NGINX_CONF=/etc/nginx/conf.d/default.conf
CONFIG_JS=/etc/nginx/html/app/config.js
INDEX_HTML=/etc/nginx/html/app/index.html
NGINX_CONF=$NGINX_BASE/conf.d/default.conf
CONFIG_JS=$NGINX_BASE/html/app/config.js
INDEX_HTML=$NGINX_BASE/html/app/index.html

# Copy build files
cp -r ./build/* /etc/nginx/html/app
cp -r ./build/* $NGINX_BASE/html/app

# Copy nginx config
cp ./nginx-default.conf $NGINX_CONF
Expand Down Expand Up @@ -50,6 +53,6 @@ if ! grep -q "<base href=\"$BASE/\">" "$INDEX_HTML"; then
fi

# Cleanup
rm -rf /etc/nginx
rm -rf $NGINX_BASE

echo "docker-entrypoint.sh test passed successfully"