Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
zeme-wana committed Aug 22, 2023
1 parent eb8d9f8 commit 7c3904f
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 27 deletions.
41 changes: 24 additions & 17 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@ on:
jobs:
publish:
runs-on: ubuntu-latest
strategy:
matrix:
image: [marlowe-playground-server, marlowe-playground-client]
steps:
- name: Checkout
uses: actions/checkout@v3
Expand All @@ -32,23 +29,33 @@ jobs:
- name: Build image and copy to local Docker registry
run: |
nix develop --command std //marlowe-playground/oci-images/${{ matrix.image }}:load
nix build .#oci-images.x86_64-linux.all.copyToDockerDaemon
./result/bin/copy-to-docker-daemon
- 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
tagAndPush() {
IMAGE_ID=ghcr.io/${{ github.repository_owner }}/$1
# 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,')
# Strip "runtime@v" prefix from tag name
[[ "${{ github.ref }}" == "refs/tags/"* ]] && TAG=$(echo $TAG | sed -e 's/^runtime@v//')
# 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 $1:latest $IMAGE_ID:$TAG
docker push $IMAGE_ID:$TAG
}
tagAndPush "marlowe-playground-server"
tagAndPush "marlowe-playground-client"
29 changes: 21 additions & 8 deletions nix/marlowe-playground/oci-images.nix
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,27 @@ let
};
};

in
lib.optionalAttrs pkgs.stdenv.isLinux {
marlowe-playground-server = mkImage {
name = "marlowe-playground-server";
description = "The backend of the Marlowe playground.";
images = {
marlowe-playground-server = mkImage {
name = "marlowe-playground-server";
description = "The backend of the Marlowe playground.";
};
marlowe-playground-client = mkImage {
name = "marlowe-playground-client";
description = "An HTTP server that serves the client for the Marlowe Playground.";
};
};
marlowe-playground-client = mkImage {
name = "marlowe-playground-client";
description = "An HTTP server that serves the client for the Marlowe Playground.";

forAllImages = f: concatMapStrings (s: s + "\n") (mapAttrsToList f images);

in
images // {
all = {
copyToDockerDaemon = std.lib.ops.writeScript {
name = "copy-to-docker-daemon";
text = forAllImages (name: img:
"${n2c.packages.skopeo-nix2container}/bin/skopeo --insecure-policy copy nix:${img} docker-daemon:${name}:latest"
);
};
};
}
4 changes: 2 additions & 2 deletions nix/marlowe-playground/operables.nix
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{ inputs', pkgs, ... }:

project:
project:

let

Expand All @@ -12,7 +12,7 @@ let
in
{
marlowe-playground-client = mkOperable {
package = marlowe-playground-client;
package = inputs'.self.packages.marlowe-playground-client;
runtimeInputs = [ darkhttpd ];
runtimeScript = ''
exec darkhttpd "''${CONFIG_HTML_ROOT:-${inputs'.self.packages.marlowe-playground-client}}" --port 8080 --mimetypes ${mailcap}/etc/mime.types
Expand Down

0 comments on commit 7c3904f

Please sign in to comment.