mirror of
https://github.com/rjNemo/rentease.git
synced 2026-06-12 13:46:51 +00:00
ci: consolidate to single workflow and add Docker layer caching; dev: optimize Dockerfile.dev for cache
This commit is contained in:
parent
90d82fb79b
commit
8ea3dbe553
2 changed files with 60 additions and 34 deletions
73
.github/workflows/ci.yml
vendored
73
.github/workflows/ci.yml
vendored
|
|
@ -6,41 +6,62 @@ on:
|
||||||
- main
|
- main
|
||||||
pull_request:
|
pull_request:
|
||||||
branches:
|
branches:
|
||||||
- main
|
- "**"
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
build:
|
checks:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
env:
|
env:
|
||||||
GO111MODULE: on
|
NAME: rentease
|
||||||
|
PORT: 8000
|
||||||
|
DB_USER: ci
|
||||||
|
DB_NAME: villafleurie
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout code
|
- name: Checkout
|
||||||
uses: actions/checkout@v3
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
- name: Set up Go
|
- name: Set up Docker Buildx
|
||||||
uses: actions/setup-go@v5
|
uses: docker/setup-buildx-action@v3
|
||||||
|
|
||||||
|
- name: Build dev image (cached)
|
||||||
|
uses: docker/build-push-action@v6
|
||||||
with:
|
with:
|
||||||
go-version: 1.23
|
context: .
|
||||||
|
file: Dockerfile.dev
|
||||||
|
tags: ${{ env.NAME }}:dev
|
||||||
|
load: true
|
||||||
|
cache-from: type=gha,scope=dev
|
||||||
|
cache-to: type=gha,scope=dev,mode=max
|
||||||
|
|
||||||
- name: Install dependencies
|
- name: Start dev container (background)
|
||||||
run: |
|
run: |
|
||||||
go mod download
|
docker run -d \
|
||||||
|
--name ${NAME} \
|
||||||
|
-v "$GITHUB_WORKSPACE":/app \
|
||||||
|
-v /app/tmp \
|
||||||
|
${NAME}:dev sleep infinity
|
||||||
|
|
||||||
- name: Lint code
|
- name: Make format
|
||||||
|
run: make format
|
||||||
|
|
||||||
|
- name: Make lint
|
||||||
|
run: make lint
|
||||||
|
|
||||||
|
- name: Make test
|
||||||
|
run: make test
|
||||||
|
|
||||||
|
- name: Stop container
|
||||||
|
if: always()
|
||||||
run: |
|
run: |
|
||||||
go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest
|
docker logs ${NAME} || true
|
||||||
golangci-lint run
|
docker stop ${NAME} || true
|
||||||
|
|
||||||
- name: Run tests
|
- name: Build production image (cached, push only)
|
||||||
run: |
|
if: github.event_name == 'push'
|
||||||
go test ./...
|
uses: docker/build-push-action@v6
|
||||||
|
with:
|
||||||
# - name: Run Gosec Security Scanner
|
context: .
|
||||||
# uses: securego/gosec@master
|
file: Dockerfile
|
||||||
# with:
|
tags: ${{ env.NAME }}:latest
|
||||||
# args: ./...
|
cache-from: type=gha,scope=prod
|
||||||
|
cache-to: type=gha,scope=prod,mode=max
|
||||||
- name: Build Docker image
|
|
||||||
run: |
|
|
||||||
docker build -t rentease .
|
|
||||||
|
|
|
||||||
|
|
@ -2,19 +2,24 @@
|
||||||
FROM golang:1.24-alpine AS builder
|
FROM golang:1.24-alpine AS builder
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|
||||||
RUN apk update && apk add --no-cache build-base
|
RUN apk add --no-cache build-base
|
||||||
|
|
||||||
|
# Install tooling early so it stays cached across source changes
|
||||||
|
RUN go install github.com/air-verse/air@latest \
|
||||||
|
&& go install github.com/a-h/templ/cmd/templ@latest
|
||||||
|
|
||||||
|
# Leverage module cache
|
||||||
COPY go.mod go.sum ./
|
COPY go.mod go.sum ./
|
||||||
RUN go mod download
|
RUN --mount=type=cache,target=/go/pkg/mod \
|
||||||
|
go mod download
|
||||||
|
|
||||||
|
# Copy the rest of the sources
|
||||||
COPY . .
|
COPY . .
|
||||||
|
|
||||||
RUN go build -ldflags="-s -w" -o rentease main.go
|
# Build once (helps verify builds and speeds CI with cache)
|
||||||
|
RUN --mount=type=cache,target=/root/.cache/go-build \
|
||||||
# Install air and templ for live reload and templating in dev
|
--mount=type=cache,target=/go/pkg/mod \
|
||||||
RUN go install github.com/air-verse/air@latest \
|
go build -ldflags="-s -w" -o rentease main.go
|
||||||
&& go install github.com/a-h/templ/cmd/templ@latest \
|
|
||||||
&& rm -rf /go/pkg/mod /root/.cache/go-build
|
|
||||||
|
|
||||||
# ----------- Dev Stage -----------
|
# ----------- Dev Stage -----------
|
||||||
FROM golang:1.24-alpine AS dev
|
FROM golang:1.24-alpine AS dev
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue