Skip to content

Commit

Permalink
Merge pull request #1 from IngmarStein/main
Browse files Browse the repository at this point in the history
Add a workflow to build Docker images with a static pixlet binary
  • Loading branch information
tavdog authored Feb 9, 2025
2 parents b55c965 + efb57dd commit bcbdb35
Show file tree
Hide file tree
Showing 12 changed files with 1,281 additions and 526 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ on:
jobs:
analyze:
name: Analyze
runs-on: ubuntu-22.04
runs-on: ubuntu-latest
permissions:
actions: read
contents: read
Expand All @@ -42,7 +42,7 @@ jobs:

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v2
uses: github/codeql-action/init@v3
with:
languages: ${{ matrix.language }}
# If you wish to specify custom queries, you can do so here or in a config file.
Expand All @@ -56,7 +56,7 @@ jobs:
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
# If this step fails, then you should remove it and run the build manually (see below)
- name: Autobuild
uses: github/codeql-action/autobuild@v2
uses: github/codeql-action/autobuild@v3

# ℹ️ Command-line programs to run using the OS shell.
# 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun
Expand All @@ -69,4 +69,4 @@ jobs:
# ./location_of_script_within_repo/buildscript.sh

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v2
uses: github/codeql-action/analyze@v3
86 changes: 71 additions & 15 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,20 @@ on:
tags:
- "v[0-9]+.[0-9]+.[0-9]+"

env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}

jobs:
lint:
runs-on: ubuntu-22.04
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@v4

- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: "1.22.2"
go-version: "1.23.6"

- name: Install buildifier
run: make install-buildifier
Expand All @@ -28,7 +32,7 @@ jobs:
name: Build and Test Release Artifacts
strategy:
matrix:
os: [ubuntu-22.04, macos-latest, windows-latest]
os: [ubuntu-24.04, macos-latest, windows-latest]

runs-on: ${{ matrix.os }}

Expand All @@ -39,7 +43,7 @@ jobs:
- name: Install Go
uses: actions/setup-go@v5
with:
go-version: "1.22.2"
go-version: "1.23.6"

- name: Install Node
uses: actions/setup-node@v4
Expand All @@ -59,7 +63,7 @@ jobs:
mingw-w64-x86_64-toolchain
- name: Install Linux dependencies
if: matrix.os == 'ubuntu-22.04'
if: matrix.os == 'ubuntu-24.04'
run: sudo ./scripts/setup-linux.sh

- name: Install macOS dependencies
Expand All @@ -71,8 +75,8 @@ jobs:
shell: msys2 {0}
run: |
set MSYSTEM=MINGW64
curl -LO https://repo.msys2.org/mingw/x86_64/mingw-w64-x86_64-libwebp-1.2.4-4-any.pkg.tar.zst
pacman -U --noconfirm mingw-w64-x86_64-libwebp-1.2.4-4-any.pkg.tar.zst
curl -LO https://repo.msys2.org/mingw/mingw64/mingw-w64-x86_64-libwebp-1.5.0-1-any.pkg.tar.zst
pacman -U --noconfirm mingw-w64-x86_64-libwebp-1.5.0-1-any.pkg.tar.zst
- name: Install frontend dependencies
run: npm install
Expand All @@ -82,7 +86,7 @@ jobs:

- name: Build Linux
run: make build
if: matrix.os == 'ubuntu-22.04'
if: matrix.os == 'ubuntu-24.04'

- name: Build macOS
run: make build
Expand All @@ -100,7 +104,7 @@ jobs:

- name: Test Linux
run: make test
if: matrix.os == 'ubuntu-22.04'
if: matrix.os == 'ubuntu-24.04'

- name: Test macOS
run: make test
Expand All @@ -119,7 +123,7 @@ jobs:
- name: Set pixlet version
id: vars
run: echo ::set-output name=tag::${GITHUB_REF#refs/*/}
if: matrix.os == 'ubuntu-22.04' || matrix.os == 'macos-latest'
if: matrix.os == 'ubuntu-24.04' || matrix.os == 'macos-latest'

- name: Set Windows pixlet version
id: windowsvars
Expand All @@ -130,7 +134,7 @@ jobs:
if: matrix.os == 'windows-latest'

- name: Build Release Linux
if: matrix.os == 'ubuntu-22.04'
if: matrix.os == 'ubuntu-24.04'
run: make release-linux
env:
PIXLET_VERSION: ${{ steps.vars.outputs.tag }}
Expand All @@ -153,14 +157,14 @@ jobs:
PIXLET_VERSION: ${{ steps.windowsvars.outputs.tag }}

- name: Upload Release Artifacts
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: release-artifacts
name: release-artifacts-${{ matrix.os }}
path: build

create-release:
name: Create Github Release
runs-on: ubuntu-22.04
runs-on: ubuntu-24.04
environment: release
needs: build-and-test-release
if: startsWith(github.ref, 'refs/tags/')
Expand All @@ -174,7 +178,7 @@ jobs:
- name: Install Go
uses: actions/setup-go@v5
with:
go-version: "1.22.2"
go-version: "1.23.6"

- name: Fetch Release Artifacts
uses: actions/download-artifact@v3
Expand All @@ -193,3 +197,55 @@ jobs:
GITHUB_TOKEN: ${{ secrets.TIDBYT_GITHUB_TOKEN }}
DISCORD_WEBHOOK_ID: ${{ secrets.DISCORD_WEBHOOK_ID }}
DISCORD_WEBHOOK_TOKEN: ${{ secrets.DISCORD_WEBHOOK_TOKEN }}

build-and-push-image:
runs-on: ubuntu-24.04
# Sets the permissions granted to the `GITHUB_TOKEN` for the actions in this job.
permissions:
contents: read
packages: write
attestations: write
id-token: write
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Log in to the Container registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=ref,event=branch
type=ref,event=pr
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=semver,pattern={{major}}
flavor: |
latest=true
prefix=
suffix=
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Build and push Docker image
id: push
uses: docker/build-push-action@v6
with:
context: .
push: true
platforms: linux/amd64,linux/arm64
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
- name: Generate artifact attestation
uses: actions/attest-build-provenance@v2
with:
subject-name: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME}}
subject-digest: ${{ steps.push.outputs.digest }}
push-to-registry: true
14 changes: 7 additions & 7 deletions .github/workflows/pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ on:

jobs:
lint:
runs-on: ubuntu-22.04
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@v4

- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: "1.22.2"
go-version: "1.23.6"

- name: Install buildifier
run: make install-buildifier
Expand All @@ -26,7 +26,7 @@ jobs:
name: Build and Test
strategy:
matrix:
os: [ubuntu-22.04, macos-latest, windows-latest]
os: [ubuntu-24.04, macos-latest, windows-latest]

runs-on: ${{ matrix.os }}

Expand All @@ -37,7 +37,7 @@ jobs:
- name: Install Go
uses: actions/setup-go@v5
with:
go-version: "1.22.2"
go-version: "1.23.6"

- name: Install Node
uses: actions/setup-node@v4
Expand All @@ -57,7 +57,7 @@ jobs:
mingw-w64-x86_64-toolchain
- name: Install Linux dependencies
if: matrix.os == 'ubuntu-22.04'
if: matrix.os == 'ubuntu-24.04'
run: sudo apt-get install -y libwebp-dev

- name: Install macOS dependencies
Expand All @@ -80,7 +80,7 @@ jobs:

- name: Build Linux
run: make build
if: matrix.os == 'ubuntu-22.04'
if: matrix.os == 'ubuntu-24.04'

- name: Build macOS
run: make build
Expand All @@ -98,7 +98,7 @@ jobs:

- name: Test Linux
run: make test
if: matrix.os == 'ubuntu-22.04'
if: matrix.os == 'ubuntu-24.04'

- name: Test macOS
run: make test
Expand Down
17 changes: 8 additions & 9 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
FROM golang:latest
FROM alpine:3.21 AS builder

RUN apt update && apt upgrade && apt install unzip libwebp-dev python3-venv python3-pip -y
RUN apk --no-cache add go npm libwebp-dev libwebp-static git make clang musl-dev
COPY . /pixlet
WORKDIR /pixlet
RUN npm install && npm run build && STATIC=1 make build

WORKDIR /tmp
RUN curl -fsSL https://deb.nodesource.com/setup_16.x | bash - && apt-get install -y nodejs && node -v
FROM scratch

#uncomment below if you want to compile during build
#RUN git clone https://github.com/tidbyt/pixlet.git
#WORKDIR /tmp/pixlet
#RUN npm install && npm run build && make build
COPY --from=builder /pixlet/pixlet /bin/pixlet

CMD ["bash"]
ENTRYPOINT ["/bin/pixlet"]
13 changes: 13 additions & 0 deletions Dockerfile.dev
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
FROM golang:latest

RUN apt update && apt upgrade && apt install unzip libwebp-dev python3-venv python3-pip -y

WORKDIR /tmp
RUN curl -fsSL https://deb.nodesource.com/setup_16.x | bash - && apt-get install -y nodejs && node -v

#uncomment below if you want to compile during build
#RUN git clone https://github.com/tidbyt/pixlet.git
#WORKDIR /tmp/pixlet
#RUN npm install && npm run build && make build

CMD ["bash"]
8 changes: 6 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,16 @@ GIT_COMMIT = $(shell git rev-list -1 HEAD)

ifeq ($(OS),Windows_NT)
BINARY = pixlet.exe
LDFLAGS = -ldflags="-s -extldflags=-static -X 'tidbyt.dev/pixlet/cmd.Version=$(GIT_COMMIT)'"
LDFLAGS = -ldflags="-s '-extldflags=-static -lsharpyuv' -X 'tidbyt.dev/pixlet/cmd.Version=$(GIT_COMMIT)'"
TAGS = -tags timetzdata
else
BINARY = pixlet
LDFLAGS = -ldflags="-X 'tidbyt.dev/pixlet/cmd.Version=$(GIT_COMMIT)'"
TAGS =
ifeq ($(STATIC),1)
LDFLAGS = -ldflags="-s -w -linkmode=external '-extldflags=-static -lsharpyuv' -X 'tidbyt.dev/pixlet/cmd.Version=$(GIT_COMMIT)'"
else
LDFLAGS = -ldflags="-X 'tidbyt.dev/pixlet/cmd.Version=$(GIT_COMMIT)'"
endif
endif

all: build
Expand Down
Loading

0 comments on commit bcbdb35

Please sign in to comment.