Last active
October 31, 2022 19:49
-
-
Save patmaddox/cac604b1a9f503c9cfd54ae64f097e19 to your computer and use it in GitHub Desktop.
Cirrus CI build/test/deploy config for Elixir on FreeBSD using ex_freebsd
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
gcp_credentials: ENCRYPTED[!...!] | |
# custom-built instance with some packages pre-installed to save time | |
# otherwise use: | |
# freebsd_instance: | |
# image_family: freebsd-13-0 | |
# and install your packages | |
gce_instance: | |
image_project: ratio-ops | |
image_family: ratio-freebsd-13-1-ci | |
platform: FreeBSD | |
zone: us-west1-c | |
type: n1-standard-8 | |
env: | |
USE_LOCALSTACK: no | |
OBAN_KEY_FINGERPRINT: ENCRYPTED[...] | |
OBAN_LICENSE_KEY: ENCRYPTED[...] | |
PATH: /usr/local/lib/erlang24/bin:$PATH | |
test_task: | |
env: | |
MIX_ENV: test | |
deps_cache: | |
folder: deps | |
build_cache: | |
folder: _build | |
npm_cache: | |
folder: assets/node_modules | |
reupload_on_changes: false # since there is a fingerprint script | |
fingerprint_script: | |
- echo $CIRRUS_OS | |
- cat assets/package-lock.json | |
start_postgres_background_script: | |
- service postgresql start | |
compile_script: ./cirrus/compile.sh | |
mix_script: mix test | |
pkg_task: | |
only_if: $CIRRUS_BRANCH == 'main' | |
env: | |
MIX_ENV: prod | |
deps_cache: | |
folder: deps | |
build_cache: | |
folder: _build | |
npm_cache: | |
folder: assets/node_modules | |
reupload_on_changes: false # since there is a fingerprint script | |
fingerprint_script: | |
- echo $CIRRUS_OS | |
- cat assets/package-lock.json | |
compile_script: ./cirrus/compile.sh | |
mix_script: | |
- mix assets.deploy | |
- mix release | |
- mix freebsd.pkg | |
- rm -rf _build/prod/rel | |
- tar czf freebsd-${CIRRUS_BUILD_ID}.txz sprlcl-*.pkg | |
- curl -s -X POST --data-binary @freebsd-${CIRRUS_BUILD_ID}.txz http://${CIRRUS_HTTP_CACHE_HOST}/freebsd-${CIRRUS_BUILD_ID}.txz | |
deploy_staging_task: | |
only_if: $CIRRUS_BRANCH == 'main' | |
execution_lock: deploy_staging | |
depends_on: | |
- test | |
- pkg | |
env: | |
TS_KEY: ENCRYPTED[...] | |
SSH_KEY: ENCRYPTED[...] | |
STAGING_FINGERPRINT: "staging.host,1.2.3.4 ecdsa-sha2-nistp256 ...=" | |
ssh_key_file: | |
path: /.cirrus_ssh/key | |
variable_name: SSH_KEY | |
known_hosts_file: | |
path: /.cirrus_ssh/known_hosts | |
variable_name: STAGING_FINGERPRINT | |
install_script: ./cirrus/install.sh sprlcl-staging | |
deploy_prod_task: | |
only_if: $CIRRUS_BRANCH == 'main' | |
execution_lock: deploy_prod | |
trigger_type: manual | |
depends_on: | |
- test | |
- pkg | |
- deploy_staging | |
env: | |
TS_KEY: ENCRYPTED[...] | |
SSH_KEY: ENCRYPTED[...] | |
PROD_FINGERPRINT: "prod.host,1.2.3.4 ecdsa-sha2-nistp256 ...=" | |
ssh_key_file: | |
path: /.cirrus_ssh/key | |
variable_name: SSH_KEY | |
known_hosts_file: | |
path: /.cirrus_ssh/known_hosts | |
variable_name: PROD_FINGERPRINT | |
install_script: ./cirrus/install.sh sprlcl-prod |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
set -e | |
npm ci --prefix assets | |
# this is because we originally installed elixir rather than elixir-devel | |
# which uses an older version. Haven't updated base CI machine yet. | |
pkg update | |
pkg remove -y elixir elixir-hex | |
pkg autoremove -y | |
pkg install -y elixir-devel erlang-runtime24 | |
mix local.hex --force --if-missing | |
mix local.rebar --force --if-missing | |
mix hex.repo add oban https://getoban.pro/repo --fetch-public-key $OBAN_KEY_FINGERPRINT --auth-key $OBAN_LICENSE_KEY | |
mix deps.get | |
mix compile --force --warnings-as-errors |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
set -e | |
deploy_host=$1 | |
tailscale up --authkey ${TS_KEY} --hostname cirrus-${CIRRUS_REPO_NAME}-${CIRRUS_BRANCH}-${CIRRUS_BUILD_ID} | |
echo '' >> /.cirrus_ssh/key # needs an empty line at end | |
echo '' >> /.cirrus_ssh/known_hosts # needs an empty line at end | |
chmod 700 /.cirrus_ssh | |
chmod 600 /.cirrus_ssh/* | |
fetch http://${CIRRUS_HTTP_CACHE_HOST}/freebsd-${CIRRUS_BUILD_ID}.txz | |
tar xzf freebsd-${CIRRUS_BUILD_ID}.txz | |
ssh -i /.cirrus_ssh/key -o UserKnownHostsFile=/.cirrus_ssh/known_hosts deployer@${deploy_host} "rm -rf cirrus_repo && mkdir cirrus_repo" | |
scp -i /.cirrus_ssh/key -o UserKnownHostsFile=/.cirrus_ssh/known_hosts sprlcl-*.pkg deployer@${deploy_host}:cirrus_repo | |
ssh -i /.cirrus_ssh/key -o UserKnownHostsFile=/.cirrus_ssh/known_hosts deployer@${deploy_host} "pkg repo cirrus_repo" | |
ssh -i /.cirrus_ssh/key -o UserKnownHostsFile=/.cirrus_ssh/known_hosts deployer@${deploy_host} "sudo pkg install -y -f -r cirrus sprlcl" | |
ssh -i /.cirrus_ssh/key -o UserKnownHostsFile=/.cirrus_ssh/known_hosts deployer@${deploy_host} "sudo service sprlcl restart" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment