From 0008c8b73980e68ae0589deb73d9a36297473f15 Mon Sep 17 00:00:00 2001 From: Condorra Date: Sun, 12 Feb 2023 23:05:34 +1100 Subject: [PATCH] Attempt to deploy as part of pipeline. --- .ci/build | 18 +++++++++--------- .ci/deploy | 14 ++++++++++++++ .ci/deploy-baseimage/Dockerfile | 2 ++ .ci/deploy-baseimage/README.md | 1 + .ci/deploy-baseimage/build-push | 2 ++ .concourse.yml | 19 ++++++++++++++++++- 6 files changed, 46 insertions(+), 10 deletions(-) create mode 100644 .ci/deploy create mode 100644 .ci/deploy-baseimage/Dockerfile create mode 100644 .ci/deploy-baseimage/README.md create mode 100755 .ci/deploy-baseimage/build-push diff --git a/.ci/build b/.ci/build index 02d9b9f..7c30131 100755 --- a/.ci/build +++ b/.ci/build @@ -3,18 +3,18 @@ set -Eeuo pipefail export HOME=$(pwd) export CARGO_HOME=$(pwd)/.cargo -echo Pre-build layout -ls -laR . - cd blastmud-repo + +BUILDSTAMP=$(date +%s) + +echo Build timestamp for binary names: $BUILDSTAMP echo Running tests cargo test --target-dir ../target --profile release + echo Running main build cargo build --target-dir ../target --profile release -echo Copying artifacts -cp ../target/release/blastmud_game ../output/ -cp ../target/release/blastmud_listener ../output/ -echo Final layout -cd .. -ls -laR . +echo Copying artifacts +echo $BUILDSTAMP >../binaries/buildstamp +cp ../target/release/blastmud_game ../binaries/ +cp ../target/release/blastmud_listener ../binaries/ diff --git a/.ci/deploy b/.ci/deploy new file mode 100644 index 0000000..3be7096 --- /dev/null +++ b/.ci/deploy @@ -0,0 +1,14 @@ +#!/bin/bash +set -Eeuo pipefail + +DEPLOY_HOST=172.19.11.5 +echo $DEPLOY_KEY >deploy-key +chmod 0600 ./deploy-key +BUILDSTAMP=$(cat binaries/buildstamp) +tar -cvJf binary-archive-$BUILDSTAMP.tar.xz -C blastmud_game blastmud_listener +scp -i deploy-key binary-archive-$BUILDSTAMP.tar.xz blast@$DEPLOY_HOST:/home/blast/archive/ +ssh -i deploy-key blast@$DEPLOY_HOST "find /home/blast/archive -mtime +30 -delete && mkdir -p /home/blast/latest && tar -xvJf /home/blast/archive/binary/binary-archive-$BUILDSTAMP.tar.xz -C /home/blast/latest" + +# In the future, we should wrap this in a check it is needed... +ssh -i deploy-key blast@$DEPLOY_HOST "mv /home/blast/latest/blastmud_game /mnt/gameserver-app/exe" +ssh -i deploy-key blast@$DEPLOY_HOST "mv /home/blast/latest/blastmud_listener /mnt/listener-app/exe" diff --git a/.ci/deploy-baseimage/Dockerfile b/.ci/deploy-baseimage/Dockerfile new file mode 100644 index 0000000..52cf2f8 --- /dev/null +++ b/.ci/deploy-baseimage/Dockerfile @@ -0,0 +1,2 @@ +FROM debian:latest +RUN apt-get update && apt-get install -y jq ssh git curl ca-certificates xz-utils && rm -rf /var/lib/apt/lists/* diff --git a/.ci/deploy-baseimage/README.md b/.ci/deploy-baseimage/README.md new file mode 100644 index 0000000..2b6479b --- /dev/null +++ b/.ci/deploy-baseimage/README.md @@ -0,0 +1 @@ +A base image for running our deploys. It is used by CI, but isn't auto-deployed by it. diff --git a/.ci/deploy-baseimage/build-push b/.ci/deploy-baseimage/build-push new file mode 100755 index 0000000..df41dd9 --- /dev/null +++ b/.ci/deploy-baseimage/build-push @@ -0,0 +1,2 @@ +docker build -t blasthavers/deploy-base:latest . +docker push blasthavers/deploy-base:latest diff --git a/.concourse.yml b/.concourse.yml index e346d0e..2e92cd6 100644 --- a/.concourse.yml +++ b/.concourse.yml @@ -1,6 +1,9 @@ jobs: - name: build-blastmud-image public: true + build_log_retention: + days: 365 + builds: 50 plan: - get: blastmud-repo trigger: true @@ -17,9 +20,23 @@ jobs: - path: target - path: .cargo outputs: - - name: output + - name: binaries run: path: blastmud-repo/.ci/build + - task: deploy + config: + platform: linux + image_resource: + type: registry-image + source: + repository: blasthavers/deploy-base + inputs: + - name: binaries + - name: blastmud-repo + params: + DEPLOY_KEY: ((deploy_key)) + run: + path: blastmud-repo/.ci/deploy resources: - name: blastmud-repo type: git