feat(ci/cd): release images with opentelemetry #444
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: pull-request-tests | |
on: | |
push: | |
branches: | |
- master | |
pull_request: | |
branches: | |
- master | |
concurrency: | |
group: ${{ github.workflow }}-${{ github.ref }} | |
cancel-in-progress: true | |
env: | |
REGISTRY: ghcr.io | |
IMAGE_NAME: ${{ github.repository }}/dali | |
CARGO_INCREMENTAL: 0 | |
CARGO_NET_RETRY: 10 | |
CI: 1 | |
RUST_BACKTRACE: short | |
RUSTUP_MAX_RETRIES: 10 | |
# RUSTFLAGS_EXTRA: "-D warnings -W rust-2021-compatibility" | |
jobs: | |
test: | |
runs-on: ubuntu-latest | |
container: rust:1.74.0-alpine3.18 | |
services: | |
backend: | |
image: nginx:latest | |
options: -v ${{ github.workspace }}/tests/resources/:/usr/share/nginx/html/ --name backend | |
steps: | |
- name: Debug workflow trigger | |
run: | | |
echo "The workflow was triggered by ${{ github.triggering_actor }}" | |
echo -e "The actor is\t${{github.actor}}" | |
echo -e "The actor has id\t${{github.actor_id}}" | |
- uses: actions/checkout@v4 | |
- name: Restart nginx | |
uses: docker://docker | |
with: | |
args: docker restart backend | |
- name: Install build dependencies | |
run: apk add --update --no-cache --repository https://dl-cdn.alpinelinux.org/alpine/v3.18/main | |
build-base=0.5-r3 | |
clang=16.0.6-r1 | |
clang16-libclang=16.0.6-r1 | |
expat-dev=2.6.4-r0 | |
giflib-dev=5.2.2-r0 | |
glib-dev=2.76.6-r0 | |
lcms2-dev=2.15-r2 | |
libexif-dev=0.6.24-r1 | |
libheif-dev=1.16.2-r0 | |
libimagequant-dev=4.2.0-r0 | |
libjpeg-turbo-dev=2.1.5.1-r3 | |
libpng-dev=1.6.44-r0 | |
librsvg-dev=2.56.3-r0 | |
libwebp-dev=1.3.2-r0 | |
openssl-dev=3.1.7-r1 | |
orc-dev=0.4.39-r0 | |
pkgconf=1.9.5-r0 | |
tiff-dev=4.5.1-r0 | |
tar | |
curl | |
- name: Install Libvips | |
run: | | |
wget https://github.com/libvips/libvips/releases/download/v8.13.3/vips-8.13.3.tar.gz | |
mkdir /vips | |
tar xvzf vips-8.13.3.tar.gz -C /vips --strip-components 1 | |
cd /vips | |
./configure --enable-debug=no --without-OpenEXR --disable-static --enable-silent-rule | |
make | |
make install | |
rm -rf vips vips-8.13.3.tar.gz | |
- name: Check if nginx is available for files hosting | |
run: curl http://backend/exif --output /dev/null | |
# Cache needs the Cargo.lock file for the cache key and must come after the git checkout | |
- name: Set up cargo cache | |
uses: actions/cache@v4 | |
continue-on-error: false | |
with: | |
path: | | |
~/.cargo/bin/ | |
~/.cargo/registry/index/ | |
~/.cargo/registry/cache/ | |
~/.cargo/git/db/ | |
target/ | |
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }} | |
restore-keys: ${{ runner.os }}-cargo- | |
- name: Build Dali | |
run: RUSTFLAGS="-C target-feature=-crt-static $(pkg-config vips --libs)" cargo build | |
- name: Run Dali | |
run: ./target/debug/dali >> /dev/null & | |
- name: Wait for Dali to start | |
run: sleep 5 | |
- name: Run tests | |
run: | | |
set +e | |
RUSTFLAGS="-C target-feature=-crt-static $(pkg-config vips --libs)" HTTP_HOST=backend cargo test -- --quiet | |
exitcode="$?" | |
echo "exitcode=$exitcode" >> $GITHUB_OUTPUT | |
exit "$exitcode" | |
# Only runs if a pull request is created | |
# ignored by renovate branch auto-commit strategy, which does not create PRs | |
# renovate creates merge branches and merges on test success | |
# if the tests fail, a PR is raised | |
# Only run if the tests were successful | |
docker-preview: | |
runs-on: ubuntu-latest | |
needs: | |
- test | |
if: ${{ !contains(needs.test.outputs.status, 'failure') }} && ${{!(github.triggering_actor == 'dependabot[bot]' || github.triggering_actor == 'renovate[bot]') && github.repository == 'olxgroup-oss/dali'}} | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v3 | |
- name: Log in to the Container registry | |
if: github.event_name == 'pull_request' | |
uses: docker/login-action@v3 | |
with: | |
registry: ${{ env.REGISTRY }} | |
username: ${{ github.repository_owner }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: Docker metadata for the Dali image with the reqwest feature | |
if: github.event_name == 'pull_request' && github.repository == 'olxgroup-oss/dali' | |
id: meta-reqwest | |
uses: docker/metadata-action@v5 | |
with: | |
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} | |
tags: ${{ github.head_ref }} | |
- name: Build and push with the reqwest feature | |
if: github.event_name == 'pull_request' && github.repository == 'olxgroup-oss/dali' | |
uses: docker/build-push-action@v5 | |
with: | |
context: . | |
file: ./Dockerfile | |
build-args: DALI_FEATURES=reqwest | |
push: true | |
tags: ${{ steps.meta-reqwest.outputs.tags }} | |
labels: ${{ steps.meta-reqwest.outputs.labels }} | |
- name: Docker metadata for the Dali image with the s3 feature | |
if: github.event_name == 'pull_request' && github.repository == 'olxgroup-oss/dali' | |
id: meta-s3 | |
uses: docker/metadata-action@v5 | |
with: | |
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}-s3 | |
tags: ${{ github.head_ref }} | |
- name: Build and push with the s3 feature | |
if: github.event_name == 'pull_request' && github.repository == 'olxgroup-oss/dali' | |
uses: docker/build-push-action@v5 | |
with: | |
context: . | |
file: ./Dockerfile | |
build-args: DALI_FEATURES=s3 | |
push: true | |
tags: ${{ steps.meta-s3.outputs.tags }} | |
labels: ${{ steps.meta-s3.outputs.labels }} | |
- name: Add package image comment to PR | |
if: github.event_name == 'pull_request' && github.repository == 'olxgroup-oss/dali' | |
uses: marocchino/sticky-pull-request-comment@v2 | |
# Inform the user that a preview image has been built and published | |
with: | |
header: pr-docker-image | |
message: | | |
Hey there and thank you for opening this pull request! 👋🏼 | |
You can pull a preview container image of dali with the below command: | |
```console | |
docker pull ${{ steps.meta-reqwest.outputs.tags }} | |
docker pull ${{ steps.meta-s3.outputs.tags }} | |
``` |