Skip to content

Commit

Permalink
Enable publishing a Docker image from a branch (#913)
Browse files Browse the repository at this point in the history
* Add workflow for publishing a docker image from branch

* Temp enable on every PR for testing

* Another temp change to test

* Setup missing variables

* Update branch name in the tag

* Return values for testing

* Fix invalid symbols

* Cleanup: run on dispatch

* Push to ghrc instead of dockerhub

* Update trigger, inputs according to the review

* Fix typo in `github.event`
  • Loading branch information
palinatolmach authored Dec 13, 2024
1 parent cc9afb7 commit 0ec85db
Showing 1 changed file with 84 additions and 0 deletions.
84 changes: 84 additions & 0 deletions .github/workflows/docker-push.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
---
name: 'Push Docker Image'
on:
workflow_dispatch:

inputs:
kontrol_branch:
description: "Branch of Kontrol to use to build the Docker image"
required: true

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
dockerhub:
name: 'Build and Publish Docker Image'
runs-on: [self-hosted, linux, normal]
steps:
- name: 'Check out code'
uses: actions/checkout@v4
with:
ref: ${{ github.event.inputs.kontrol_branch}}
fetch-depth: 0

- name: 'Set environment'
run: |
KONTROL_VERSION=$(cat package/version)
echo "CONTAINER_NAME=kontrol-ci-docker-${GITHUB_SHA}" >> ${GITHUB_ENV}
BRANCH_NAME="${{ github.event.inputs.kontrol_branch }}"
SANITIZED_BRANCH_NAME=$(echo "${BRANCH_NAME}" | tr '/' '-' | tr -cd '[:alnum:]-_.')
GHCR_TAG=ghcr.io/runtimeverification/kontrol/kontrol:ubuntu-jammy-${SANITIZED_BRANCH_NAME}
echo "GHCR_TAG=${GHCR_TAG}" >> ${GITHUB_ENV}
echo "DOCKER_USER=user" >> ${GITHUB_ENV}
echo "DOCKER_GROUP=user" >> ${GITHUB_ENV}
echo "FOUNDRY_ROOT=/home/user/foundry" >> ${GITHUB_ENV}
- name: 'Build Docker image'
run: |
K_VERSION=$(cat deps/k_release)
Z3_VERSION=$(cat deps/z3)
docker build . --no-cache --tag ${GHCR_TAG} --build-arg K_VERSION=${K_VERSION} --build-arg Z3_VERSION=${Z3_VERSION}
- name: 'Run Docker image'
run: |
docker run \
--name ${CONTAINER_NAME} \
--rm \
--interactive \
--tty \
--detach \
--user root \
${GHCR_TAG}
docker cp src/tests/integration/test-data/foundry ${CONTAINER_NAME}:${FOUNDRY_ROOT}
docker exec ${CONTAINER_NAME} chown -R ${DOCKER_USER}:${DOCKER_GROUP} ${FOUNDRY_ROOT}
- name: 'Run forge build'
run: |
docker exec --user ${DOCKER_USER} --workdir ${FOUNDRY_ROOT} ${CONTAINER_NAME} forge install --no-git foundry-rs/forge-std@75f1746
docker exec --user ${DOCKER_USER} --workdir ${FOUNDRY_ROOT} ${CONTAINER_NAME} forge install --no-git runtimeverification/kontrol-cheatcodes@a5dd4b0
docker exec --user ${DOCKER_USER} --workdir ${FOUNDRY_ROOT} ${CONTAINER_NAME} forge build
- name: 'Run kontrol build'
run: docker exec --user ${DOCKER_USER} --workdir ${FOUNDRY_ROOT} ${CONTAINER_NAME} kontrol build -O2

- name: 'Run kontrol prove'
run: docker exec --user ${DOCKER_USER} --workdir ${FOUNDRY_ROOT} ${CONTAINER_NAME} kontrol prove --match-test 'AssertTest.test_assert_true()'

- name: 'Run kontrol show'
run: docker exec --user ${DOCKER_USER} --workdir ${FOUNDRY_ROOT} ${CONTAINER_NAME} kontrol show 'AssertTest.test_assert_true()'

- name: 'Tear Down Docker'
if: always()
run: |
docker stop --time=0 ${CONTAINER_NAME}
- name: 'Push Docker Image to GitHub Packages'
run: |
echo ${{ secrets.DOCKERHUB_PASSWORD }} | docker login -u ${{ vars.DOCKERHUB_USERNAME }} --password-stdin
echo ${{ secrets.GITHUB_TOKEN }} | docker login ghcr.io -u ${{ github.repository_owner }} --password-stdin
docker push ${GHCR_TAG}

0 comments on commit 0ec85db

Please sign in to comment.