diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..63ed02a --- /dev/null +++ b/.github/workflows/release.yml @@ -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<> $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 diff --git a/Dockerfile b/Dockerfile index 65ccd65..1b1d5c3 100644 --- a/Dockerfile +++ b/Dockerfile @@ -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"] diff --git a/Dockerfile.static b/Dockerfile.build similarity index 63% rename from Dockerfile.static rename to Dockerfile.build index 27e0ac0..beedfcc 100644 --- a/Dockerfile.static +++ b/Dockerfile.build @@ -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 \ @@ -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 / diff --git a/do_release.sh b/do_release.sh index 607c5d1..b92a26d 100755 --- a/do_release.sh +++ b/do_release.sh @@ -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 diff --git a/shard.lock b/shard.lock index 667d05e..d585340 100644 --- a/shard.lock +++ b/shard.lock @@ -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 diff --git a/site/install.sh b/site/install.sh index 6d73c6f..c399005 100644 --- a/site/install.sh +++ b/site/install.sh @@ -7,7 +7,6 @@ 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 @@ -15,7 +14,7 @@ trap 'rm -rf "${TEMP_DIR}"' EXIT ERR INT TERM # Ensure cleanup # 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 @@ -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..." @@ -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