From b742b1d8a1397be4f25ba17ef5d50d41312607f5 Mon Sep 17 00:00:00 2001 From: Oliver Davies Date: Fri, 5 Nov 2021 17:30:00 +0000 Subject: [PATCH] build(run): add artifact command Add an `artifact:build` command that will pull the image for a given commit SHA and copy the generated HTML from it onto the local filesystem so that it can be served by Nginx in production. --- run | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/run b/run index dacf3ab3..265b0736 100755 --- a/run +++ b/run @@ -1,6 +1,6 @@ #!/bin/bash -set -e +set -eu . .env @@ -48,8 +48,23 @@ function help { printf "\nExtended help:\n Each task has comments for general usage\n" } -function run-production { - docker-compose --file docker-compose-production.yaml up --detach --remove-orphans +function artifact:build { + DESTINATION_PATH="${2:-/var/www/oliverdavies.uk}" + GIT_COMMIT_HASH=$1 + + # Clean up any old containers or files within the artifact directory. + rm -fr ${DESTINATION_PATH}/* || true + + docker image pull ghcr.io/opdavies/oliverdavies-uk-web:${GIT_COMMIT_HASH} + + docker container run \ + --entrypoint sh \ + --name oliverdavies-uk-web \ + ghcr.io/opdavies/oliverdavies-uk-web:${GIT_COMMIT_HASH} + + docker container cp oliverdavies-uk-web:/code ${DESTINATION_PATH} + + docker container rm oliverdavies-uk-web } function sh {