Add CI/CD build and deploy scripts, along with docker-compose, HAProxy config, and a certbot
Some checks failed
Build And Deploy / build-and-deploy (push) Has been cancelled
Some checks failed
Build And Deploy / build-and-deploy (push) Has been cancelled
merge hook. Set up env.example generation. Add doiuse dev dependency.
This commit is contained in:
parent
0350a4b8e3
commit
1714225d00
11 changed files with 334 additions and 2 deletions
29
cicd/scripts/build.sh
Executable file
29
cicd/scripts/build.sh
Executable file
|
|
@ -0,0 +1,29 @@
|
|||
#!/bin/bash
|
||||
|
||||
#######################
|
||||
# VARIABLES #
|
||||
#######################
|
||||
ROOT_DIR=$(dirname $(dirname $(dirname $(realpath $0))))
|
||||
GIT_REF=${GIT_REF:-main}
|
||||
|
||||
### NO EDITS BELOW THIS LINE ###
|
||||
cd ${ROOT_DIR}
|
||||
source .env
|
||||
git checkout ${GIT_REF}
|
||||
GIT_SHA=$(git rev-parse --short HEAD)
|
||||
|
||||
if [[ "${GIT_REF}" =~ ^refs/tags/v([0-9]+\.[0-9]+\.[0-9]+)(-.*)?$ ]]; then
|
||||
VERSION="${BASH_REMATCH[1]}"
|
||||
if [[ -n "${BASH_REMATCH[2]}" ]]; then
|
||||
VERSION="${VERSION}${BASH_REMATCH[2]}"
|
||||
fi
|
||||
echo "Using git tag version: ${VERSION}"
|
||||
else
|
||||
VERSION=$(node -p "require('./package.json').version || '0.0.0'")
|
||||
GIT_SHA_SHORT="${GIT_SHA:0:7}"
|
||||
VERSION="${VERSION}-${GIT_SHA_SHORT}"
|
||||
echo "Using package.json + SHA version: ${VERSION}"
|
||||
fi
|
||||
|
||||
docker build -t ${IMAGE_NAME}:latest -t ${IMAGE_NAME}:v${VERSION} --build-arg VERSION=${VERSION} .
|
||||
docker save -o ${IMAGE_FILENAME} ${IMAGE_NAME}:latest
|
||||
42
cicd/scripts/deploy.sh
Executable file
42
cicd/scripts/deploy.sh
Executable file
|
|
@ -0,0 +1,42 @@
|
|||
#!/bin/bash
|
||||
|
||||
#######################
|
||||
# VARIABLES #
|
||||
#######################
|
||||
ROOT_DIR=$(dirname $(dirname $(dirname $(realpath $0))))
|
||||
|
||||
### NO EDITS BELOW THIS LINE ###
|
||||
cd ${ROOT_DIR}
|
||||
source .env
|
||||
|
||||
mkdir -p ${HOME}/.ssh
|
||||
chmod 700 ${HOME}/.ssh
|
||||
echo "${SSH_KEY}" > ${HOME}/.ssh/id_ed25519-${SSH_HOST//./_}
|
||||
echo "${SSH_KNOWN_HOST}" > ${HOME}/.ssh/known_hosts-${SSH_HOST//./_}
|
||||
chmod -R 600 ${HOME}/.ssh/
|
||||
chmod 700 ${HOME}/.ssh
|
||||
|
||||
grep -q "Host ${SSH_HOST}" ${HOME}/.ssh/config || cat >> ${HOME}/.ssh/config <<EOF
|
||||
Host ${SSH_HOST}
|
||||
HostName ${SSH_HOST}
|
||||
User ${SSH_USER}
|
||||
Port ${SSH_PORT}
|
||||
IdentityFile ${HOME}/.ssh/id_ed25519-${SSH_HOST//./_}
|
||||
UserKnownHostsFile ${HOME}/.ssh/known_hosts-${SSH_HOST//./_}
|
||||
StrictHostKeyChecking yes
|
||||
ControlMaster auto
|
||||
ControlPath ~/.ssh/control-%C
|
||||
ControlPersist yes
|
||||
ConnectionAttempts 3
|
||||
ConnectTimeout 10
|
||||
ServerAliveInterval 10
|
||||
EOF
|
||||
|
||||
DOCKER_HOST=ssh://${SSH_HOST} docker load -i ${IMAGE_FILENAME}
|
||||
|
||||
ssh ${SSH_HOST} "mkdir -p /srv/${IMAGE_NAME#*/}/"
|
||||
ssh ${SSH_HOST} "cd /srv/${IMAGE_NAME#*/}/ && docker compose down"
|
||||
scp .env ${SSH_HOST}:/srv/${IMAGE_NAME#*/}/.env
|
||||
cd deploy
|
||||
scp -r . ${SSH_HOST}:/srv/${IMAGE_NAME#*/}/
|
||||
ssh ${SSH_HOST} "cd /srv/${IMAGE_NAME#*/}/ && docker compose up -d"
|
||||
Loading…
Add table
Add a link
Reference in a new issue