feat: add support for multiple languages (#51) #37
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: Build and Publish | |
on: | |
push: | |
branches: ["main"] | |
release: | |
types: [created] | |
env: | |
DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }} | |
DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }} | |
IMAGE_NAME: ${{ secrets.DOCKERHUB_USERNAME }}/hxckr-core | |
jobs: | |
build-and-push: | |
runs-on: ubuntu-latest | |
strategy: | |
matrix: | |
arch: [amd64, arm64] | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v3 | |
- name: Install Nix | |
uses: cachix/install-nix-action@v20 | |
with: | |
nix_path: nixpkgs=channel:nixos-unstable | |
extra_nix_config: | | |
experimental-features = nix-command flakes | |
accept-flake-config = true | |
keep-outputs = true | |
keep-derivations = true | |
- name: Setup Nix caching | |
uses: actions/cache@v3 | |
with: | |
path: | | |
~/.cache/nix | |
key: ${{ runner.os }}-nix-${{ matrix.arch }}-${{ hashFiles('**/build-image.nix', '**/Cargo.lock') }} | |
restore-keys: | | |
${{ runner.os }}-nix-${{ matrix.arch }}- | |
- name: Build with Nix | |
run: | | |
export NIX_BUILD_CORES=$(nproc) | |
nix-build build-image.nix -A ${{ matrix.arch }} -o result-${{ matrix.arch }} | |
ls -l result-${{ matrix.arch }} | |
env: | |
NIX_BUILD_CORES: ${{ steps.cores.outputs.count }} | |
- name: Load image into Docker | |
run: docker load < result-${{ matrix.arch }} | |
- name: Verify image contents and entrypoint | |
run: | | |
docker run --rm hxckr-core:${{ matrix.arch }}-latest ls -l /app || echo "Failed to list /app contents" | |
docker run --rm hxckr-core:${{ matrix.arch }}-latest ls -l /app/migrations || echo "Failed to list migrations" | |
docker run --rm hxckr-core:${{ matrix.arch }}-latest cat /app/entrypoint.sh || echo "Failed to cat entrypoint.sh" | |
docker run --rm hxckr-core:${{ matrix.arch }}-latest diesel --version || echo "Failed to get diesel version" | |
- name: Login to DockerHub | |
uses: docker/login-action@v2 | |
with: | |
username: ${{ env.DOCKERHUB_USERNAME }} | |
password: ${{ env.DOCKERHUB_TOKEN }} | |
- name: Tag and push Docker image | |
run: | | |
TAG=${{ github.event_name == 'release' && 'main' || 'dev' }} | |
ARCH=${{ matrix.arch }} | |
docker tag hxckr-core:$ARCH-latest ${{ env.IMAGE_NAME }}:$TAG-$ARCH | |
docker push ${{ env.IMAGE_NAME }}:$TAG-$ARCH | |
# Print image details | |
docker inspect ${{ env.IMAGE_NAME }}:$TAG-$ARCH | |
- name: Print image size and details | |
run: | | |
docker image ls hxckr-core:${{ matrix.arch }}-latest | |
docker history hxckr-core:${{ matrix.arch }}-latest | |
- name: Print image info | |
run: | | |
TAG=${{ github.event_name == 'release' && 'main' || 'dev' }} | |
docker inspect ${{ env.IMAGE_NAME }}:$TAG-${{ matrix.arch }} | |
create-manifest: | |
needs: build-and-push | |
runs-on: ubuntu-latest | |
steps: | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v1 | |
- name: Login to DockerHub | |
uses: docker/login-action@v2 | |
with: | |
username: ${{ env.DOCKERHUB_USERNAME }} | |
password: ${{ env.DOCKERHUB_TOKEN }} | |
- name: Create and push manifest | |
run: | | |
TAG=${{ github.event_name == 'release' && 'main' || 'dev' }} | |
docker manifest create ${{ env.IMAGE_NAME }}:$TAG \ | |
--amend ${{ env.IMAGE_NAME }}:$TAG-amd64 \ | |
--amend ${{ env.IMAGE_NAME }}:$TAG-arm64 | |
docker manifest annotate ${{ env.IMAGE_NAME }}:$TAG ${{ env.IMAGE_NAME }}:$TAG-amd64 --os linux --arch amd64 | |
docker manifest annotate ${{ env.IMAGE_NAME }}:$TAG ${{ env.IMAGE_NAME }}:$TAG-arm64 --os linux --arch arm64 --variant v8 | |
docker manifest push --purge ${{ env.IMAGE_NAME }}:$TAG | |
# Inspect individual images | |
docker buildx imagetools inspect ${{ env.IMAGE_NAME }}:$TAG-amd64 | |
docker buildx imagetools inspect ${{ env.IMAGE_NAME }}:$TAG-arm64 | |
# Inspect manifest | |
docker buildx imagetools inspect ${{ env.IMAGE_NAME }}:$TAG | |
- name: Verify manifest | |
run: | | |
TAG=${{ github.event_name == 'release' && 'main' || 'dev' }} | |
docker manifest inspect ${{ env.IMAGE_NAME }}:$TAG |