2023-06-18 20:22:44 +00:00
|
|
|
# borrowed from https://gitlab.com/nix17/nixos-config/-/blob/main/.gitlab-ci.yml
|
|
|
|
|
|
|
|
stages:
|
2023-12-27 21:16:30 +00:00
|
|
|
- misc
|
2023-07-25 07:17:38 +00:00
|
|
|
- test
|
2023-07-26 22:23:55 +00:00
|
|
|
- deploy
|
2023-08-07 02:03:46 +00:00
|
|
|
- deploy_gitlab
|
2023-06-18 20:22:44 +00:00
|
|
|
|
2023-07-26 22:32:20 +00:00
|
|
|
# Update the flake for any changes upstream
|
2023-06-18 20:22:44 +00:00
|
|
|
# Passed in from upstream
|
|
|
|
# $PACKAGE_NAME = name of the flake that needs to be updated
|
|
|
|
# $UPDATE_FLAKE = flag to update the flake
|
|
|
|
update:
|
2023-12-27 21:16:30 +00:00
|
|
|
stage: misc
|
2023-07-30 04:08:29 +00:00
|
|
|
tags:
|
|
|
|
- nix
|
2023-06-18 20:22:44 +00:00
|
|
|
# from https://forum.gitlab.com/t/git-push-from-inside-a-gitlab-runner/30554/5
|
|
|
|
before_script:
|
2023-07-26 22:32:20 +00:00
|
|
|
# set teh ssh key for the commit
|
2023-07-26 22:35:58 +00:00
|
|
|
- eval $(ssh-agent -s)
|
2023-06-18 20:22:44 +00:00
|
|
|
- echo "${CI_KEY}" | tr -d '\r' | ssh-add - > /dev/null
|
|
|
|
- mkdir -p ~/.ssh
|
|
|
|
- chmod 700 ~/.ssh
|
|
|
|
- echo "$CI_KEY" >> ~/.ssh/id_rsa.pub
|
|
|
|
- '[[ -f /.dockerenv ]] && echo -e "Host *\n\tStrictHostKeyChecking no\n\n" > ~/.ssh/config'
|
|
|
|
|
|
|
|
script:
|
|
|
|
- git config --global user.email "${CI_EMAIL}"
|
|
|
|
- git config --global user.name "${CI_USERNAME}"
|
|
|
|
# the part that updates the flake
|
2023-08-11 01:00:32 +00:00
|
|
|
- nix --experimental-features 'nix-command flakes' flake lock --update-input $PACKAGE_NAME
|
2023-06-18 20:22:44 +00:00
|
|
|
- git add flake.lock
|
|
|
|
- git commit -m "[skip ci] Updated flake for $PACKAGE_NAME" || echo "No changes, nothing to commit"
|
|
|
|
# we have a custom domain
|
2023-08-11 06:52:33 +00:00
|
|
|
- git remote rm origin && git remote add origin ssh://git@gitlab.skynet.ie:2222/compsoc1/skynet/nixos.git
|
2023-06-18 20:22:44 +00:00
|
|
|
- git push origin HEAD:$CI_COMMIT_REF_NAME
|
|
|
|
only:
|
|
|
|
refs:
|
|
|
|
- main
|
|
|
|
variables:
|
|
|
|
- $UPDATE_FLAKE == "yes"
|
|
|
|
|
2023-12-27 21:16:30 +00:00
|
|
|
sync_repos:
|
|
|
|
stage: misc
|
|
|
|
image: registry.gitlab.com/gitlab-ci-utils/curl-jq:2.0.0
|
|
|
|
script:
|
|
|
|
- cd sync
|
|
|
|
- chmod +x ./sync.sh
|
|
|
|
- ./sync.sh
|
|
|
|
rules:
|
2023-12-27 22:49:39 +00:00
|
|
|
- if: '$SYNC_OVERRIDE == "true"'
|
2023-12-27 21:16:30 +00:00
|
|
|
- changes:
|
|
|
|
- sync/repos.csv
|
|
|
|
|
2023-08-09 19:27:04 +00:00
|
|
|
.scripts_base: &scripts_base
|
|
|
|
# load nix environment
|
2023-08-09 19:31:31 +00:00
|
|
|
- git pull origin $CI_COMMIT_REF_NAME
|
2023-08-09 19:56:22 +00:00
|
|
|
- . "$HOME/.nix-profile/etc/profile.d/nix.sh"
|
2023-10-02 02:25:24 +00:00
|
|
|
- nix --extra-experimental-features 'nix-command flakes' profile install nixpkgs#colmena
|
2023-08-09 19:27:04 +00:00
|
|
|
|
|
|
|
.scripts_deploy: &scripts_deploy
|
|
|
|
# setup ssh key
|
|
|
|
- eval $(ssh-agent -s)
|
|
|
|
- echo "$DEPLOY_KEY" | tr -d '\r' | ssh-add - > /dev/null
|
|
|
|
- mkdir -p ~/.ssh
|
|
|
|
- chmod 700 ~/.ssh
|
|
|
|
|
2023-07-26 22:32:20 +00:00
|
|
|
# every commit on main will build and deploy
|
2023-08-09 19:12:43 +00:00
|
|
|
.build_template: &builder
|
2023-07-30 04:08:29 +00:00
|
|
|
tags:
|
|
|
|
- nix
|
2023-07-26 22:23:55 +00:00
|
|
|
before_script:
|
2023-08-09 19:27:04 +00:00
|
|
|
- *scripts_base
|
2023-09-28 10:14:05 +00:00
|
|
|
rules:
|
|
|
|
- changes:
|
2023-07-28 13:02:30 +00:00
|
|
|
- applications/**/*
|
|
|
|
- machines/**/*
|
|
|
|
- secrets/**/*
|
|
|
|
- flake.*
|
2023-08-06 17:45:03 +00:00
|
|
|
- .gitlab-ci.yml
|
|
|
|
|
2023-08-09 19:12:43 +00:00
|
|
|
# deploy items only run on main
|
|
|
|
.deploy_template: &deployment
|
2023-08-09 19:27:04 +00:00
|
|
|
before_script:
|
|
|
|
- *scripts_deploy
|
|
|
|
- *scripts_base
|
2023-09-28 10:10:56 +00:00
|
|
|
rules:
|
2023-09-28 10:20:57 +00:00
|
|
|
- if: '$CI_PROJECT_NAMESPACE == "compsoc1/skynet" && $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH'
|
2023-09-30 22:53:03 +00:00
|
|
|
changes:
|
|
|
|
- flake.nix
|
|
|
|
- flake.lock
|
|
|
|
- applications/**/*
|
|
|
|
- machines/**/*
|
|
|
|
- secrets/**/*
|
2023-08-09 19:12:43 +00:00
|
|
|
|
2023-10-27 02:12:51 +00:00
|
|
|
linter:
|
|
|
|
<<: *builder
|
|
|
|
stage: test
|
|
|
|
script:
|
|
|
|
- nix --extra-experimental-features 'nix-command flakes' fmt -- --check .
|
|
|
|
|
2023-08-07 02:03:46 +00:00
|
|
|
build:
|
2023-08-09 19:12:43 +00:00
|
|
|
<<: *builder
|
2023-08-07 02:03:46 +00:00
|
|
|
stage: test
|
|
|
|
script:
|
2023-11-20 17:33:51 +00:00
|
|
|
- colmena build -v --on @active-dns
|
|
|
|
- colmena build -v --on @active-core
|
|
|
|
- colmena build -v --on @active
|
|
|
|
- colmena build -v --on @active-ext
|
|
|
|
- colmena build -v --on @active-gitlab
|
2023-08-07 02:03:46 +00:00
|
|
|
|
|
|
|
# dns always has to be deployed first
|
|
|
|
deploy_dns:
|
2023-08-09 19:12:43 +00:00
|
|
|
<<: *builder
|
|
|
|
<<: *deployment
|
2023-08-06 17:45:03 +00:00
|
|
|
stage: deploy
|
2023-08-07 02:03:46 +00:00
|
|
|
script:
|
2023-11-20 17:33:51 +00:00
|
|
|
- colmena apply -v --on @active-dns
|
2023-08-07 02:03:46 +00:00
|
|
|
|
|
|
|
deploy_core:
|
2023-08-09 19:12:43 +00:00
|
|
|
<<: *builder
|
|
|
|
<<: *deployment
|
2023-08-07 02:03:46 +00:00
|
|
|
stage: deploy
|
|
|
|
needs:
|
|
|
|
- deploy_dns
|
|
|
|
script:
|
2023-11-20 17:33:51 +00:00
|
|
|
- colmena apply -v --on @active-core
|
2023-08-07 02:03:46 +00:00
|
|
|
|
|
|
|
deploy_active:
|
2023-08-09 19:12:43 +00:00
|
|
|
<<: *builder
|
|
|
|
<<: *deployment
|
2023-08-07 02:03:46 +00:00
|
|
|
stage: deploy
|
|
|
|
needs:
|
|
|
|
- deploy_dns
|
|
|
|
script:
|
2023-11-20 17:33:51 +00:00
|
|
|
- colmena apply -v --on @active
|
2023-08-07 02:03:46 +00:00
|
|
|
|
2023-09-28 13:06:44 +00:00
|
|
|
# this is just skynet server
|
|
|
|
deploy_ext:
|
|
|
|
<<: *builder
|
|
|
|
<<: *deployment
|
|
|
|
stage: deploy
|
|
|
|
needs:
|
|
|
|
- deploy_dns
|
|
|
|
script:
|
2023-11-20 17:33:51 +00:00
|
|
|
- colmena apply -v --on @active-ext
|
2023-09-28 13:13:31 +00:00
|
|
|
allow_failure: true
|
2023-09-28 13:06:44 +00:00
|
|
|
|
2023-08-07 02:03:46 +00:00
|
|
|
deploy_gitlab:
|
2023-08-09 19:12:43 +00:00
|
|
|
<<: *builder
|
|
|
|
<<: *deployment
|
2023-08-07 02:03:46 +00:00
|
|
|
stage: deploy_gitlab
|
2023-08-06 17:45:03 +00:00
|
|
|
script:
|
2023-11-20 17:33:51 +00:00
|
|
|
- colmena apply -v --on @active-gitlab
|
2023-08-06 17:45:03 +00:00
|
|
|
when: manual
|