Skip to content

With environment restriction #34

With environment restriction

With environment restriction #34

on:
push:
branches: [main]
pull_request:
jobs:
build-and-deploy:
name: Build and deploy
runs-on: ubuntu-latest
permissions:
contents: read
id-token: write
steps:
- uses: DeterminateSystems/nix-installer-action@main
- uses: actions/checkout@v4
- uses: aws-actions/configure-aws-credentials@v4
id: aws
with:
role-to-assume: "${{ vars.DEPLOY_ROLE_ARN }}"
aws-region: eu-central-1
output-credentials: true
# Needed for substitution as that happens by nix-daemon and runs as root
- name: Set up aws credentials for root user
run: |
sudo aws configure set aws_access_key_id ${{ steps.aws.outputs.aws-access-key-id }}
sudo aws configure set aws_secret_access_key ${{ steps.aws.outputs.aws-secret-access-key }}
sudo aws configure set aws_session_token ${{ steps.aws.outputs.aws-session-token }}
sudo aws configure set region eu-central-1
- id: get-cache-secret-key
name: Get cache secret key
run: echo "${{ secrets.CACHE_SECRET_KEY }}" > cache-secret-key
- id: build
name: Build
run: |
store="${{ vars.CACHE_BUCKET }}&secret-key=$(realpath ./cache-secret-key)"
out_path=$(nix build \
--eval-store auto \
--store "$store" \
--builders auto \
--extra-substituters "https://cache.nixos.org $store" \
--trusted-public-keys "cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY= ${{ vars.CACHE_PUBLIC_KEY }}" \
--print-out-paths \
.#nixosConfigurations.web-push.config.system.build.toplevel)
# if ! nix path-info --eval-store auto --store "$store" .#nixosConfigurations.web-push.config.system.build.toplevel; then
# nix copy --eval-store auto --to "$store" .#nixosConfigurations.web-push.config.system.build.toplevel
# :fi
# out_path=$(nix path-info --eval-store auto --store "$store" .#nixosConfigurations.web-push.config.system.build.toplevel)
echo "out_path=$out_path" >> "$GITHUB_OUTPUT"
- id: deploy
name: Deploy
run: |
aws ssm send-command \
--document-name ${{ vars.SSM_DOCUMENT_NAME }} \
--targets 'Key=tag:Name,Values=web-push' \
--parameters "installable=${{ steps.build.outputs.out_path }},substituters=${{ vars.CACHE_BUCKET }},trustedPublicKeys=${{ vars.CACHE_PUBLIC_KEY }}"
- id: wait-for-deploy
name: Wait for deploy
run: |
echo "TODO: Implement"
echo "Deployed successfully"