Skip to content

Commit ab5b875

Browse files
Publish Java CLI docker images on GitHub Packages (#272)
1 parent e0d224c commit ab5b875

File tree

3 files changed

+113
-0
lines changed

3 files changed

+113
-0
lines changed
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
name: "CLI: publish image"
2+
on:
3+
push:
4+
branches: [main]
5+
6+
env:
7+
REGISTRY: ghcr.io
8+
IMAGE_NAME: utbot_java_cli
9+
DOCKERFILE_PATH: docker/Dockerfile_java_cli
10+
11+
jobs:
12+
build-and-publish-docker:
13+
runs-on: ubuntu-20.04
14+
steps:
15+
- name: Checkout repository
16+
uses: actions/checkout@v3
17+
18+
- name: Set timezone
19+
uses: szenius/[email protected]
20+
with:
21+
timezoneLinux: "Europe/Moscow"
22+
23+
- name: Set environment variables
24+
run:
25+
echo "COMMIT_SHORT_SHA="$(git rev-parse --short HEAD)"" >> $GITHUB_ENV
26+
27+
- name: Set docker tag
28+
run:
29+
echo "DOCKER_TAG="$(date +%Y).$(date +%-m).$(date +%-d)-${{ env.COMMIT_SHORT_SHA }}"" >> $GITHUB_ENV
30+
31+
- name: Log in to the Container registry
32+
uses: docker/login-action@v1
33+
with:
34+
registry: ${{ env.REGISTRY }}
35+
username: ${{ github.actor }}
36+
password: ${{ secrets.GITHUB_TOKEN }}
37+
38+
- name: Set up Docker Buildx
39+
uses: docker/setup-buildx-action@v1
40+
41+
- name: Cache Docker layers
42+
uses: actions/cache@v2
43+
with:
44+
path: /tmp/.buildx-cache
45+
key: ${{ runner.os }}-buildx-${{ github.sha }}
46+
restore-keys: |
47+
${{ runner.os }}-buildx-
48+
49+
- name: Docker meta
50+
id: meta
51+
uses: docker/metadata-action@v3
52+
with:
53+
images: ${{ env.REGISTRY }}/${{ github.repository }}/${{ env.IMAGE_NAME }}
54+
tags: |
55+
type=raw,value=${{ env.DOCKER_TAG }}
56+
57+
- name: Docker Buildx (build and push)
58+
run: |
59+
docker buildx build \
60+
-f ${{ env.DOCKERFILE_PATH }} \
61+
--cache-from "type=local,src=/tmp/.buildx-cache" \
62+
--cache-to "type=local,dest=/tmp/.buildx-cache-new" \
63+
--tag ${{ steps.meta.outputs.tags }} \
64+
--build-arg ACCESS_TOKEN=${{ secrets.GITHUB_TOKEN }} \
65+
--push .
66+
67+
# Temp fix
68+
# https://github.com/docker/build-push-action/issues/252
69+
# https://github.com/moby/buildkit/issues/1896
70+
- name: Move cache
71+
run: |
72+
rm -rf /tmp/.buildx-cache
73+
mv /tmp/.buildx-cache-new /tmp/.buildx-cache

docker/Dockerfile_java_cli

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
FROM openjdk:8
2+
3+
ARG ACCESS_TOKEN
4+
5+
WORKDIR /usr/src/
6+
7+
RUN apt-get update \
8+
&& apt-get install -y curl \
9+
unzip \
10+
python3 \
11+
python3-requests \
12+
&& apt-get clean
13+
14+
# Install UTBot Java CLI
15+
COPY docker/get_java_cli_download_url.py .
16+
17+
ENV JAVA_CLI_ZIP_NAME "utbot_java_cli.zip"
18+
19+
RUN curl -H "Authorization: Bearer ${ACCESS_TOKEN}" \
20+
-L "$(python3 get_java_cli_download_url.py)" \
21+
-o "${JAVA_CLI_ZIP_NAME}" \
22+
&& unzip "${JAVA_CLI_ZIP_NAME}" \
23+
&& rm "${JAVA_CLI_ZIP_NAME}"
24+
25+
ENV JAVA_CLI_PATH="$(find $pwd -type f -name "utbot-cli*")"
26+
RUN ln -s "${JAVA_CLI_PATH}" $pwd/utbot-cli.jar

docker/get_java_cli_download_url.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import json
2+
import requests
3+
4+
JAVA_ARTIFACTS_URL="https://github.com/api/repos/UnitTestBot/UTBotJava/actions/artifacts"
5+
6+
request = requests.get(url = JAVA_ARTIFACTS_URL)
7+
data = request.json()
8+
artifacts = data['artifacts']
9+
10+
for artifact in artifacts:
11+
if "utbot-cli" in artifact['name']:
12+
print(artifact['archive_download_url'])
13+
break
14+

0 commit comments

Comments
 (0)