Skip to content

Commit

Permalink
Merge branch 'dev-build' of https://github.com/srophe/britishLibrary
Browse files Browse the repository at this point in the history
…into dev-build
  • Loading branch information
wsalesky committed Jul 8, 2024
2 parents 4c382fa + 09e6e35 commit bfd915d
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 23 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: ci
on:
push:
branches:
- 'build'
- 'dev-build'

permissions:
id-token: write # This is required for requesting the JWT
Expand Down
2 changes: 1 addition & 1 deletion build/git-sync_template.xql
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@ return
githubxq:execute-webhook($data,
'/db/apps/britishlibrary',
'https://github.com/srophe/britishlibrary',
'main',
'development',
'${SECRET_KEY}',
'')
58 changes: 37 additions & 21 deletions build/workflow.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,27 @@
GITHUB_ORG="srophe"
GITHUB_REPOSITORY="britishLibrary-data"

### CREATE NECESSARY CONFIG FOR THE BUILD, AND POPULATE VERSION AND PACKAGE_NAME
# use sed to replace the template git-sync with secrets and other
# Application git-sync
TEMPLATE_FILE="./build/git-sync_template.xql"
DESTINATION_FILE="./modules/git-sync.xql"

echo "Copying secret key over"
# SECRET_KEY, $ADMIN_PASSWORD
sed \
-e "s/\${SECRET_KEY}/$SECRET_KEY/" \
$TEMPLATE_FILE > $DESTINATION_FILE
echo "Copied secret key over successfully - app directory"

# GET the version of the project from the expath-pkg.xml
VERSION=$(cat expath-pkg.xml | grep package | grep version= | awk -F'version="' '{ print $2 }' | awk -F'"' '{ print $1 }')
# GET the package name of the project from the expath-pkg.xml file
PACKAGE_NAME=$(cat expath-pkg.xml | grep package | grep version= | awk -F'abbrev="' '{ print $2 }' | awk -F'"' '{ print tolower($1) }')
echo "Deploying app $PACKAGE_NAME:$VERSION"


### BUILD THE APPLICATION AND DATA THAT USES CONFIGS FROM THE PREV STEP A
# remove any old auto deploy
rm -rf autodeploy
# create an autodeploy folder
Expand All @@ -11,49 +32,44 @@ ant
echo "Ran app build successfully"

echo "Fetching the data repository to build a data xar"
git clone https://github.com/$GITHUB_ORG/$GITHUB_REPOSITORY
git clone https://github.com/$GITHUB_ORG/$GITHUB_REPOSITORY --branch development --single-branch

cd $GITHUB_REPOSITORY
### CREATE NECESSARY CONFIG FOR THE BUILD, AND POPULATE VERSION AND PACKAGE_NAME
# use sed to replace the template git-sync with secrets and other
# Application git-sync
TEMPLATE_FILE="./build/git-sync_template.xql"
DESTINATION_FILE="./modules/git-sync.xql"

echo "Copying secret key over"
# SECRET_KEY, $ADMIN_PASSWORD
sed \
-e "s/\${SECRET_KEY}/$SECRET_KEY/" \
$TEMPLATE_FILE > $DESTINATION_FILE
echo "Copied secret key over successfully - data directory"

rm -rf build
mkdir build
echo "Running data build ..."
ant
echo "Ran data build successfully"

cd ..

# move the xar from build to autodeploy
mv build/*.xar autodeploy/
mv $GITHUB_REPOSITORY/build/*.xar autodeploy/

rm -rf $GITHUB_REPOSITORY

# use sed to replace the template git-sync with secrets and other
TEMPLATE_FILE="./build/git-sync_template.xql"
DESTINATION_FILE="./conf/git-sync.xql"

echo "Copying secret key over"
# SECRET_KEY, $ADMIN_PASSWORD
sed \
-e "s/\${SECRET_KEY}/$SECRET_KEY/" \
$TEMPLATE_FILE > $DESTINATION_FILE
echo "Copied secret key over successfully"

# GET the version of the project from the expath-pkg.xml
VERSION=$(cat expath-pkg.xml | grep package | grep version= | awk -F'version="' '{ print $2 }' | awk -F'"' '{ print $1 }')
# GET the package name of the project from the expath-pkg.xml file
PACKAGE_NAME=$(cat expath-pkg.xml | grep package | grep version= | awk -F'abbrev="' '{ print $2 }' | awk -F'"' '{ print tolower($1) }')

echo "Deploying app $PACKAGE_NAME:$VERSION"


### BUILD DOCKER WITH THE APPLICATION AND DATA XAR FILE
echo "Building docker file"
docker build -t "$PACKAGE_NAME:$VERSION" --build-arg ADMIN_PASSWORD="$ADMIN_PASSWORD" --no-cache .
echo docker build -t "$PACKAGE_NAME:$VERSION" --build-arg ADMIN_PASSWORD="$ADMIN_PASSWORD" --no-cache .
echo "Built successfully"

DOCKER_URL=$AWS_ACCOUNT_ID.dkr.ecr.$AWS_REGION.amazonaws.com/$DEV_ECR_REPOSITORY:latest

### UPLOAD TO ECR
echo "Loging in to AWS"
# Get the aws docker login creds. Note: only works if the github repo is allowed access from OIDC
aws ecr get-login-password --region $AWS_REGION | \
Expand Down

0 comments on commit bfd915d

Please sign in to comment.