Skip to content

Instantly share code, notes, and snippets.

@ntimo
Created October 20, 2022 18:23
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ntimo/3f103526955c5b795ff0ccec152a612e to your computer and use it in GitHub Desktop.
Save ntimo/3f103526955c5b795ff0ccec152a612e to your computer and use it in GitHub Desktop.
Test Coder Tempaltes with GitLab CI
---
stages:
- tpl_test
- tpl_sync
integration_tests:
stage: tpl_test
image:
name: ubuntu:20.04
entrypoint: [""]
resource_group: template_tests
script:
- |
apt-get update > /dev/null
apt-get install -y wget tar jq curl gettext > /dev/null
- |
version=$(curl -sL $CODER_URL/api/v2/buildinfo | jq -r '.version' | cut -d '+' -f 1)
echo "Coder server version: $version"
mkdir /tmp/coder
wget -q -O /tmp/coder/coder.tar.gz "https://github.com/coder/coder/releases/download/${version}/coder_${version//v}_linux_amd64.tar.gz"
tar -zxvf /tmp/coder/coder.tar.gz
cp coder /usr/local/bin/coder
chmod +x /usr/local/bin/coder
- |
cd .tests/${PROVIDER}/
echo "Updating secrets in template.yml"
envsubst < template.yml | tee template.yml >/dev/null
cd ../..
- |
cd ${PROVIDER}
coder templates list | grep -q "${PROVIDER}-test " || error_code=$?
if [ $error_code -eq 1 ]; then
echo ""
echo "----------------------------------------------------------------"
echo "------- Create template"
echo "----------------------------------------------------------------"
echo ""
coder templates create ${PROVIDER}-test --yes --parameter-file ../.tests/${PROVIDER}/template.yml
else
echo ""
echo "----------------------------------------------------------------"
echo "------- Update template"
echo "----------------------------------------------------------------"
echo ""
coder templates push ${PROVIDER}-test --yes --parameter-file ../.tests/${PROVIDER}/template.yml
fi
- |
echo "----------------------------------------------------------------"
echo "------- Create workspace"
echo "----------------------------------------------------------------"
echo ""
coder create test-for-template-${PROVIDER} --template ${PROVIDER}-test --yes --parameter-file ../.tests/${PROVIDER}/workspace.yml
sleep 10
echo ""
echo "----------------------------------------------------------------"
echo "------- Show workspace"
echo "----------------------------------------------------------------"
echo ""
coder show test-for-template-${PROVIDER}
echo ""
echo "----------------------------------------------------------------"
echo "------- Stop workspace"
echo "----------------------------------------------------------------"
echo ""
coder stop test-for-template-${PROVIDER} --yes
sleep 10
echo ""
echo "----------------------------------------------------------------"
echo "------- Delete workspace"
echo "----------------------------------------------------------------"
echo ""
coder delete test-for-template-${PROVIDER} --yes
parallel:
matrix:
- PROVIDER:
- docker
- hetzner-cloud
sync_to_coder:
stage: tpl_sync
image:
name: ubuntu:20.04
entrypoint: [""]
resource_group: template_deploy
script:
- |
apt-get update > /dev/null
apt-get install -y wget tar jq curl gettext > /dev/null
- |
version=$(curl -sL $CODER_URL/api/v2/buildinfo | jq -r '.version' | cut -d '+' -f 1)
echo "Coder server version: $version"
mkdir /tmp/coder
wget -q -O /tmp/coder/coder.tar.gz "https://github.com/coder/coder/releases/download/${version}/coder_${version//v}_linux_amd64.tar.gz"
tar -zxvf /tmp/coder/coder.tar.gz
cp coder /usr/local/bin/coder
chmod +x /usr/local/bin/coder
- |
cd .tests/${PROVIDER}/
echo "Updating secrets in template.yml"
envsubst < template.yml | tee template.yml >/dev/null
cd ../..
- |
cd ${PROVIDER}
coder templates list | grep -q "$PROVIDER " || error_code=$?
if [ $error_code -eq 1 ]; then
echo ""
echo "----------------------------------------------------------------"
echo "------- Create template"
echo "----------------------------------------------------------------"
echo ""
coder templates create ${PROVIDER} --yes --parameter-file ../.tests/${PROVIDER}/template.yml
else
echo ""
echo "----------------------------------------------------------------"
echo "------- Update template"
echo "----------------------------------------------------------------"
echo ""
coder templates push ${PROVIDER} --yes --parameter-file ../.tests/${PROVIDER}/template.yml
fi
parallel:
matrix:
- PROVIDER:
- docker
- hetzner-cloud
only:
refs:
- master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment