Skip to content

Commit

Permalink
Build and publish docker images.
Browse files Browse the repository at this point in the history
  • Loading branch information
noeppi-noeppi committed Jun 29, 2024
1 parent e0a8032 commit 3368ec2
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 6 deletions.
18 changes: 18 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,28 @@ jobs:
with:
distribution: 'temurin'
java-version: '21'
- name: 'Build Docker Image'
run: |
docker build \
--pull --no-cache \
--build-arg="VERSION=${{ github.ref_name }}" \
-t "ghcr.io/moddingx/pastewrapper:${{ github.ref_name }}" \
-t "ghcr.io/moddingx/pastewrapper:latest" \
.
- name: 'Build'
run: |
./gradlew \
-Pversion=${{ github.ref_name }} \
-PmoddingxUsername=${{ secrets.PUBLISH_USER }} \
-PmoddingxPassword=${{ secrets.PUBLISH_PASSWORD }} \
build publish
- name: 'Login to package registry'
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: 'Publish Docker Image'
run: |
docker push "ghcr.io/moddingx/pastewrapper:${{ github.ref_name }}"
docker push "ghcr.io/moddingx/pastewrapper:latest"
12 changes: 12 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
FROM gradle:8-jdk21 AS build
ARG VERSION
COPY . /data
WORKDIR /data
RUN gradle -Pversion="${VERSION}" --no-daemon clean build
WORKDIR /dist
RUN tar --strip-components=1 -xf "/data/build/distributions/PasteWrapper-${VERSION}.tar"

FROM eclipse-temurin:21
COPY --from=build --link /dist/ /data/
ENV JAVA_OPTS="-server"
CMD [ "/data/bin/PasteWrapper", "--no-ssl", "--docker" ]
9 changes: 3 additions & 6 deletions src/main/java/org/moddingx/pastewrapper/PasteApi.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
package org.moddingx.pastewrapper;

import com.google.gson.*;
import org.moddingx.pastewrapper.route.CreateRoute;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.annotation.Nullable;
import java.io.IOException;
Expand All @@ -16,7 +13,7 @@

public class PasteApi {

private static final Logger logger = LoggerFactory.getLogger(PasteApi.class);
public static final int MAXIMUM_EXPIRATION = 60 * 60 * 24 * 365;

private static final Gson GSON;

Expand All @@ -35,12 +32,12 @@ public PasteApi(String token) {
}

public Paste createPaste(@Nullable String title, String content) throws IOException {
return this.createPaste(title, content, CreateRoute.EXPIRATION_ONE_YEAR);
return this.createPaste(title, content, MAXIMUM_EXPIRATION);
}

public Paste createPaste(@Nullable String title, String content, int expirationSeconds) throws IOException {
try {
expirationSeconds = Math.min(expirationSeconds, CreateRoute.EXPIRATION_ONE_YEAR);
expirationSeconds = Math.min(expirationSeconds, MAXIMUM_EXPIRATION);
JsonObject json = new JsonObject();
if (title != null) json.addProperty("description", title);
JsonArray sections = new JsonArray();
Expand Down

0 comments on commit 3368ec2

Please sign in to comment.