Skip to content

Commit

Permalink
feat: support run cache server in docker (#18)
Browse files Browse the repository at this point in the history
Co-authored-by: rick <LinuxSuRen@users.noreply.github.com>
  • Loading branch information
LinuxSuRen and LinuxSuRen authored Mar 4, 2024
1 parent e6fbf5d commit 4183f01
Show file tree
Hide file tree
Showing 8 changed files with 181 additions and 10 deletions.
44 changes: 44 additions & 0 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ name: Maven Package
on:
- pull_request

env:
REGISTRY: ghcr.io
REGISTRY_DOCKERHUB: docker.io
REGISTRY_ALIYUN: registry.aliyuncs.com
IMAGE_NAME: ${{ github.repository }}

jobs:
build:

Expand Down Expand Up @@ -35,3 +41,41 @@ jobs:
CODACY_PROJECT_TOKEN: ${{ secrets.CODACY_PROJECT_TOKEN }}
run: |
bash <(curl -Ls https://coverage.codacy.com/get.sh)
image:
runs-on: ubuntu-20.04
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-tags: true
fetch-depth: 0
- name: Set output
id: vars
run: echo "tag=$(git describe --tags)" >> $GITHUB_OUTPUT
- name: Setup Docker buildx
uses: docker/setup-buildx-action@79abd3f86f79a9d68a23c75a09a9a85889262adf
- name: Log into registry ${{ env.REGISTRY }}
if: github.event_name != 'pull_request'
uses: docker/login-action@28218f9b04b4f3f62068d7b6ce6ca5b26e35336c
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GH_PUBLISH_SECRETS }}
- name: Extract Docker metadata
id: meta
uses: docker/metadata-action@98669ae865ea3cffbcbaa878cf57c20bbf1c6c38
with:
images: ${{ env.REGISTRY }}/linuxsuren/api-testing
- name: Build and push Docker image
id: build-and-push
uses: docker/build-push-action@ac9327eae2b366085ac7f6a2d02df8aa8ead720a
with:
context: .
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
platforms: linux/amd64,linux/arm64
cache-from: type=gha
cache-to: type=gha,mode=max
build-args: VERSION=${{ steps.vars.outputs.tag }}
44 changes: 44 additions & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@

name: Maven Package

env:
REGISTRY: ghcr.io
REGISTRY_DOCKERHUB: docker.io
REGISTRY_ALIYUN: registry.aliyuncs.com
IMAGE_NAME: ${{ github.repository }}

on:
release:
types: [created]
Expand Down Expand Up @@ -59,3 +65,41 @@ jobs:
mvn deploy -s $GITHUB_WORKSPACE/settings.xml
env:
GITHUB_TOKEN: ${{ github.token }}

image:
runs-on: ubuntu-20.04
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-tags: true
fetch-depth: 0
- name: Set output
id: vars
run: echo "tag=$(git describe --tags)" >> $GITHUB_OUTPUT
- name: Setup Docker buildx
uses: docker/setup-buildx-action@79abd3f86f79a9d68a23c75a09a9a85889262adf
- name: Log into registry ${{ env.REGISTRY }}
if: github.event_name != 'pull_request'
uses: docker/login-action@28218f9b04b4f3f62068d7b6ce6ca5b26e35336c
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GH_PUBLISH_SECRETS }}
- name: Extract Docker metadata
id: meta
uses: docker/metadata-action@98669ae865ea3cffbcbaa878cf57c20bbf1c6c38
with:
images: ${{ env.REGISTRY }}/linuxsuren/api-testing
- name: Build and push Docker image
id: build-and-push
uses: docker/build-push-action@ac9327eae2b366085ac7f6a2d02df8aa8ead720a
with:
context: .
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
platforms: linux/amd64,linux/arm64
cache-from: type=gha
cache-to: type=gha,mode=max
build-args: VERSION=${{ steps.vars.outputs.tag }}
14 changes: 14 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
FROM maven:3.9.6-amazoncorretto-21 AS builder

WORKDIR /workspace
COPY . .
RUN mvn package -DskipTests -Djavafx.platform=linux -DskipLaunch4j

FROM ubuntu/jre:17-22.04_39

WORKDIR /workspace
COPY --from=builder /workspace/target/listening-0.0.1-SNAPSHOT-full-linux.jar listening.jar

EXPOSE 8080

CMD ["-cp", "listening.jar", "listening.linuxsuren.github.io.cli.CacheServerCLI"]
7 changes: 3 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,9 @@ Podcast client written by Java

See the screenshots from [here](https://github.com/LinuxSuRen/listening/discussions/1).

## TODO
* Cache the audio file
* Cache the logo
* Add RSS
## Features
* Cache
* Add personal RSS address

## Similar Projects
* https://github.com/Automattic/pocket-casts-android
Expand Down
10 changes: 8 additions & 2 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,20 @@ Please feel free to download it from https://github.com/LinuxSuRen/listening/rel
![image](https://github.com/LinuxSuRen/listening/assets/1450685/c0e2fa9e-17cf-4403-8445-8330f6c1a174)

## Installer

We're using Install4j to create installer.

<a href="https://www.ej-technologies.com/products/install4j/overview.html" target="_blank">
<img class="image-margin" width="92" height="26"
src="https://www.ej-technologies.com/images/product_banners/install4j_small.png">
</a>

## More Podcasts
## Cache Server
You can run the cache server in Docker:

```shell
## Default port is 8080
docker run -p 9090:8080 ghcr.io/linuxsuren/listening
```

## More Podcasts
Please feel free to add more interesting Podcast into [index.yaml](index.yaml).
5 changes: 5 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,11 @@
<artifactId>javafx-swing</artifactId>
<version>20</version>
</dependency>
<dependency>
<groupId>commons-cli</groupId>
<artifactId>commons-cli</artifactId>
<version>1.6.0</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
* Copyright 2024 LinuxSuRen.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package listening.linuxsuren.github.io.cli;

import listening.linuxsuren.github.io.server.CacheServer;
import org.apache.commons.cli.*;

import java.io.IOException;

public class CacheServerCLI {
private static final int defaultPort = 8080;

public static void main(String[] args) {
// create the command line parser
CommandLineParser parser = new DefaultParser();

// create the Options
Options options = new Options();
options.addOption("p", "port", true, "The cache server port");

int port = 0;
try {
// parse the command line arguments
CommandLine line = parser.parse(options, args);

String portStr = line.getOptionValue("port", "" + defaultPort);

port = Integer.parseInt(portStr);
} catch (ParseException exp) {
System.out.println("Unexpected exception:" + exp.getMessage());
} catch (NumberFormatException e) {
port = defaultPort;
System.out.println("got invalid port number:" + e.getMessage());
}

try {
new CacheServer().start(port);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,18 +36,21 @@ public class CacheServer implements HttpHandler {
private static int port = -1;
private Map<String, String> cacheQueue = new HashMap<>();


public void start() throws IOException {
public void start(int port) throws IOException {
ThreadPoolExecutor threadPoolExecutor = (ThreadPoolExecutor) Executors.newFixedThreadPool(20);
InetSocketAddress address = new InetSocketAddress("127.0.0.1", 0);
InetSocketAddress address = new InetSocketAddress("127.0.0.1", port);
HttpServer server = HttpServer.create(address, 0);
server.setExecutor(threadPoolExecutor);
server.createContext("/", this);
server.start();
port = server.getAddress().getPort();
port = server.getAddress().getPort(); // it can return the real port if the input parameter is 0
System.out.println("started cache server with port: " + port);
}

public void start() throws IOException {
start(0);
}

private String getCacheDir() {
return System.getProperty("user.home") + File.separator + ".config/listening/cache";
}
Expand Down

0 comments on commit 4183f01

Please sign in to comment.