diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..00476df --- /dev/null +++ b/.dockerignore @@ -0,0 +1,8 @@ +.git +.gitignore +*.md +flake.nix +flake.lock +.envrc +.direnv +.claude diff --git a/.gitea/workflows/build.yaml b/.gitea/workflows/build.yaml new file mode 100644 index 0000000..f588f8f --- /dev/null +++ b/.gitea/workflows/build.yaml @@ -0,0 +1,48 @@ +name: Build and Push + +on: + push: + branches: + - master + +jobs: + test: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - uses: actions/setup-go@v5 + with: + go-version: '1.22' + + - name: Run tests + run: go test ./... + + build: + runs-on: ubuntu-latest + needs: test + steps: + - uses: actions/checkout@v4 + + - name: Set image tag + id: tag + run: | + TIMESTAMP=$(date +%Y%m%d%H%M%S) + SHA=$(echo ${{ github.sha }} | cut -c1-7) + echo "tag=${TIMESTAMP}-${SHA}" >> $GITHUB_OUTPUT + + - name: Build Docker image + run: | + docker build -t gitea.leeworks.dev/0xwheatyz/gitea-mobile:${{ steps.tag.outputs.tag }} . + docker tag gitea.leeworks.dev/0xwheatyz/gitea-mobile:${{ steps.tag.outputs.tag }} \ + gitea.leeworks.dev/0xwheatyz/gitea-mobile:latest + + - name: Login to Gitea registry + run: | + echo "${{ secrets.REGISTRY_PASSWORD }}" | docker login gitea.leeworks.dev \ + -u "${{ secrets.REGISTRY_USERNAME }}" --password-stdin + + - name: Push image + run: | + docker push gitea.leeworks.dev/0xwheatyz/gitea-mobile:${{ steps.tag.outputs.tag }} + docker push gitea.leeworks.dev/0xwheatyz/gitea-mobile:latest diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..029e1ca --- /dev/null +++ b/Dockerfile @@ -0,0 +1,16 @@ +# Stage 1: Build +FROM golang:1.22-alpine AS builder +WORKDIR /app +COPY go.mod go.sum ./ +RUN go mod download +COPY . . +RUN CGO_ENABLED=0 GOOS=linux go build -ldflags="-s -w" -o /gitea-mobile ./cmd/server + +# Stage 2: Runtime +FROM gcr.io/distroless/static:nonroot +COPY --from=builder /gitea-mobile /gitea-mobile +COPY static/ /static/ +COPY internal/templates/ /templates/ +EXPOSE 8080 +USER nonroot:nonroot +ENTRYPOINT ["/gitea-mobile"]