Prefer pure shell, print docker-build output #59
Workflow file for this run
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
name: deploy | |
on: | |
push: | |
branches: | |
- dev | |
- main | |
paths-ignore: | |
- "*.md" | |
jobs: | |
deploy: | |
name: Deploy | |
runs-on: ubuntu-latest | |
steps: | |
- name: Prepare environment | |
run: | | |
echo "TAG=${{ github.head_ref || github.ref_name }}" >> $GITHUB_ENV | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
- name: Install Nix | |
uses: cachix/install-nix-action@v24 | |
with: | |
nix_path: nixpkgs=channel:nixpkgs-23.11-darwin | |
extra_nix_config: | | |
trusted-public-keys = cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY= | |
substituters = https://cache.nixos.org/ | |
- name: Install dependencies | |
run: | | |
nix-shell --pure --run true | |
- name: Build | |
run: | | |
echo "IMAGE_PATH=$(nix-shell --pure --run docker-build | tee /dev/tty | tail -1)" >> $GITHUB_ENV | |
- name: Set up SSH | |
run: | | |
mkdir -p ~/.ssh | |
echo "${{ secrets.SSH_PRIVATE_KEY }}" > ~/.ssh/id_rsa && chmod 600 ~/.ssh/id_rsa | |
echo "${{ secrets.SSH_KNOWN_HOSTS }}" > ~/.ssh/known_hosts | |
echo "Host remote | |
HostName ${{ secrets.SSH_HOST }} | |
User ${{ secrets.SSH_USER }} | |
Port ${{ secrets.SSH_PORT }} | |
IdentityFile ~/.ssh/id_rsa | |
" > ~/.ssh/config | |
- name: Upload image | |
run: | | |
scp $IMAGE_PATH remote:~ | |
- name: Deploy | |
run: | | |
ssh remote <<EOF | |
set -e | |
image_filename=$(basename $IMAGE_PATH) | |
function cleanup { | |
echo "Cleaning up" | |
rm -f $image_filename | |
} | |
trap cleanup EXIT | |
echo "Loading Docker image" | |
docker load < $image_filename | |
echo "Fetching latest changes from the git repository" | |
cd $TAG | |
git fetch origin $TAG | |
git checkout $TAG | |
git reset --hard origin/$TAG | |
echo "Restarting containers" | |
export TAG=$TAG | |
docker compose --env-file envs/compose/$TAG.env up -d | |
EOF |