Skip to content

Commit

Permalink
chore: Update CI
Browse files Browse the repository at this point in the history
  • Loading branch information
Threated committed Apr 8, 2024
1 parent 17cdbad commit 3c8fbe4
Show file tree
Hide file tree
Showing 7 changed files with 61 additions and 167 deletions.
149 changes: 11 additions & 138 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,151 +3,24 @@ name: Rust
on:
push:
pull_request:
workflow_dispatch:
schedule:
# Fetch new base image updates every night at 1am
- cron: '0 1 * * *'

env:
CARGO_TERM_COLOR: always
PROFILE: release

jobs:
pre-check:
name: Security, License Check
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- uses: EmbarkStudios/cargo-deny-action@v1

build-rust:
name: Build (Rust)
runs-on: ubuntu-latest

strategy:
matrix:
arch:
- amd64
- arm64
features:
- sockets
- ""

steps:
- name: Set arch ${{ matrix.arch }}
env:
ARCH: ${{ matrix.arch }}
run: |
if [ "${ARCH}" == "arm64" ]; then
echo "rustarch=aarch64-unknown-linux-gnu" >> $GITHUB_ENV
elif [ "${ARCH}" == "amd64" ]; then
echo "rustarch=x86_64-unknown-linux-gnu" >> $GITHUB_ENV
else
exit 1
fi
if [ "$(dpkg --print-architecture)" != "${ARCH}" ]; then
echo "Cross-compiling to ${ARCH}."
echo "is_cross=true" >> $GITHUB_ENV
else
echo "Natively compiling to ${ARCH}."
echo "is_cross=false" >> $GITHUB_ENV
fi
- name: Set profile ${{ env.PROFILE }}
env:
PROFILE: ${{ env.PROFILE }}
run: |
if [ "${PROFILE}" == "release" ]; then
echo "profilestr=--release" >> $GITHUB_ENV
elif [ "${PROFILE}" == "debug" ]; then
echo "profilestr=" >> $GITHUB_ENV
else
echo "profilestr=--profile $PROFILE" >> $GITHUB_ENV
fi
- uses: actions/checkout@v3
- uses: actions-rs/toolchain@v1
with:
toolchain: stable
override: true
target: ${{ env.rustarch }}
- uses: Swatinem/rust-cache@v2
with:
key: ${{ matrix.arch }}-${{ env.PROFILE }}
prefix-key: v1-rust-${{ matrix.features && format('features_{0}', matrix.features) || 'nofeatures' }} # Increase to invalidate old caches.
- name: Build (${{ matrix.arch }})
uses: actions-rs/cargo@v1
with:
use-cross: ${{ env.is_cross }}
command: build
args: --target ${{ env.rustarch }} ${{ matrix.features && format('--features {0}', matrix.features) }} ${{ env.profilestr }}
- name: Upload Artifact
uses: actions/upload-artifact@v3
with:
name: binaries-${{ matrix.arch }}-${{ matrix.features }}
path: |
target/${{ env.rustarch }}/${{ env.PROFILE }}/connect
test:
name: Run tests
needs: [ build-rust ]
runs-on: ubuntu-22.04

strategy:
matrix:
features:
- ""
- "sockets"

steps:
- uses: actions/checkout@v3
- uses: actions/download-artifact@v3
with:
name: binaries-amd64-${{ matrix.features }}
path: artifacts/binaries-amd64/
- name: Set diffrent image tag
run: |
if [[ ${{ format('"{0}"', matrix.features) }} == 'sockets' ]]; then
echo "TAG=develop-sockets" >> $GITHUB_ENV
fi
- name: Start containers
run: ./dev/start ci
# - name: Show logs
# working-directory: ./dev
# run: |
# sleep 3
# docker compose logs
- name: Run tests
run: cargo test ${{ format('--features "{0}"', matrix.features) }}

docker:
needs: [ build-rust, pre-check, test ]

strategy:
matrix:
features:
- ""
- "sockets"

# This workflow defines how a maven package is built, tested and published.
# Visit: https://github.com/samply/github-workflows/blob/develop/.github/workflows/docker-ci.yml, for more information
uses: samply/github-workflows/.github/workflows/docker-ci.yml@main
uses: samply/github-workflows/.github/workflows/rust.yml@main
with:
# The Docker Hub Repository you want eventually push to, e.g samply/share-client
image-name: "samply/beam-connect"
image-tag-suffix: ${{ matrix.features && format('-{0}', matrix.features) }}
# Define special prefixes for docker tags. They will prefix each images tag.
# image-tag-prefix: "foo"
# Define the build context of your image, typically default '.' will be enough
# build-context: '.'
# Define the Dockerfile of your image, typically default './Dockerfile' will be enough
build-file: './Dockerfile.ci'
# NOTE: This doesn't work currently
# A list of build arguments, passed to the docker build
build-args: |
FEATURE=-${{ matrix.features }}
# Define the target platforms of the docker build (default "linux/amd64,linux/arm64/v8")
# build-platforms: "linux/amd64,linux/arm64"
# If your actions generate an artifact in a previous build step, you can tell this workflow to download it
artifact-name: '*'
# For information on these variables, please refer to https://github.com/samply/github-workflows/tree/main/.github/workflows/rust.yml
# Docker Hub name will be {image-prefix}{component}
image-prefix: "samply/"
components: '[ "beam-connect" ]'
#architectures: '[ "amd64" ]'
#profile: debug
test-via-script: true
features: '[ "", "sockets" ]'
push-to: ${{ (github.ref_protected == true || github.event_name == 'workflow_dispatch') && 'dockerhub' || 'ghcr' }}
# This passes the secrets from calling workflow to the called workflow
secrets:
DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }}
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[package]
name = "connect"
name = "beam-connect"
version = "0.1.1"
edition = "2021"
license = "Apache-2.0"
Expand Down
20 changes: 20 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# This assumes binaries are present, see COPY directive.

ARG IMGNAME=gcr.io/distroless/cc

FROM alpine AS chmodder
ARG FEATURE
ARG TARGETARCH
ARG COMPONENT=beam-connect
COPY /artifacts/binaries-$TARGETARCH$FEATURE/$COMPONENT /app/$COMPONENT
RUN chmod +x /app/*

# FROM ${IMGNAME}
FROM ubuntu:latest
RUN apt update
RUN apt install -y ca-certificates
RUN apt install -y ssl-cert
RUN make-ssl-cert generate-default-snakeoil
ARG COMPONENT=beam-connect
COPY --from=chmodder /app/$COMPONENT /usr/local/bin/samply
ENTRYPOINT [ "/usr/local/bin/samply" ]
24 changes: 0 additions & 24 deletions Dockerfile.ci

This file was deleted.

4 changes: 2 additions & 2 deletions dev/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ services:
- proxy1
build:
context: ../
dockerfile: Dockerfile.ci
dockerfile: Dockerfile
ports:
- 8062:8062
volumes:
Expand All @@ -66,7 +66,7 @@ services:
- proxy2
build:
context: ../
dockerfile: Dockerfile.ci
dockerfile: Dockerfile
ports:
- 8063:8063
volumes:
Expand Down
4 changes: 2 additions & 2 deletions dev/start
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ function build() {
BUILD_DOCKER=0
BACK=$(pwd)
cd $SD/..
CONNECT=./target/debug/connect
CONNECT=./target/debug/beam-connect
if [ ! -x ./artifacts/binaries-$ARCH ]; then
echo "Binaries missing -- building ..."
BUILD="$(cargo build $@ --message-format=json)"
Expand Down Expand Up @@ -114,7 +114,7 @@ function start_ci {
pki/pki devsetup
echo "$VAULT_TOKEN" > ./pki/pki.secret
build $@
docker-compose up --no-build --no-recreate -d
docker-compose up --no-recreate -d
for ADDR in $P1 $P2; do
TRIES=1
while [ $TRIES -ne 0 ]; do
Expand Down
25 changes: 25 additions & 0 deletions dev/test
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/bin/bash -e

SD=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )

cd $SD

case "$1" in
noci)
shift
cd ..
cargo test $@
;;
ci)
shift
$SD/start ci $@
for testbin in $SD/../testbinaries/*; do
chmod +x $testbin
$testbin
done
;;
*)
echo "Usage: $0 noci|ci"
exit 1
;;
esac

0 comments on commit 3c8fbe4

Please sign in to comment.