Skip to content

Commit 740961f

Browse files
Infrastructure for Container (#56)
- action that builds image and tests probtest - deploy image to[ c2sm/probtest](https://hub.docker.com/repository/docker/c2sm/probtest/general) for any future release --------- Co-authored-by: Annika Lauber <annika.lauber@c2sm.ethz.ch>
1 parent 22d9dbf commit 740961f

File tree

5 files changed

+146
-7
lines changed

5 files changed

+146
-7
lines changed
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
name: Build Docker Container
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
branches:
9+
- main
10+
11+
jobs:
12+
build:
13+
runs-on: ubuntu-latest
14+
15+
steps:
16+
- name: Checkout repository
17+
uses: actions/checkout@v2
18+
with:
19+
submodules: true
20+
21+
- name: Set up Docker Buildx
22+
uses: docker/setup-buildx-action@v1
23+
24+
- name: Log in to Docker Hub
25+
uses: docker/login-action@v1
26+
with:
27+
username: c2sm
28+
password: ${{ secrets.DOCKER_PASSWORD }}
29+
30+
- name: Build Docker image
31+
uses: docker/build-push-action@v6
32+
with:
33+
context: .
34+
file: ./Dockerfile
35+
push: false
36+
tags: c2sm/probtest:latest
37+
platforms: linux/amd64,linux/arm64
38+
outputs: type=oci,dest=probtest_image.tar
39+
40+
- name: Upload Docker image as artifact
41+
uses: actions/upload-artifact@v4
42+
with:
43+
name: probtest_image.tar
44+
path: probtest_image.tar
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
name: Deploy image to DockerHub and GitHub Release
2+
3+
on:
4+
push:
5+
tags:
6+
- '*'
7+
8+
jobs:
9+
build_and_release:
10+
runs-on: ubuntu-latest
11+
12+
steps:
13+
- name: Set up Git repository
14+
uses: actions/checkout@v2
15+
with:
16+
submodules: true # Checkout submodules
17+
18+
- name: Set up Docker Buildx
19+
uses: docker/setup-buildx-action@v1
20+
21+
- name: Log in to Docker Hub
22+
uses: docker/login-action@v1
23+
with:
24+
username: c2sm
25+
password: ${{ secrets.DOCKER_PASSWORD }}
26+
27+
- name: Build and Save Docker image
28+
id: build_docker_image
29+
uses: docker/build-push-action@v2
30+
with:
31+
context: .
32+
file: ./Dockerfile
33+
push: true
34+
tags: c2sm/probtest:${{ github.ref_name }}
35+
platforms: linux/amd64,linux/arm64
36+
outputs: type=oci,dest=probtest_image.tar
37+
38+
- name: Upload Docker image as artifact
39+
uses: actions/upload-artifact@v4
40+
with:
41+
name: probtest_image.tar
42+
path: probtest_image.tar
43+
44+
- name: Get release
45+
id: get_release
46+
uses: bruceadams/get-release@v1.3.2
47+
env:
48+
GITHUB_TOKEN: ${{ github.token }}
49+
50+
- name: Upload Release Asset
51+
id: upload-release-asset
52+
uses: actions/upload-release-asset@v1
53+
env:
54+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
55+
with:
56+
upload_url: ${{ steps.get_release.outputs.upload_url }}
57+
asset_path: probtest_image.tar
58+
asset_name: probtest_image.tar
59+
asset_content_type: application/x-tar

.github/workflows/pytest.yml

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,6 @@
11
name: Run Pytest in probtest
22

3-
on:
4-
push:
5-
branches:
6-
- main
7-
pull_request:
8-
branches:
9-
- main
3+
on: [push]
104

115
jobs:
126
probtest-pytest:

Dockerfile

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# Use the official Ubuntu base image
2+
FROM ubuntu:latest
3+
4+
# Set environment variables
5+
ENV TZ=Europe/Zurich
6+
7+
# Install necessary dependencies
8+
RUN apt-get update && apt-get install -y \
9+
wget \
10+
bzip2 \
11+
ca-certificates \
12+
curl \
13+
git \
14+
# Install tzdata to set the timezone, otherwise timing tests of probtest will fail with
15+
# ValueError: time data 'Sun Jun 26 20:11:23 CEST 2022' does not match format '%a %b %d %H:%M:%S %Z %Y'
16+
tzdata \
17+
&& apt-get clean
18+
19+
20+
COPY . /probtest
21+
RUN cd /probtest && ./setup_miniconda.sh -p /opt/conda
22+
# Add conda to PATH
23+
ENV PATH=/opt/conda/miniconda/bin:$PATH
24+
25+
# only unpinned env works on aarch64
26+
RUN ARCH=$(uname -m) && \
27+
cd /probtest && chmod +x /probtest/setup_env.sh && \
28+
if [ "$ARCH" = "aarch64" ]; then \
29+
./setup_env.sh -u -n probtest; \
30+
else \
31+
./setup_env.sh -n probtest; \
32+
fi
33+
34+
# Test probtest
35+
RUN cd /probtest && conda run --name probtest pytest -v -s --cov --cov-report=term tests/
36+
37+
# Set the working directory
38+
WORKDIR /probtest
39+
40+
SHELL ["/bin/bash", "-c"]
41+
ENTRYPOINT ["conda", "run", "--name", "probtest", "/bin/bash", "-c"]

setup_miniconda.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ if [[ -f $CONDA_EXE ]]; then
3535
echo "Found a conda executable at: ${CONDA_EXE}"
3636
else
3737
echo "No conda executable available, fetching Miniconda install script"
38+
mkdir -p ${INSTALL_PREFIX}
3839
wget -O ${INSTALL_PREFIX}/miniconda.sh ${MINICONDA_URL}
3940
echo "${SHA256} ${INSTALL_PREFIX}/miniconda.sh" | sha256sum --check || exit 1
4041
bash ${INSTALL_PREFIX}/miniconda.sh -b -p ${INSTALL_PREFIX}/miniconda

0 commit comments

Comments
 (0)