build and release htmgo site

This commit is contained in:
maddalax 2024-09-21 12:20:35 -05:00
parent 1f98f49735
commit 0210fa5019
3 changed files with 81 additions and 4 deletions

48
.github/workflows/release-site.yml vendored Normal file
View file

@ -0,0 +1,48 @@
name: Build and Deploy htmgo.dev
on:
push:
branches:
- master # Trigger on pushes to master
paths:
- 'htmgo-site/**' # Trigger only if files in this directory change
jobs:
build-and-push:
runs-on: self-hosted
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Log in to GitHub Container Registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Get short commit hash
id: vars
run: echo "::set-output name=short_sha::$(echo $GITHUB_SHA | cut -c1-7)"
- name: Build Docker image
run: |
cd ./htmgo-site && docker build -t ghcr.io/${{ github.repository_owner }}/htmgo-site:${{ steps.vars.outputs.short_sha }} .
- name: Log in to GitHub Container Registry
run: echo "${{ secrets.CR_PAT }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin
- name: Push Docker image
run: |
docker push ghcr.io/${{ github.repository_owner }}/htmgo-site:${{ steps.vars.outputs.short_sha }}
- name: Create Git tag
run: |
git config user.name "GitHub Actions"
git config user.email "actions@github.com"
git tag ${{ steps.vars.outputs.short_sha }}
git push origin ${{ steps.vars.outputs.short_sha }}

View file

@ -76,10 +76,7 @@ func (t Trigger) AddEvent(event TriggerEvent) Trigger {
func (t Trigger) ToString() string {
builder := strings.Builder{}
for i, e := range t.events {
eventName := e.event
if strings.HasPrefix(eventName, "htmx:") {
eventName = eventName[5:]
}
eventName := ToHtmxTriggerName(e.event)
builder.WriteString(eventName)
for _, m := range e.modifiers {
builder.WriteString(" ")

32
htmgo-site/Dockerfile Normal file
View file

@ -0,0 +1,32 @@
# Stage 1: Build the Go binary
FROM golang:1.22-alpine AS builder
# Set the working directory inside the container
WORKDIR /app
# Copy go.mod and go.sum files
COPY go.mod go.sum ./
# Download and cache the Go modules
RUN go mod download
# Copy the source code into the container
COPY . .
# Build the Go binary for Linux
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o server
# Stage 2: Create the smallest possible image
FROM gcr.io/distroless/base-debian11
# Set the working directory inside the container
WORKDIR /app
# Copy the Go binary from the builder stage
COPY --from=builder /app/server .
# Expose the necessary port (replace with your server port)
EXPOSE 3000
# Command to run the binary
CMD ["./server"]