Skip to content

Commit

Permalink
Reproducible release process
Browse files Browse the repository at this point in the history
  • Loading branch information
sgreben committed Nov 2, 2018
1 parent 188d7b2 commit 54d40ee
Show file tree
Hide file tree
Showing 9 changed files with 193 additions and 15 deletions.
5 changes: 5 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
*
!/src/
!/pom.xml
!/settings.xml
!/gpg-params
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
target/
/target/
/settings.xml
/gpg-params
/gpg-home
44 changes: 44 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
FROM alpine:3.8 AS download-maven
RUN apk add --no-cache curl
ARG MAVEN_VERSION=3.5.4
ARG SHA=ce50b1c91364cb77efe3776f756a6d92b76d9038b0a0782f7d53acf1e997a14d
ARG BASE_URL=https://apache.osuosl.org/maven/maven-3/${MAVEN_VERSION}/binaries
RUN mkdir -p /app /app/ref \
&& curl -fsSL -o /maven.tar.gz ${BASE_URL}/apache-maven-"${MAVEN_VERSION}"-bin.tar.gz \
&& echo "${SHA} /maven.tar.gz" | sha256sum -c - \
&& tar -xzf /maven.tar.gz -C /app --strip-components=1

FROM alpine:3.8 AS generate-gpg-key
RUN apk add --no-cache gnupg1
ENV GNUPGHOME=/key
RUN mkdir -p "${GNUPGHOME}"
COPY gpg-params /gpg-params
RUN gpg --batch --gen-key /gpg-params

FROM openjdk:9-jdk-slim AS build-jar
RUN ln -s /etc/java-9-openjdk /usr/lib/jvm/java-9-openjdk-$(dpkg --print-architecture)/conf
ENV MAVEN_HOME /usr/share/maven
ENV MAVEN_CONFIG "${HOME}/.m2"
COPY --from=download-maven /app "${MAVEN_HOME}"
RUN ln -s "${MAVEN_HOME}"/bin/mvn /usr/bin/mvn
# Build app
ENV APP_SOURCE /app
WORKDIR /app
COPY pom.xml pom.xml
RUN mvn validate dependency:go-offline
COPY src src
RUN mvn clean compile test
RUN mvn -DskipTests=true package

FROM build-jar AS build-signed-jar
RUN apt-get update && apt-get install -y gnupg1 && rm -rf /var/lib/apt/lists/*
ENV GNUPGHOME=/key
COPY --from=generate-gpg-key /key "${GNUPGHOME}"
COPY settings.xml /root/.m2/
RUN mvn -o -DskipTests=true verify

FROM build-signed-jar AS deploy-snapshot
RUN mvn -DskipTests=true deploy

FROM build-signed-jar AS deploy-release
RUN mvn -DskipTests=true deploy
22 changes: 22 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
.PHONY: jar signed-jar export-gpg-key deploy-release deploy-snapshot publish-gpg-key

jar:
mkdir -p target
docker-compose build build-jar
docker-compose run --rm build-jar
deploy-release: publish-gpg-key
docker-compose build deploy-release
deploy-snapshot: publish-gpg-key
docker-compose build deploy-snapshot
signed-jar: export-gpg-key
mkdir -p target
docker-compose build build-signed-jar
docker-compose run --rm build-signed-jar
publish-gpg-key: export-gpg-key
docker-compose build publish-gpg-key
docker-compose run --rm publish-gpg-key
export-gpg-key: gpg-home
gpg-home:
mkdir -p gpg-home
docker-compose build export-gpg-key
docker-compose run --rm export-gpg-key
18 changes: 9 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

Write regexes as **plain Java code**. Unlike opaque regex strings, commenting your expressions and reusing regex fragments is straightforward.

The **regex-builder** library is implemented as a light-weight wrapper around `java.util.regex`. It consists of three main components: the expression builder `Re`, its fluent API equivalent `FluentRe`, and the character class builder `CharClass`. The components are introduced in the examples below as well as in the API overview tables at the end of this document.
The **regex-builder** library is implemented as a light-weight wrapper around `java.util.regex`. It consists of three main components: the expression builder `Re`, its fluent API equivalent `FluentRe`, and the character class builder `CharClass`. The components are introduced in the examples below as well as in the API overview tables at the end of this document.

There's a [discussion](https://www.reddit.com/r/java/comments/4tyk90/github_sgrebenregexbuilder_write_regular/) of this project over on the Java reddit.
There's a [discussion](https://www.reddit.com/r/java/comments/4tyk90/github_sgrebenregexbuilder_write_regular/) of this project over on the Java subreddit.

- [Installation / Maven dependency](#maven-dependency)
- [Examples](#examples)
Expand All @@ -24,7 +24,7 @@ There's a [discussion](https://www.reddit.com/r/java/comments/4tyk90/github_sgre
<dependency>
<groupId>com.github.sgreben</groupId>
<artifactId>regex-builder</artifactId>
<version>1.0.1-SNAPSHOT</version>
<version>1.0.1</version>
</dependency>
```

Expand Down Expand Up @@ -94,7 +94,7 @@ The above example can also be expressed using the fluent API implemented in `Flu
```java
import static com.github.sgreben.regex_builder.CharClass.*;
import com.github.sgreben.regex_builder.FluentRe;
```
```

```java
CaptureGroup ip, client, user, dateTime, method, request, protocol, responseCode, size;
Expand Down Expand Up @@ -168,7 +168,7 @@ assertEquals("22", m.group(second));
```java
Expression threeHexDigits = repeat(hexDigit(), 3);
CaptureGroup hexValue = capture(
threeHexDigits, // #FFF
threeHexDigits, // #FFF
optional(threeHexDigits) // #FFFFFF
);
Expression hexColor = sequence(
Expand All @@ -190,19 +190,19 @@ assertEquals("1bf", m.group(hexValue));

To reuse an expression cleanly, it should be packaged as a class. To access the capture groups contained in the expression,
each capture group should be exposed as a final field or method.

To allow the resulting object to be used as an expression, `regex-builder` provides a utility class `ExpressionWrapper`,
which exposes a method `setExpression(Expression expr)` and implements the `Expresssion` interface.

```java
import com.github.sgreben.regex_builder.ExpressionWrapper;
```

To use the class, simply extend it and call `setExpression` in your constructor or initialization block.
To use the class, simply extend it and call `setExpression` in your constructor or initialization block.
You can then pass it to any `regex-builder` method that expects an `Expression`.

### Reusable Apache log expression
Using `ExpressionWrapper`, we can package the Apache log
Using `ExpressionWrapper`, we can package the Apache log
example above as follows:
```java
public class ApacheLog extends ExpressionWrapper {
Expand Down Expand Up @@ -305,4 +305,4 @@ public static boolean sameIP(String twoLogs) {
| verticalWhitespaceChar() | \v |
| nonVerticalWhitespaceChar() | \V |
| horizontalWhitespaceChar() | \h |
| nonHorizontalWhitespaceChar()| \H |
| nonHorizontalWhitespaceChar()| \H |
67 changes: 67 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
version: '3.4'
services:
export-gpg-key:
image: regex-builder:export-gpg-key
build:
context: .
target: generate-gpg-key
volumes:
- type: bind
source: ./gpg-home
target: /output
entrypoint: /bin/sh
command:
- -euxc
- cd "$$GNUPGHOME" && cp -rv . /output
publish-gpg-key:
image: regex-builder:export-gpg-key
build:
context: .
target: generate-gpg-key
entrypoint: /bin/sh
command:
- -euxc
- |
KEY_ID=$$(gpg --list-keys --with-colons | awk -F: '/^pub:/ { print $$5 }');
gpg --keyserver hkp://pool.sks-keyservers.net --send-keys "$$KEY_ID" &
gpg --keyserver hkp://eu.pool.sks-keyservers.net --send-keys "$$KEY_ID" &
gpg --keyserver hkp://na.pool.sks-keyservers.net --send-keys "$$KEY_ID" &
gpg --keyserver hkp://oc.pool.sks-keyservers.net --send-keys "$$KEY_ID" &
gpg --keyserver hkp://keyserver.ubuntu.com --send-keys "$$KEY_ID" &
wait
build-jar:
image: regex-builder:build-jar
build:
context: .
target: build-jar
volumes:
- type: bind
source: ./target
target: /output
entrypoint: /bin/sh
command:
- -euxc
- cp -rv target/*.jar /output
build-signed-jar:
image: regex-builder:build-signed-jar
build:
context: .
target: build-signed-jar
volumes:
- type: bind
source: ./target
target: /output
entrypoint: /bin/sh
command:
- -euxc
- cp -rv target/*.jar /output
deploy-release:
image: regex-builder:release
build:
context: .
target: deploy-release
deploy-snapshot:
image: regex-builder:snapshot
build:
context: .
target: deploy-snapshot
6 changes: 6 additions & 0 deletions gpg-params.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Key-Type: default
Subkey-Type: default
Name-Real: TODO: NAME
Name-Email: TODO: EMAIL
Expire-Date: 0
Passphrase: TODO: PASSPHRASE
20 changes: 15 additions & 5 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<groupId>com.github.sgreben</groupId>
<artifactId>regex-builder</artifactId>
<packaging>jar</packaging>
<version>1.0.1-SNAPSHOT</version>
<version>1.0.1</version>
<name>${project.groupId}:${project.artifactId}</name>
<description>Construct regular expressions as pure Java code.</description>
<url>https://github.com/sgreben/regex-builder/</url>
Expand All @@ -26,9 +26,6 @@
<url>http://www.opensource.org/licenses/mit-license.php</url>
</license>
</licenses>
<prerequisites>
<maven>3.0</maven>
</prerequisites>
<distributionManagement>
<snapshotRepository>
<id>ossrh</id>
Expand Down Expand Up @@ -68,6 +65,19 @@
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.9.1</version>
<executions>
<execution>
<id>attach-javadocs</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.sonatype.plugins</groupId>
<artifactId>nexus-staging-maven-plugin</artifactId>
Expand Down Expand Up @@ -95,4 +105,4 @@
</plugin>
</plugins>
</build>
</project>
</project>
21 changes: 21 additions & 0 deletions settings.xml.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<settings>
<servers>
<server>
<id>ossrh</id>
<username>TODO: USERNAME</username>
<password>TODO: PASSWORD</password>
</server>
</servers>
<profiles>
<profile>
<id>ossrh</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<properties>
<gpg.executable>gpg1</gpg.executable>
<gpg.passphrase>TODO: PASSPHRASE</gpg.passphrase>
</properties>
</profile>
</profiles>
</settings>

0 comments on commit 54d40ee

Please sign in to comment.