Running a IHP app build on github actions #1292
-
Hi, I would like to set up a CI build for my IHP project, any hints on how to do that? I found https://github.com/marketplace/actions/install-nix But not sure how that applies to a IHP project? |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 14 replies
-
Here's one github action file that builds an IHP app and then uses nix to copy it over to the production server. At the end the github action switches a symlink at name: Deployment
on:
push:
branches: [ master ]
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout Code
uses: actions/checkout@v2
- name: Install nix and cachix
uses: cachix/[email protected]
with:
nix_path: nixpkgs=https://github.com/NixOS/nixpkgs/archive/51bcdc4cdaac48535dabf0ad4642a66774c609ed.tar.gz
- name: Cachix Init
uses: cachix/cachix-action@v10
with:
name: digitallyinduced
skipPush: true
- name: "Building"
run : nix-build -j auto --cores 0
- name: Install SSH Key
uses: shimataro/[email protected]
with:
key: ${{ secrets.KEY }}
known_hosts: ${{ secrets.KNOWN_HOSTS }}
name: id_rsa
config: |
Host production
HostName REPLACEME.eu-central-1.compute.amazonaws.com
User root
IdentityFile ~/.ssh/id_rsa
- name: "Copying Build"
run : nix --experimental-features nix-command copy --to ssh://production ./result
- name: "Migrate DB"
run: |
nix-shell --run migrate
env:
DATABASE_URL: ${{ secrets.DATABASE_URL }}
- name: "Enable Build"
run: ssh production "ln -sfT $(readlink -f ./result) /root/app"
- name: "Restart App"
run: ssh production "systemctl restart app worker" If you don't want to deploy the binary, remove all steps after For completeness here's also a nix file that fits the above github action: let
ihpEnv = {
PORT = "8000";
IHP_REQUEST_LOGGER_IP_ADDR_SOURCE = "FromHeader";
IHP_BASEURL = "https://someapp.digitallyinduced.com";
IHP_ENV = "Production";
DATABASE_URL = "REPLACEME";
IHP_SESSION_SECRET = "REPLACEME";
};
in
{ config, pkgs, modulesPath, ... }: {
imports = [ "${modulesPath}/virtualisation/amazon-image.nix" ];
ec2.hvm = true;
environment.systemPackages = with pkgs; [
vim
];
i18n.defaultLocale = "en_US.UTF-8";
console = {
font = "Lat2-Terminus16";
keyMap = "us";
};
nix = {
binaryCaches = [ "https://digitallyinduced.cachix.org" ];
binaryCachePublicKeys = [ "digitallyinduced.cachix.org-1:y+wQvrnxQ+PdEsCt91rmvv39qRCYzEgGQaldK26hCKE=" ];
};
systemd.services.app = {
enable = true;
description = "App";
serviceConfig = {
Type = "simple";
ExecStart = "/root/app/bin/RunProdServer";
WorkingDirectory = "/root/app/lib";
};
environment = ihpEnv;
};
systemd.services.worker = {
enable = true;
description = "Worker";
serviceConfig = {
Type = "simple";
ExecStart = "/root/app/bin/RunJobs";
WorkingDirectory = "/root/app/lib";
};
environment = ihpEnv;
};
services.nginx = {
enable = true;
enableReload = true;
recommendedProxySettings = true;
recommendedGzipSettings = true;
recommendedOptimisation = true;
recommendedTlsSettings = true;
virtualHosts."someapp.digitallyinduced.com" = {
forceSSL = true;
enableACME = true;
locations = {
"/" = { proxyPass = "http://app_upstream"; proxyWebsockets = true; };
};
};
appendHttpConfig = ''
upstream app_upstream { server localhost:8000; }
'';
};
networking.firewall.allowedTCPPorts = [ 80 443 22 ];
security.acme.email = ''[email protected]'';
security.acme.acceptTerms = true;
} |
Beta Was this translation helpful? Give feedback.
-
One more related question: |
Beta Was this translation helpful? Give feedback.
-
Still having problems: (I printed both make commands)
|
Beta Was this translation helpful? Give feedback.
-
For the case someone comes here from Google or GitHub search, here's a fully working GitHub action file: # This is a basic workflow to help you get started with Actions
name: Test
# Controls when the workflow will run
on:
# Triggers the workflow on push or pull request events but only for the main branch
push:
branches: [ main ]
pull_request:
branches: [ main ]
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
tests:
name: Run Tests
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: cachix/install-nix-action@v15
with:
nix_path: nixpkgs=https://github.com/NixOS/nixpkgs/archive/51bcdc4cdaac48535dabf0ad4642a66774c609ed.tar.gz
- uses: cachix/cachix-action@v10
with:
name: digitallyinduced
skipPush: true
- run: |
mkdir -p ~/.config/nixpkgs
echo "{ allowBroken = true; }" >> ~/.config/nixpkgs/config.nix
nix-shell --run "make build/ihp-lib"
nix-shell --run "make build/Generated/Types.hs"
nix-shell --run "mkdir -p build/db; initdb build/db/state --no-locale --encoding UTF8;"
nix-shell --run "postgres -D build/db/state -k $PWD/build/db -c listen_addresses=" &
sleep 5 # Wait for pg to start
nix-shell --run "createdb app -h $PWD/build/db"
nix-shell --run "runghc $(make print-ghc-extensions) -i. -ibuild -iConfig Test/Main.hs" It's used in this repo https://github.com/francisdb/ihp-github-actions |
Beta Was this translation helpful? Give feedback.
For the case someone comes here from Google or GitHub search, here's a fully working GitHub action file: