Skip to content

Commit

Permalink
docker-publish.yml: Use nix
Browse files Browse the repository at this point in the history
  • Loading branch information
evan-goode committed May 11, 2024
1 parent f0d5560 commit dcc124b
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 44 deletions.
47 changes: 20 additions & 27 deletions .github/workflows/docker-publish.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,4 @@
# This workflow uses actions that are not certified by GitHub.
# They are provided by a third-party and are governed by
# separate terms of service, privacy policy, and support
# documentation.

# GitHub recommends pinning actions to a commit SHA.
# To get a newer version, you will need to update the SHA.
# You can also reference a tag or branch, but the action may change without warning.

name: Publish Docker image
name: Publish OCI image

on:
push:
Expand All @@ -16,19 +7,15 @@ on:

jobs:
push_to_registry:
name: Push Docker image to Docker Hub
name: Push OCI image to Docker Hub
runs-on: ubuntu-latest
steps:
- name: Check out the repo
uses: actions/checkout@v3

- name: Log in to Docker Hub
uses: docker/login-action@f4ef78c080cd8ba55a85445d5b36e214a81df20a
- uses: actions/checkout@v3
- uses: cachix/install-nix-action@v20
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
github_access_token: ${{ secrets.GITHUB_TOKEN }}

- name: Extract metadata (tags, labels) for Docker
- name: Extract metadata (tags, labels)
id: meta
uses: docker/metadata-action@v4
with:
Expand All @@ -37,11 +24,17 @@ jobs:
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
- name: Build and push Docker image
uses: docker/build-push-action@3b5e8027fcad23fda98b2e3ac259d8d67585f671
with:
context: .
file: ./Dockerfile
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
- name: Build and push OCI image
env:
REFERENCES: ${{ steps.meta.outputs.tags }}
run: |
for system in 'x86_64-linux' 'aarch64-linux'; do
oci_archive="$(nix build --no-link --print-out-paths ".#oci-cross-$system")"
for reference in $REFERENCES; do
skopeo --insecure-policy copy \
--dest-creds='${{ secrets.DOCKERHUB_USERNAME }}:${{ secrets.DOCKERHUB_TOKEN }}' \
"docker-archive:$oci_archive" \
"docker://$reference"
done
done
2 changes: 1 addition & 1 deletion .github/workflows/nix-build.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: "nix build"
name: nix build
on:
pull_request:
push:
Expand Down
29 changes: 13 additions & 16 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{
description = "Self-hosted API server for Minecraft";

# Nixpkgs / NixOS version to use.
inputs = {
nixpkgs.url = "nixpkgs/nixos-23.11";
buildNodeModules = {
Expand All @@ -17,18 +16,17 @@
}: let
version = "1.0.3";

# System types to support.
supportedSystems = ["x86_64-linux" "x86_64-darwin" "aarch64-linux" "aarch64-darwin"];
# nodejs_20 is currently broken on Darwin
supportedSystems = ["x86_64-linux" "aarch64-linux"];
# supportedSystems = ["x86_64-linux" "x86_64-darwin" "aarch64-linux" "aarch64-darwin"];

# Helper function to generate an attrset '{ x86_64-linux = f "x86_64-linux"; ... }'.
forAllSystems = nixpkgs.lib.genAttrs supportedSystems;

overlays = [];

nixpkgsFor = forAllSystems (system: import nixpkgs {inherit system overlays;});
nixpkgsFor = forAllSystems (system: import nixpkgs {inherit system;});
nixpkgsCross =
forAllSystems (localSystem:
forAllSystems (crossSystem: import nixpkgs {inherit localSystem crossSystem overlays;}));
forAllSystems (crossSystem: import nixpkgs {inherit localSystem crossSystem;}));
in {
packages = forAllSystems (system: let
buildDrasl = pkgs: let
Expand Down Expand Up @@ -65,27 +63,26 @@
'';
};

buildDockerImage = pkgs:
buildOCIImage = pkgs:
pkgs.dockerTools.buildLayeredImage {
name = "unmojang/drasl";
tag = "latest";
contents = with pkgs; [cacert];
config.Cmd = "${buildDrasl pkgs}/bin/drasl";
};
in rec {
drasl = buildDrasl nixpkgsFor.${system};

drasl-cross-x86_64-linux = buildDrasl nixpkgsCross.${system}.x86_64-linux;
drasl-cross-x86_64-darwin = buildDrasl nixpkgsCross.${system}.x86_64-darwin;
# drasl-cross-x86_64-darwin = buildDrasl nixpkgsCross.${system}.x86_64-darwin;
drasl-cross-aarch64-linux = buildDrasl nixpkgsCross.${system}.aarch64-linux;
drasl-cross-aarch64-darwin = buildDrasl nixpkgsCross.${system}.aarch64-darwin;
# drasl-cross-aarch64-darwin = buildDrasl nixpkgsCross.${system}.aarch64-darwin;

docker = buildDockerImage nixpkgsFor.${system};
oci = buildOCIImage nixpkgsFor.${system};

docker-cross-x86_64-linux = buildDockerImage nixpkgsCross.${system}.x86_64-linux;
docker-cross-x86_64-darwin = buildDockerImage nixpkgsCross.${system}.x86_64-darwin;
docker-cross-aarch64-linux = buildDockerImage nixpkgsCross.${system}.aarch64-linux;
docker-cross-aarch64-darwin = buildDockerImage nixpkgsCross.${system}.aarch64-darwin;
oci-cross-x86_64-linux = buildOCIImage nixpkgsCross.${system}.x86_64-linux;
# oci-cross-x86_64-darwin = buildOCIImage nixpkgsCross.${system}.x86_64-darwin;
oci-cross-aarch64-linux = buildOCIImage nixpkgsCross.${system}.aarch64-linux;
# oci-cross-aarch64-darwin = buildOCIImage nixpkgsCross.${system}.aarch64-darwin;
});

nixosModules.drasl = {
Expand Down

0 comments on commit dcc124b

Please sign in to comment.