Skip to content

Commit

Permalink
New build and CI system
Browse files Browse the repository at this point in the history
  • Loading branch information
unkcpz committed May 15, 2024
1 parent 36e4a96 commit 9562a84
Show file tree
Hide file tree
Showing 10 changed files with 285 additions and 163 deletions.
44 changes: 0 additions & 44 deletions .github/workflows/build_and_test.yml

This file was deleted.

150 changes: 150 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
---
name: Build images and run tests and publish

on:
pull_request:
push:
branches:
- main
- support/**
tags:
- "v*"
workflow_dispatch:

env:
BUILDKIT_PROGRESS: plain
FORCE_COLOR: 1

# https://docs.github.com/en/actions/using-jobs/using-concurrency
concurrency:
# only cancel in-progress jobs or runs for the current workflow - matches against branch & tags
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:

build:

runs-on: ubuntu-latest
timeout-minutes: 30

outputs:
image: ${{ steps.bake_metadata.outputs.image }}

steps:
- name: Checkout Repo ⚡️
uses: actions/checkout@v4

- name: Set up QEMU
if: ${{ inputs.platforms != 'linux/amd64' }}
uses: docker/setup-qemu-action@v3

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Login to GitHub Container Registry 🔑
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3


- uses: crazy-max/ghaction-github-runtime@v3
- name: Build and upload to ghcr.io 📤
id: build-upload
uses: docker/bake-action@v4
with:
push: true
# Using provenance to disable default attestation so it will build only desired images:
# https://github.com/orgs/community/discussions/45969
provenance: false
set: |
*.platform=linux/amd64
*.output=type=registry,name-canonical=true,push-by-digest=true
*.cache-from=type=gha
*.cache-to=type=gha,mode=max
files: |
docker-bake.hcl
build.json
.github/workflows/env.hcl
- name: Set output variables
id: bake_metadata
run: |
.github/workflows/extract-image-name.sh | tee -a "${GITHUB_OUTPUT}"
env:
BAKE_METADATA: ${{ steps.build-upload.outputs.metadata }}

test:
runs-on: ubuntu-latest
timeout-minutes: 30
needs: build

steps:

- name: Checkout Repo ⚡️
uses: actions/checkout@v4

- name: Login to GitHub Container Registry 🔑
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Run container checking libraries exist in the container
run: |
docker run --rm ${{ needs.build.outputs.image }} /bin/bash -c "which oncvpsp.x" >> /tmp/cat-output.txt
if cat /tmp/cat-output.txt | grep -q "/usr/local/bin/oncvpsp.x"; then
echo "oncvpsp.x found"
else
echo "oncvpsp.x not found"
exit 1
fi
publish:
runs-on: ubuntu-latest
timeout-minutes: 30
needs: [build]
if: >-
github.repository == 'pspgen/oncvpsp'
&& (github.ref_type == 'tag' || github.ref_name == 'main')
steps:
- uses: actions/checkout@v4

- name: Login to GitHub Container Registry 🔑
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Read build variables
id: build_vars
run: |
vars=$(cat build.json | jq -c '[.variable | to_entries[] | {"key": .key, "value": .value.default}] | from_entries')
echo "vars=$vars" | tee -a "${GITHUB_OUTPUT}"
- name: Docker meta
id: meta
uses: docker/metadata-action@v5
env: ${{ fromJSON(steps.build_vars.outputs.vars) }}
with:
images: ghcr.io/${{ github.repository_owner }}/oncvpsp
tags: |
type=edge,enable={{is_default_branch}}
type=raw,value={{tag}},enable=${{ github.ref_type == 'tag' && startsWith(github.ref_name, 'v') }}
type=raw,value=oncvpsp-${{ env.ONCVPSP_VERSION }},enable=${{ github.ref_type == 'tag' && startsWith(github.ref_name, 'v') }}
type=match,pattern=v(\d{4}\.\d{4}(-.+)?),group=1
- name: Push tags
uses: akhilerm/[email protected]
with:
src: ${{ needs.build.outputs.image }}
dst: ${{ steps.meta.outputs.tags }}
2 changes: 2 additions & 0 deletions .github/workflows/env.hcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# env.hcl
REGISTRY = "ghcr.io"
34 changes: 34 additions & 0 deletions .github/workflows/extract-image-name.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Extract image names together with their sha256 digests
# from the docker/bake-action metadata output.
# These together uniquely identify newly built images.

# The input to this script is a JSON string passed via BAKE_METADATA env variable
# Here's example input (trimmed to relevant bits):
# BAKE_METADATA: {
# "base": {
# "containerimage.descriptor": {
# "mediaType": "application/vnd.docker.distribution.manifest.v2+json",
# "digest": "sha256:8e57a52b924b67567314b8ed3c968859cad99ea13521e60bbef40457e16f391d",
# "size": 6170,
# },
# "containerimage.digest": "sha256:8e57a52b924b67567314b8ed3c968859cad99ea13521e60bbef40457e16f391d",
# "image.name": "ghcr.io/pspgen/oncvpsp"
# }
# }
#
# Example output (real output is on one line):
#
# image="ghcr.io/pspgen/oncvpsp@sha256:79a0f984b9e03b733304fda809ad3e8eec8416992ff334052d75da00cadb8f12"
# }
#
# This json output is later turned to environment variables using fromJson() GHA builtin
# (e.g. BUILD_MACHINE_IMAGE=ghcr.io/pspgen/oncvpsp@sha256:8e57a52b...)
# and these are in turn read in the docker-compose.<target>.yml files for tests.

if [[ -z ${BAKE_METADATA-} ]];then
echo "ERROR: Environment variable BAKE_METADATA is not set!"
exit 1
fi

image=$(echo "${BAKE_METADATA}" | jq -c '. as $base | to_entries[] | [(.value."image.name"|split(",")[0]),(.value."containerimage.digest")]|join("@")' | tr -d '"')
echo "image=$image"
50 changes: 0 additions & 50 deletions .github/workflows/push_to_dockerhub.yml

This file was deleted.

62 changes: 0 additions & 62 deletions 19_K_st.dat

This file was deleted.

20 changes: 13 additions & 7 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,17 +1,23 @@
FROM pspgen/psp-prerequisites:0.1.0
FROM build-base-image

WORKDIR /oncvpsp-build
# compile oncvpsp-4.0.1
RUN wget -c http://www.mat-simresearch.com/oncvpsp-4.0.1.tar.gz && \
tar xf oncvpsp-4.0.1.tar.gz
RUN cd oncvpsp-4.0.1/src && \


ARG ONCVPSP_VERSION

# Compile oncvpsp-4.0.1
RUN wget -c -O oncvpsp.tar.gz http://www.mat-simresearch.com/oncvpsp-${ONCVPSP_VERSION}.tar.gz && \
mkdir -p oncvpsp && \
tar xf oncvpsp.tar.gz -C oncvpsp --strip-components=1 && \
cd oncvpsp/src && \
echo "LIBS += -static-libgfortran -static-libgcc" >> ../make.inc && \
make all

FROM phusion/baseimage:focal-1.2.0
# Move binaries to a small image to reduce the size
FROM runtime-base-image
RUN apt-get update && apt-get install -y \
libquadmath0 \
&& rm -rf /var/lib/apt/lists/* \
&& apt-get clean all

COPY --from=0 /oncvpsp-build/oncvpsp-4.0.1/src/*.x /usr/local/bin/
COPY --from=0 /oncvpsp-build/oncvpsp/src/*.x /usr/local/bin/
Loading

0 comments on commit 9562a84

Please sign in to comment.