Test commit to ensure CD is working for production #66
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" | |
env: | |
ALLOWED_URIS: "https://github.com https://api.github.com" | |
TRUSTED_PUBLIC_KEYS: "cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY= hydra.iohk.io:f/Ea+s+dFdN+3Y/G+FDgSq+a5NEWhJGzdjvKNGv0/EQ= marlowe-temp.cachix.org-1:1gPjVFpu4QjaAT3tRurCioX+BC23V7mjvFwpP5bV0Ec= loony-tools:pr9m4BkM/5/eSTZlkQyRt57Jz7OMBxNSUiMC4FkcNfk=" | |
SUBSTITUTERS: "https://cache.nixos.org/ https://cache.iog.io https://marlowe-temp.cachix.org https://cache.zw3rk.com/" | |
on: | |
push: | |
branches: | |
- main | |
- production | |
jobs: | |
publish: | |
runs-on: ubuntu-latest | |
strategy: | |
matrix: | |
image: [marlowe-playground-server, marlowe-playground-client] | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v3 | |
- name: Install Nix | |
uses: cachix/install-nix-action@v20 | |
with: | |
nix_path: nixpkgs=channel:nixos-unstable | |
install_url: https://releases.nixos.org/nix/nix-2.10.3/install | |
extra_nix_config: | | |
allowed-uris = ${{ env.ALLOWED_URIS }} | |
trusted-public-keys = ${{ env.TRUSTED_PUBLIC_KEYS }} | |
substituters = ${{ env.SUBSTITUTERS }} | |
experimental-features = nix-command flakes | |
- name: Build image and copy to local Docker registry | |
run: | | |
nix build .\#__std.actions.x86_64-linux.marlowe-playground.oci-images.${{ matrix.image }}.load | |
./result | |
- name: Authenticate with container registry | |
run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u $ --password-stdin | |
- name: Tag and push images | |
run: | | |
IMAGE_ID=ghcr.io/${{ github.repository_owner }}/${{ matrix.image }} | |
# Change all uppercase to lowercase | |
IMAGE_ID=$(echo $IMAGE_ID | tr '[A-Z]' '[a-z]') | |
# Strip git ref prefix from version | |
TAG=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,') | |
# Use Docker `latest` tag convention | |
[ "$TAG" == "main" ] && TAG=latest | |
# Use date + short hash for production releases | |
[ "$TAG" == "production" ] && TAG="$(date +'%Y-%m-%d')-$(git rev-parse --short "${{ github.ref }}")" | |
echo IMAGE_ID=$IMAGE_ID | |
echo TAG=$TAG | |
docker tag ${{ matrix.image }} $IMAGE_ID:$TAG | |
docker push $IMAGE_ID:$TAG |