Skip to content

Commit 5a4db62

Browse files
Publish C/C++ CLI docker images on GitHub Packages (#296)
1 parent 8bcda41 commit 5a4db62

File tree

3 files changed

+120
-0
lines changed

3 files changed

+120
-0
lines changed
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
name: Publish UTBot CLI image
2+
on:
3+
push:
4+
branches: [main]
5+
6+
env:
7+
REGISTRY: ghcr.io
8+
IMAGE_NAME: utbot_c_family_cli
9+
DOCKERFILE_PATH: docker/Dockerfile_c_family_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+
# Temp fix
67+
# https://github.com/docker/build-push-action/issues/252
68+
# https://github.com/moby/buildkit/issues/1896
69+
- name: Move cache
70+
run: |
71+
rm -rf /tmp/.buildx-cache
72+
mv /tmp/.buildx-cache-new /tmp/.buildx-cache

docker/Dockerfile_c_family_cli

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
FROM ubuntu:bionic-20220531
2+
3+
ARG ACCESS_TOKEN
4+
5+
RUN apt-get update \
6+
&& apt-get install -y build-essential \
7+
software-properties-common \
8+
&& add-apt-repository -y ppa:ubuntu-toolchain-r/test \
9+
&& apt-get update \
10+
&& apt-get install -y gcc-9 \
11+
g++-9 \
12+
curl \
13+
unzip \
14+
python3 \
15+
python3-requests \
16+
&& update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-9 60 --slave /usr/bin/g++ g++ /usr/bin/g++-9 \
17+
&& update-alternatives --config gcc \
18+
&& apt-get clean
19+
20+
WORKDIR /usr/src/
21+
22+
# Install UTBot C/C++ CLI
23+
COPY docker/get_c_family_cli_download_url.py .
24+
25+
ENV C_FAMILY_CLI_ZIP_NAME "utbot_distr.zip"
26+
27+
RUN curl -H "Authorization: Bearer ${ACCESS_TOKEN}" \
28+
-L $(python3 get_c_family_cli_download_url.py) \
29+
-o "${C_FAMILY_CLI_ZIP_NAME}" \
30+
&& unzip -q "${C_FAMILY_CLI_ZIP_NAME}" \
31+
&& find . ! -name 'utbot_distr.tar.gz' -type f -exec rm -f {} + \
32+
&& mkdir utbot-cli \
33+
&& tar -xf utbot_distr.tar.gz -C utbot-cli \
34+
&& chmod +x utbot-cli/utbot_distr/utbot_online_cli.sh \
35+
&& chmod +x utbot-cli/utbot_distr/utbot_run_system.sh
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import json
2+
import requests
3+
4+
C_FAMILY_ARTIFACTS_URL="https://api.github.com/repos/UnitTestBot/UTBotCPP/actions/artifacts"
5+
6+
request = requests.get(url = C_FAMILY_ARTIFACTS_URL)
7+
data = request.json()
8+
artifacts = data['artifacts']
9+
10+
for artifact in artifacts:
11+
if "utbot-dev" in artifact['name']:
12+
print(artifact['archive_download_url'])
13+
break

0 commit comments

Comments
 (0)