Skip to content

Commit 898d594

Browse files
committed
support output directory, add dockerfile and extend readme
1 parent 628e085 commit 898d594

7 files changed

Lines changed: 96 additions & 13 deletions

File tree

.dockerignore

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
Dockerfile
2+
.dockerignore
3+
study
4+
.idea
5+
.github
6+
.goreleaser*
7+
*.so
8+
*.cue
9+
seru
10+
test.sh
11+
README.md

Dockerfile

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
FROM eclipse-temurin:25 AS jre-build
2+
3+
RUN $JAVA_HOME/bin/jlink \
4+
--add-modules java.base,java.logging \
5+
--strip-debug \
6+
--no-man-pages \
7+
--no-header-files \
8+
--compress=2 \
9+
--output /javaruntime
10+
11+
12+
FROM golang:1.23.2-bookworm AS build
13+
ENV CUE_VERSION=v0.12.1
14+
15+
WORKDIR /app
16+
17+
COPY go.mod go.sum ./
18+
RUN go mod download
19+
20+
COPY . .
21+
22+
RUN CGO_ENABLED=1 GOOS=linux go generate ./...
23+
RUN CGO_ENABLED=1 GOOS=linux go build -o seru
24+
RUN go install cuelang.org/go/cmd/cue@${CUE_VERSION}
25+
26+
FROM debian:bookworm-slim
27+
28+
RUN apt-get update && apt-get install -y --no-install-recommends \
29+
ca-certificates \
30+
git \
31+
&& rm -rf /var/lib/apt/lists/*
32+
33+
ENV JAVA_HOME=/opt/java/openjdk
34+
ENV PATH="${JAVA_HOME}/bin:${PATH}"
35+
COPY --from=jre-build /javaruntime $JAVA_HOME
36+
37+
COPY --from=build /usr/local/go /usr/local/go
38+
COPY --from=build /go/bin/cue /usr/local/bin/cue
39+
ENV PATH="/usr/local/go/bin:${PATH}"
40+
41+
WORKDIR /app
42+
COPY --from=build /app/seru .
43+
COPY --from=build /app/cue.so .
44+
COPY --from=build /app/cue.jar .
45+
COPY --from=build /app/perses_deploy.jar .
46+
47+
ENTRYPOINT ["./seru"]

README.md

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,29 @@ SeRu currently supports:
1515
- Semantic reducers for languages
1616
- CUE
1717

18+
## Docker
19+
20+
You can use SeRu with our docker image.
21+
Use the following command to run a reduction with docker:
22+
```bash
23+
WORKDIR=/data docker run --rm -it -v $(pwd):${WORKDIR} mando9/seru -o ${WORKDIR} -i ${WORKDIR}/<input file> -t ${WORKDIR}/<test script>
24+
# e.g. to use in.cue and test.sh in the current working dir, run
25+
WORKDIR=/data docker run --rm -it -v $(pwd):${WORKDIR} mando9/seru -o ${WORKDIR} -i ${WORKDIR}/in.cue -t ${WORKDIR}/test.sh
26+
```
27+
28+
This will create a result directory with the prefix "seru_reduction" in your working directory.
29+
It contains the final result as well as the intermediate steps in subdirectories.
30+
1831
## Pre-requisites
1932

2033
> Steps 1 & 2 are only necessary while the repository are private
2134
> SeRu will download such dependencies automatically
2235
2336
1. Download Perses & CUE-specific extension (latest from the release page)
2437
1. [perses_deploy.jar](https://github.com/mandoway/seru/releases/download/v0.0.1-alpha/perses_deploy.jar)
38+
1. Compiled Perses & Vulcan as a executable JAR file
2539
2. [cue.jar](https://github.com/mandoway/seru/releases/download/v0.0.1-alpha/cue.jar)
40+
1. The CUE grammar in the form of a Perses language plugin
2641
2. Compile CUE-specific semantic reduction strategies
2742
1. Run
2843
```bash
@@ -31,7 +46,9 @@ SeRu currently supports:
3146
3. Make sure you have Java installed (for Perses)
3247

3348
## Run seru
34-
Run SeRu using Go or standalone
49+
50+
Run SeRu using Go or standalone
51+
3552
- `go run .`
3653
- `go build && ./seru`
3754
- Install from the release page
@@ -43,6 +60,7 @@ Run SeRu using Go or standalone
4360
| `--input <path>` | `-i` || path to input file |
4461
| `--test <path>` | `-t` || path to property testscript, a test script **must return 0** when the property holds and 1 (or any code) if the property is invalid |
4562
| `--lang <string>` | `-l` | | language of file, e.g. cue. Will be inferred from the file extension if omitted. |
63+
| `--out <string>` | `-o` | | define the output directory |
4664
| `--reducer <perses\|vulcan>` | `-r` | | either 'perses' OR 'vulcan' (default "perses"). Perses is faster, Vulcan can be more effective. |
4765
| `--enable-metrics` | `-m` | | store metrics as a json file |
4866
| `--strategy-isolation` | `-s` | | (*untested*) Activates strategy isolation.<br/> Modes: <br/>- Isolation (many candidates, slow): only one strategy will be applied before next iteration. This mode will apply only one semantic strategy and try to reduce all returned candidates using the syntactic reducer. <br/>- Strategy combination (**default**, much faster, less calls to syntactic reducer). In strategy combination, all strategies are applied and combined to one "best candidate". Then this single candidate will be reduced by the syntactic reducer. |

cmd/root.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ var rootCmd = &cobra.Command{
1515
Short: "A tool to reduce a program while maintaining a property",
1616
Long: `TODO`,
1717
Run: func(cmd *cobra.Command, args []string) {
18-
err := reduction.StartReductionProcess(flags.InputFile, flags.TestScript, flags.GivenLanguage, flags.UseStrategyIsolation, flags.EnableMetrics, flags.GetReducer(), flags.GetActiveStrategies())
18+
err := reduction.StartReductionProcess(flags.WorkDir, flags.InputFile, flags.TestScript, flags.GivenLanguage, flags.UseStrategyIsolation, flags.EnableMetrics, flags.GetReducer(), flags.GetActiveStrategies())
1919
if err != nil {
2020
log.Fatal(err)
2121
}
@@ -31,6 +31,9 @@ func init() {
3131
_ = rootCmd.MarkPersistentFlagRequired("test")
3232
_ = rootCmd.MarkPersistentFlagFilename("test")
3333

34+
rootCmd.PersistentFlags().StringVarP(&flags.WorkDir, "out", "o", "", "output directory")
35+
_ = rootCmd.MarkPersistentFlagFilename("out")
36+
3437
rootCmd.PersistentFlags().StringVarP(&flags.GivenLanguage, "lang", "l", "", "language of file, e.g. cue")
3538
rootCmd.PersistentFlags().StringVarP(&flags.SyntacticReducer, "reducer", "r", PersesReducer, "either 'perses' OR 'vulcan'")
3639

cmd/types.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@ const (
1414
)
1515

1616
type Flags struct {
17-
InputFile, TestScript, GivenLanguage string
18-
UseStrategyIsolation, EnableMetrics bool
19-
SyntacticReducer reductionType
20-
ActiveStrategies []int
17+
InputFile, TestScript, GivenLanguage, WorkDir string
18+
UseStrategyIsolation, EnableMetrics bool
19+
SyntacticReducer reductionType
20+
ActiveStrategies []int
2121
}
2222

2323
func (f Flags) GetReducer() syntactic.Reducer {

reduction/context/run_context.go

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,18 @@ import (
44
"crypto/md5"
55
"errors"
66
"fmt"
7+
"os"
8+
"path"
9+
"strconv"
10+
"time"
11+
712
"github.com/google/uuid"
813
"github.com/mandoway/seru/files"
914
"github.com/mandoway/seru/reduction/candidate"
1015
"github.com/mandoway/seru/reduction/logging"
1116
"github.com/mandoway/seru/reduction/metrics"
1217
"github.com/mandoway/seru/reduction/plugin"
1318
"github.com/mandoway/seru/reduction/syntactic"
14-
"os"
15-
"path"
16-
"strconv"
17-
"time"
1819
)
1920

2021
const RunContextFolderPrefix = "seru_reduction_"
@@ -210,11 +211,14 @@ func (ctx *RunContext) GetHash() [16]byte {
210211
return ctx.hashOfBest
211212
}
212213

213-
func NewRunContext(givenLanguage, inputFilePath, testScriptPath string, algorithmConfig AlgorithmConfig) (*RunContext, error) {
214+
func NewRunContext(givenLanguage, inputFilePath, testScriptPath, workDir string, algorithmConfig AlgorithmConfig) (*RunContext, error) {
214215
// Copy input files
215216
randId, _ := uuid.NewRandom()
216217
startTimeFormatted := time.Now().Format(time.RFC3339)
217218
reductionDir := fmt.Sprintf("%s%s_%s", RunContextFolderPrefix, startTimeFormatted, randId)
219+
if len(workDir) != 0 {
220+
reductionDir = path.Join(workDir, reductionDir)
221+
}
218222
err := os.Mkdir(reductionDir, 0750)
219223
if err != nil {
220224
return nil, NewRunContextErr(err)

reduction/entry.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,14 @@ import (
77
"github.com/mandoway/seru/util/collection"
88
)
99

10-
func StartReductionProcess(inputFile, testScript, givenLanguage string, isolation, enableMetrics bool, reducer syntactic.Reducer, activeStrategies *collection.Set) error {
10+
func StartReductionProcess(workDir, inputFile, testScript, givenLanguage string, isolation, enableMetrics bool, reducer syntactic.Reducer, activeStrategies *collection.Set) error {
1111
logging.Default.Println("SeRu - Syntactic & Semantic Reduction")
1212
logging.Default.Println()
1313
logging.Default.Printf("Creating new run context with (input=%s, test=%s, lang=%s)\n", inputFile, testScript, givenLanguage)
1414
algorithmConfig := context.NewAlgorithmConfig(isolation, reducer, activeStrategies)
1515
logging.Default.Printf("Running algorithm with config %s\n", algorithmConfig)
1616

17-
runCtx, err := context.NewRunContext(givenLanguage, inputFile, testScript, *algorithmConfig)
17+
runCtx, err := context.NewRunContext(givenLanguage, inputFile, testScript, workDir, *algorithmConfig)
1818
if err != nil {
1919
return err
2020
}

0 commit comments

Comments
 (0)