Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into feature/templ
Browse files Browse the repository at this point in the history
  • Loading branch information
applejag committed Mar 27, 2024
2 parents 6a69e44 + 3f89c0e commit 7186b55
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 58 deletions.
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ build
# Files not needed during builds
.dockerignore
.gitignore
Dockerfile
Earthfile
**/*.md
**/*.license
Expand Down
24 changes: 24 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# SPDX-FileCopyrightText: 2023 Risk.Ident GmbH <[email protected]>
#
# SPDX-License-Identifier: CC0-1.0

FROM golang:1.21.5-alpine AS build
WORKDIR /jelease
COPY go.mod go.sum ./
RUN go mod download

ARG VERSION=latest
COPY . .
RUN go test -v ./... \
&& go build \
-ldflags "-X github.com/RiskIdent/jelease/cmd.appVersion=$VERSION" \
-o build/jelease main.go

FROM alpine
RUN apk add --no-cache ca-certificates git
COPY --from=build /jelease/build/jelease /usr/local/bin/
CMD ["jelease", "serve"]
USER 10000
LABEL org.opencontainers.image.source=https://github.com/RiskIdent/jelease
LABEL org.opencontainers.image.description="Automatically create software update PRs and Jira tickets using newreleases.io webhooks."
LABEL org.opencontainers.image.licenses=GPL-3.0-or-later
40 changes: 0 additions & 40 deletions Earthfile

This file was deleted.

20 changes: 6 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -146,23 +146,15 @@ go generate

## Building the application and docker image

The application uses [earthly](https://earthly.dev/get-earthly) for building
and pushing a docker image.

After installing earthly, the image can be built by running

```bash
earhtly +docker

# if you want to push a new image version
earhtly --push +docker --VERSION=v0.4.1
```
VERSION=v0.4.1

You can also persist build flags in a `.env` file, e.g:
podman build . -t ghcr.io/riskident/jelease:${VERSION} --build-arg VERSION=${VERSION}
podman tag ghcr.io/riskident/jelease:{${VERSION},latest}

```properties
# Inside the .env file
REGISTRY=docker.io/my-username
podman login ghcr.io
podman push ghcr.io/riskident/jelease:${VERSION}
podman push ghcr.io/riskident/jelease:latest
```

## Releasing
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

module github.com/RiskIdent/jelease

go 1.21.3
go 1.21.5

require (
github.com/a-h/templ v0.2.408
Expand Down
8 changes: 5 additions & 3 deletions pkg/patch/patch.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"io"
"os"
"path/filepath"
"slices"

"github.com/RiskIdent/jelease/pkg/config"
"github.com/RiskIdent/jelease/pkg/util"
Expand All @@ -46,14 +47,16 @@ type TemplateContextRegex struct {
func ApplyMany(repoDir string, patches []config.PackageRepoPatch, tmplCtx TemplateContext) error {
for _, p := range patches {
if err := Apply(repoDir, p, tmplCtx); err != nil {
return err
return fmt.Errorf("file %q: %w", p.File, err)
}
}
return nil
}

// Apply applies a single patch to the repository.
func Apply(repoDir string, patch config.PackageRepoPatch, tmplCtx TemplateContext) error {
log.Debug().Str("file", patch.File).Msg("Patching file.")

// TODO: Check that the patch path doesn't go outside the repo dir.
// For example, reject stuff like "../../../somefile.txt"
path := filepath.Join(repoDir, patch.File)
Expand All @@ -71,7 +74,6 @@ func Apply(repoDir string, patch config.PackageRepoPatch, tmplCtx TemplateContex
return fmt.Errorf("write patch: %w", err)
}

log.Debug().Str("file", patch.File).Msg("Patched file.")
return nil
}

Expand Down Expand Up @@ -175,7 +177,7 @@ func readLinesFromReader(r io.Reader) ([][]byte, error) {
var lines [][]byte
scanner := bufio.NewScanner(r)
for scanner.Scan() {
lines = append(lines, scanner.Bytes())
lines = append(lines, slices.Clone(scanner.Bytes()))
}
if err := scanner.Err(); err != nil {
return nil, err
Expand Down

0 comments on commit 7186b55

Please sign in to comment.