From ecd531708ca8944304511866144d4cbc27a7c571 Mon Sep 17 00:00:00 2001 From: EmmaLRussell Date: Fri, 9 Aug 2024 14:08:10 +0100 Subject: [PATCH] Add build and run scripts, use ghcr tags --- db/scripts/build | 6 +++--- db/scripts/common | 19 ------------------- db/scripts/run | 4 ++-- docker/build | 9 +++++++++ docker/common | 26 ++++++++++++++++++++++++++ docker/run | 12 ++++++++++++ 6 files changed, 52 insertions(+), 24 deletions(-) delete mode 100644 db/scripts/common create mode 100755 docker/build create mode 100644 docker/common create mode 100755 docker/run diff --git a/db/scripts/build b/db/scripts/build index c62e8f18..97cbb483 100755 --- a/db/scripts/build +++ b/db/scripts/build @@ -1,11 +1,11 @@ #!/usr/bin/env bash set -e HERE=$(dirname $0) -. $HERE/common +. $HERE/../../docker/common PACKAGE_ROOT=$(realpath $HERE/..) docker build \ - -t "$TAG_SHA" \ - -t "$TAG_BRANCH" \ + -t "$DB_TAG_SHA" \ + -t "$DB_TAG_BRANCH" \ $PACKAGE_ROOT diff --git a/db/scripts/common b/db/scripts/common deleted file mode 100644 index fda8acbc..00000000 --- a/db/scripts/common +++ /dev/null @@ -1,19 +0,0 @@ -#!/usr/bin/env bash -set -ex - -if [[ -v "GITHUB_SHA" ]]; then - GIT_ID=${GITHUB_SHA:0:7} -else - GIT_ID=$(git rev-parse --short=7 HEAD) -fi - -if [[ -v "BRANCH_NAME" ]]; then - GIT_BRANCH=${BRANCH_NAME} -else - GIT_BRANCH=$(git symbolic-ref --short HEAD) -fi - -ORG=jameel-institute -IMAGE_NAME=daedalus-web-app-db -TAG_SHA="${ORG}/${IMAGE_NAME}:${GIT_ID}" -TAG_BRANCH="${ORG}/${IMAGE_NAME}:${GIT_BRANCH}" diff --git a/db/scripts/run b/db/scripts/run index a6d1379c..a29e8d48 100755 --- a/db/scripts/run +++ b/db/scripts/run @@ -2,10 +2,10 @@ set -e HERE=$(dirname $0) -. $HERE/common +. $HERE/../../docker/common docker run --rm -d \ --network=bridge \ --name daedalus-web-app-db \ -p 5432:5432 \ - "$TAG_BRANCH" + "$DB_TAG_BRANCH" diff --git a/docker/build b/docker/build new file mode 100755 index 00000000..1e60ecc1 --- /dev/null +++ b/docker/build @@ -0,0 +1,9 @@ +#!/usr/bin/env bash +set -e +HERE=$(dirname $0) +. $HERE/common + +docker build \ + --tag $APP_TAG_SHA \ + -f docker/Dockerfile \ + . \ No newline at end of file diff --git a/docker/common b/docker/common new file mode 100644 index 00000000..2f5b844e --- /dev/null +++ b/docker/common @@ -0,0 +1,26 @@ +#!/usr/bin/env bash +set -ex + +if [[ -v "GITHUB_SHA" ]]; then + GIT_ID=${GITHUB_SHA:0:7} +else + GIT_ID=$(git rev-parse --short=7 HEAD) +fi + +if [[ -v "BRANCH_NAME" ]]; then + GIT_BRANCH=${BRANCH_NAME} +else + GIT_BRANCH=$(git symbolic-ref --short HEAD) +fi + +REGISTRY=ghcr.io +ORG=jameel-institute +DB_IMAGE_NAME=daedalus-web-app-db +DB_TAG="${REGISTRY}/${ORG}/${DB_IMAGE_NAME}" +DB_TAG_SHA="${DB_TAG}:${GIT_ID}" +DB_TAG_BRANCH="${DB_TAG}:${GIT_BRANCH}" + +APP_IMAGE_NAME=daedalus-web-app +APP_TAG="${REGISTRY}/${ORG}/${APP_IMAGE_NAME}" +APP_TAG_SHA="${APP_TAG}:${GIT_ID}" +APP_TAG_BRANCH="${APP_TAG}:${GIT_BRANCH}" diff --git a/docker/run b/docker/run new file mode 100755 index 00000000..091d2009 --- /dev/null +++ b/docker/run @@ -0,0 +1,12 @@ +#!/usr/bin/env bash +set -e +HERE=$(dirname $0) +. $HERE/common +# run web app image, assuming dependencies are already running +docker run --rm -d \ + --network bridge \ + --name daedalus-web-app \ + -p 3000:3000 \ + "$APP_TAG_SHA" + +# env vars \ No newline at end of file