name: Build docker containers
on:
  push:
    branches:
      - master
env:
  CACHIX_CACHE: capack
jobs:
  build-packages:
    name: Build docker containers
    runs-on: ubuntu-latest
    steps:
      - name: Install Nix
        run: |
          curl -L https://nixos.org/nix/install | sh
          source ~/.nix-profile/etc/profile.d/nix.sh
          nix --version
      - name: Set up cachix
        run: |
          source ~/.nix-profile/etc/profile.d/nix.sh
          nix-env -iA cachix -f https://cachix.org/api/v1/install
          cachix --version
          cachix use ${CACHIX_CACHE}
      - uses: actions/checkout@v2
      - name: Login to DockerHub
        uses: docker/login-action@v1
        with:
          username: ${{ secrets.DOCKERHUB_USERNAME }}
          password: ${{ secrets.DOCKERHUB_TOKEN }}
      - name: Build docker containers
        run: |
          source ~/.nix-profile/etc/profile.d/nix.sh
          nix-build https://github.com/oar-team/nur-kapack/archive/master.tar.gz -A batsim-docker-master -o ./container-tarball
          docker load -i ./container-tarball
          docker push oarteam/batsim:latest
