Skip to content

Commit

Permalink
Add dev ecr and secrets
Browse files Browse the repository at this point in the history
  • Loading branch information
wsalesky committed Oct 26, 2023
1 parent d21b6db commit 8261ae0
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 36 deletions.
5 changes: 2 additions & 3 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ jobs:
build/workflow.sh
env:
SECRET_KEY: ${{ secrets.SECRET_KEY }}
ADMIN_PASSWORD: ${{secrets.ADMIN_PASSWORD}}
ECR_REPOSITORY: ${{secrets.ECR_REPOSITORY}}
ADMIN_PASSWORD: ${{secrets.DEV_ADMIN_PASSWORD}}
ECR_REPOSITORY: ${{secrets.DEV_ECR_REPOSITORY}}
AWS_REGION: ${{ secrets.AWS_REGION }}
AWS_ACCOUNT_ID: ${{ secrets.AWS_ACCOUNT_ID }}
DEV_ECR_REPOSITORY: ${{ secrets.AWS_ACCOUNT_ID }}
75 changes: 42 additions & 33 deletions build/workflow.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,28 @@
GITHUB_ORG="Chinese-Monuments-WG"
GITHUB_REPOSITORY="tcadrt"

### 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
mkdir autodeploy
Expand All @@ -13,55 +35,42 @@ echo "Fetching the data repository to build a data xar"
git clone https://github.com/$GITHUB_ORG/$GITHUB_REPOSITORY

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 ..
# remove any old auto deploy
#rm -rf autodeploy
# create an autodeploy folder
#mkdir autodeploy

#echo "Running app build ..."
#ant
#echo "Ran app build successfully"


# 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 .
docker build -t "$PACKAGE_NAME:$VERSION" --build-arg ADMIN_PASSWORD="$DEV_ADMIN_PASSWORD" --no-cache .
echo docker build -t "$PACKAGE_NAME:$VERSION" --build-arg ADMIN_PASSWORD="$DEV_ADMIN_PASSWORD" --no-cache .
echo "Built successfully"

DOCKER_URL=$AWS_ACCOUNT_ID.dkr.ecr.$AWS_REGION.amazonaws.com/$ECR_REPOSITORY:latest
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 All @@ -72,4 +81,4 @@ docker tag $PACKAGE_NAME:$VERSION $DOCKER_URL
echo "Pushing to $DOCKER_URL"
docker push $DOCKER_URL

echo "Pushed successfully, wait for a few minutes to see the changes reflected"
echo "Pushed successfully, wait for a few minutes to see the changes reflected"

0 comments on commit 8261ae0

Please sign in to comment.