Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
122 changes: 122 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
name: Build release

on:
workflow_dispatch:
push:
tags:
- "v*"

permissions:
contents: write
packages: write
attestations: write
id-token: write

env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

jobs:
release:
runs-on: ubuntu-latest
services:
registry:
image: registry:2
ports:
- 5000:5000
# credentials improve quotas
#credentials:
# username: ${{ secrets.DH_USER }}
# password: ${{ secrets.DH_TOKEN }}

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Install git-cliff
uses: taiki-e/install-action@git-cliff

- name: Get release notes
id: notes
run: |
notes=$(git cliff -l -s all)
echo "notes<<EOF" >> $GITHUB_OUTPUT
echo $notes >> $GITHUB_OUTPUT
echo EOF >> $GITHUB_OUTPUT

- name: Set up QEMU
uses: docker/setup-qemu-action@v3
with:
platforms: arm64

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
with:
# to have access to the registry service
driver-opts: network=host

- name: Build binaries
uses: docker/build-push-action@v6
with:
context: .
file: Dockerfile.build
platforms: linux/amd64,linux/arm64
outputs: type=local,dest=bin

- name: List and rename binaries
run: |
ls -Rl bin
for arch in `ls -d bin/linux* | cut -f 2 -d _`; do
cp -v bin/linux_${arch}/grafito bin/linux_${arch}/grafito-static-linux-${arch}
done

- name: Build docker image
uses: docker/build-push-action@v6
with:
labels: |
org.opencontainers.image.source=https://github.com/${{ github.repository }}
org.opencontainers.image.version=${{ github.ref_name }}
context: .
file: Dockerfile
platforms: linux/amd64,linux/arm64
tags: localhost:5000/grafito:latest
outputs: type=registry,push=true,rewrite-timestamp=true

- name: Inspect images
run: |
docker buildx imagetools inspect localhost:5000/grafito:latest --format "{{json .Image}}"

- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Upload images to ghcr.io
run: |
date
docker -D buildx imagetools create localhost:5000/grafito:latest \
--tag ghcr.io/${{ github.repository }}:latest \
--tag ghcr.io/${{ github.repository }}:${{ github.ref_name }}

- name: Upload release
uses: softprops/action-gh-release@v2
with:
name: Release ${{ github.ref_name }}
body: ${{ steps.notes.outputs.notes }}
fail_on_unmatched_files: true
files: |
bin/linux_amd64/grafito-static-linux-amd64
bin/linux_arm64/grafito-static-linux-arm64

#- name: Publish AUR package
# uses: ulises-jeremias/github-actions-aur-publish@5a3661ae205f5ef93460c0c9fa1117c727b342bf
# with:
# pkgname: my-awesome-package
# pkgbuild: ./PKGBUILD
# commit_username: ${{ secrets.AUR_USERNAME }}
# commit_email: ${{ secrets.AUR_EMAIL }}
# ssh_private_key: ${{ secrets.AUR_SSH_PRIVATE_KEY }}
# commit_message: Update AUR package
# ssh_keyscan_types: rsa,dsa,ecdsa,ed25519
# update_pkgver: false
9 changes: 3 additions & 6 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
FROM ubuntu:latest
ARG ARCH=amd64
ARG VERSION
LABEL org.opencontainers.image.source="https://github.com/ralsina/grafito"
LABEL org.opencontainers.image.version="${VERSION}"

ARG TARGETARCH
RUN apt update && apt -y upgrade && apt -y clean && apt install -y \
systemd


RUN ln -s /usr/share/zoneinfo/UTC /etc/localtime -f
COPY bin/grafito-static-linux-${ARCH} /usr/local/bin/grafito
COPY ./bin/linux_${TARGETARCH}/grafito /usr/local/bin/grafito
CMD ["/usr/local/bin/grafito", "-b", "0.0.0.0"]
11 changes: 10 additions & 1 deletion Dockerfile.static → Dockerfile.build
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM --platform=${TARGETPLATFORM:-linux/amd64} alpine:edge AS build
FROM alpine:edge AS build
RUN apk add --no-cache \
crystal \
shards \
Expand All @@ -16,3 +16,12 @@ RUN apk add --no-cache \
zlib-static \
xz-dev \
xz-static

COPY . /app

RUN cd /app \
&& shards build --static --release \
&& strip bin/grafito

FROM scratch
COPY --from=build /app/bin/grafito /
5 changes: 0 additions & 5 deletions do_release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,10 @@ PKGNAME=$(basename "$PWD")
VERSION=$(git cliff --bumped-version --unreleased |cut -dv -f2)

sed "s/^version:.*$/version: $VERSION/g" -i shard.yml
sed "s/^VERSION=.*$/VERSION=\"$VERSION\" # Hardcoded version/g" -i site/install.sh
./build_static.sh
git add shard.yml
git add site/install.sh
# hace lint test
git cliff --bump -o
git commit -a -m "bump: Release v$VERSION"
git tag "v$VERSION"
git push --tags
gh release create "v$VERSION" "bin/$PKGNAME-static-linux-amd64" "bin/$PKGNAME-static-linux-arm64" --title "Release v$VERSION" --notes "$(git cliff -l -s all)"
bash -x upload_docker.sh
bash -x do_aur.sh
2 changes: 1 addition & 1 deletion shard.lock
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ shards:

baked_file_handler:
git: https://github.com/ralsina/baked_file_handler.git
version: 0.1.0+git.commit.29280afeb2301e2c60ca84812f9c3b47e7505304
version: 0.1.5

baked_file_system:
git: https://github.com/ralsina/baked_file_system.git
Expand Down
13 changes: 11 additions & 2 deletions site/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,14 @@ INSTALL_DIR="/usr/local/bin"
SERVICE_DIR="/etc/systemd/system"
SERVICE_NAME="grafito.service"
BINARY_NAME="grafito"
VERSION="0.16.0" # Hardcoded version
TEMP_DIR=$(mktemp -d)
trap 'rm -rf "${TEMP_DIR}"' EXIT ERR INT TERM # Ensure cleanup

# --- Helper Functions ---

# Check if required commands are available
check_dependencies() {
local deps=("curl" "tar" "systemctl") # Removed jq
local deps=("curl" "tar" "systemctl" "grep" "tr") # Removed jq
for dep in "${deps[@]}"; do
if ! command -v "$dep" &> /dev/null; then
echo "Error: Required dependency '$dep' is not installed." >&2
Expand Down Expand Up @@ -44,6 +43,10 @@ get_architecture() {
esac
}

get_version() {
curl -s https://api.github.com/repos/ralsina/grafito/releases/latest | grep -o '"v[0-9]*\.[0-9]*\.[0-9]*"' | tr -d '"'
}

# --- Main Installation Logic ---

echo "Starting Grafito installation..."
Expand All @@ -61,6 +64,12 @@ check_dependencies
ARCH=$(get_architecture)
echo "Detected architecture: ${ARCH}"

# If version is not defined - find out the latest one
if test -z "$VERSION"; then
VERSION=$(get_version)
echo "The latest version is: ${VERSION}"
fi

# Construct download URL for the hardcoded version
echo "Using Grafito version: ${VERSION}"
ASSET_NAME="${BINARY_NAME}-static-linux-${ARCH}" # Asset name based on architecture
Expand Down