Skip to content

Commit 70d4134

Browse files
committed
Add exoframe-template-java package and setup auto prereleases for it
1 parent 8065eed commit 70d4134

File tree

4 files changed

+120
-0
lines changed

4 files changed

+120
-0
lines changed

.github/workflows/prerelease.yml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,3 +109,28 @@ jobs:
109109
run: npm publish --access public --tag next -w exoframe-recipe-ghost
110110
env:
111111
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
112+
113+
publish-template-java:
114+
runs-on: ubuntu-latest
115+
steps:
116+
- uses: actions/checkout@v3
117+
- uses: actions/setup-node@v3
118+
with:
119+
node-version: 18
120+
cache: 'npm'
121+
registry-url: 'https://registry.npmjs.org'
122+
# get versions for currently published and local packages
123+
- name: check versions
124+
id: versions
125+
run: |
126+
echo "current=$(npm info exoframe-template-java@next version || echo 'no published package yet')" >> $GITHUB_OUTPUT
127+
echo "new=$(npm info ./packages/exoframe-template-java version)" >> $GITHUB_OUTPUT
128+
# install and publish if local version is not the same as published
129+
- name: install
130+
if: ${{ steps.versions.outputs.current != steps.versions.outputs.new }}
131+
run: npm ci
132+
- name: publish
133+
if: ${{ steps.versions.outputs.current != steps.versions.outputs.new }}
134+
run: npm publish --access public --tag next -w exoframe-template-java
135+
env:
136+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Java deployment template for exoframe
2+
3+
Java deployment template for [Exoframe](https://github.com/exoframejs/exoframe).
4+
5+
## Notes
6+
7+
The template assumes your app is deployed via `app.jar` file and listens on port 80.
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
// npm packages
2+
import { readdir, writeFile } from 'fs/promises';
3+
import { join } from 'path';
4+
5+
const javaDockerfile = () =>
6+
`FROM openjdk
7+
COPY . /usr/src/myapp
8+
WORKDIR /usr/src/myapp
9+
EXPOSE 80
10+
CMD java -jar app.jar`;
11+
12+
export const name = 'java';
13+
14+
// function to check if the template fits this recipe
15+
export async function checkTemplate({ tempDockerDir }) {
16+
// if project already has dockerfile - just exit
17+
try {
18+
const filesList = await readdir(tempDockerDir);
19+
return filesList.filter((file) => file.includes('.jar')).length > 0;
20+
} catch (e) {
21+
return false;
22+
}
23+
}
24+
25+
// function to execute current template
26+
export async function executeTemplate({ username, tempDockerDir, resultStream, util, docker }) {
27+
try {
28+
// generate dockerfile
29+
const dockerfile = javaDockerfile();
30+
const dfPath = join(tempDockerDir, 'Dockerfile');
31+
await writeFile(dfPath, dockerfile, 'utf-8');
32+
util.writeStatus(resultStream, { message: 'Deploying Java project..', level: 'info' });
33+
34+
// build docker image
35+
const buildRes = await docker.build({ username, resultStream });
36+
util.logger.debug('Build result:', buildRes);
37+
38+
// check for errors in build log
39+
if (
40+
buildRes.log
41+
.map((it) => it.toLowerCase())
42+
.some((it) => it.includes('error') || (it.includes('failed') && !it.includes('optional')))
43+
) {
44+
util.logger.debug('Build log conains error!');
45+
util.writeStatus(resultStream, { message: 'Build log contains errors!', level: 'error' });
46+
resultStream.end('');
47+
return;
48+
}
49+
50+
// start image
51+
const containerInfo = await docker.start(Object.assign({}, buildRes, { username, resultStream }));
52+
util.logger.debug(containerInfo.Name);
53+
54+
// clean temp folder
55+
await util.cleanTemp();
56+
57+
const containerData = docker.daemon.getContainer(containerInfo.Id);
58+
const container = await containerData.inspect();
59+
// return new deployments
60+
util.writeStatus(resultStream, { message: 'Deployment success!', deployments: [container], level: 'info' });
61+
resultStream.end('');
62+
} catch (e) {
63+
util.logger.debug('build failed!', e);
64+
util.writeStatus(resultStream, { message: e.error, error: e.error, log: e.log, level: 'error' });
65+
resultStream.end('');
66+
}
67+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"name": "exoframe-template-java",
3+
"version": "1.0.0-pre-alpha.1",
4+
"description": "Java deployment template for exoframe",
5+
"main": "index.js",
6+
"type": "module",
7+
"scripts": {
8+
"test": "echo \"Error: no test specified\" && exit 1"
9+
},
10+
"keywords": [],
11+
"author": "Tim Ermilov <[email protected]> (http://codezen.net)",
12+
"license": "MIT",
13+
"repository": {
14+
"type": "git",
15+
"url": "git+https://github.com/exoframejs/exoframe.git"
16+
},
17+
"bugs": {
18+
"url": "https://github.com/exoframejs/exoframe/issues"
19+
},
20+
"homepage": "https://github.com/exoframejs/exoframe#readme"
21+
}

0 commit comments

Comments
 (0)