Skip to content

Merge pull request #22 from MindsHub/develop #189

Merge pull request #22 from MindsHub/develop

Merge pull request #22 from MindsHub/develop #189

Workflow file for this run

name: Rust
on:
push:
branches: [ "main" ]
env:
CARGO_TERM_COLOR: always
REGISTRY_IMAGE: mindshubalessio/insigno
jobs:
test:
# service containers to run with `build-test`
services:
# label used to access the service container
postgres:
# Docker Hub image
image: postgis/postgis:15-3.3
# service environment variables
# `POSTGRES_HOST` is `postgres`
env:
# optional (defaults to `postgres`)
POSTGRES_DB: insignorocketdb
# required
POSTGRES_PASSWORD: test
# optional (defaults to `5432`)
POSTGRES_PORT: 5432
# optional (defaults to `postgres`)
POSTGRES_USER: mindshub
ports:
# maps tcp port 5432 on service container to the host
- 5432:5432
# set health checks to wait until postgres has started
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v3
- run: rustup toolchain install stable --profile minimal
#- name: Cache rust
# uses: Swatinem/[email protected]
# with:
# cache-all-crates: "true"
# prefix-key: "v0-rust"
# shared-key: "test"
# key: "test"
#cache-on-failure: "true"
#cache-directories: ".\n~.cargo"
# - name: Install deps
# run: sudo apt update
- uses: FedericoCarboni/setup-ffmpeg@v2
id: setup-ffmpeg
- name: Install Diesel-cli
uses: baptiste0928/cargo-install@v2
with:
crate: diesel_cli
#version: "^0.5" #
#- name: Install-diesel-Cli
# run: cargo install diesel_cli --no-default-features --features "postgres"
- name: Make migrations
run: diesel database reset --database-url="postgres://mindshub:test@localhost:5432/insignorocketdb"
- name: "CI testing"
run: cargo test -- --test-threads=1
build:
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v3
- run: rustup toolchain install stable --profile minimal
# - name: Cache rust
# uses: Swatinem/[email protected]
# with:
# cache-all-crates: "true"
# prefix-key: "v0-rust"
# shared-key: "build"
# key: "build"
# cache-directories: "."
- name: Build
run: cargo build --release --bin insigno
- uses: actions/upload-artifact@v3
with:
name: build-result
path: target/release/insigno
document:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- run: rustup toolchain install stable --profile minimal
#- run: rustup override set nightly
# - name: Cache rust
# uses: Swatinem/[email protected]
# with:
# cache-all-crates: "true"
# prefix-key: "v0-rust-doc"
# shared-key: "test"
#à key: "test"
- name: BuildDoc
run: ./document
- name: parse
uses: actions/upload-pages-artifact@v1
with:
name: "documentation"
path: "docs"
deploy:
# Grant GITHUB_TOKEN the permissions required to make a Pages deployment
permissions:
pages: write # to deploy to Pages
id-token: write # to verify the deployment originates from an appropriate source
contents: write
# Deploy to the github-pages environment
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
runs-on: ubuntu-22.04
needs: [build, test, document]
steps:
- uses: actions/checkout@v3
- uses: actions/download-artifact@v3
with:
name: build-result
path: target/release
- name: Deploy to GitHub Pages
uses: actions/deploy-pages@v2
id: deployment
with:
artifact_name: "documentation"
- name: Kill Server
uses: appleboy/[email protected]
with:
host: ${{secrets.SSH_HOST}}
username: ${{secrets.SSH_USER}}
password: ${{secrets.SSH_PASS}}
port: ${{secrets.SSH_PORT}}
script: |
if pgrep insigno; then pkill insigno; fi
- name: Copy exec via SSH
uses: appleboy/scp-action@master
with:
host: ${{secrets.SSH_HOST}}
username: ${{secrets.SSH_USER}}
password: ${{secrets.SSH_PASS}}
port: ${{secrets.SSH_PORT}}
source: "target/release/insigno"
target: "insigno"
strip_components: 2
- name: Copy exec via SSH
uses: appleboy/scp-action@master
with:
host: ${{secrets.SSH_HOST}}
username: ${{secrets.SSH_USER}}
password: ${{secrets.SSH_PASS}}
port: ${{secrets.SSH_PORT}}
source: "templates/*"
target: "insigno"
- name: Re-run server
uses: appleboy/[email protected]
with:
host: ${{secrets.SSH_HOST}}
username: ${{secrets.SSH_USER}}
password: ${{secrets.SSH_PASS}}
port: ${{secrets.SSH_PORT}}
script: |
cd insigno/
chmod +x ./insigno
nohup ./insigno > nohup.out 2> nohup.err < /dev/null &
docker-build:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
platform:
- linux/amd64
- linux/arm/v6
- linux/arm/v7
- linux/arm64
steps:
- name: Prepare
run: |
platform=${{ matrix.platform }}
echo "PLATFORM_PAIR=${platform//\//-}" >> $GITHUB_ENV
- name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY_IMAGE }}
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ vars.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Build and push by digest
id: build
uses: docker/build-push-action@v6
with:
platforms: ${{ matrix.platform }}
labels: ${{ steps.meta.outputs.labels }}
outputs: type=image,name=${{ env.REGISTRY_IMAGE }},push-by-digest=true,name-canonical=true,push=true
cache-from: type=registry,ref=${{ env.REGISTRY_IMAGE }}:buildcache-${{env.PLATFORM_PAIR}}
cache-to: type=registry,ref=${{ env.REGISTRY_IMAGE }}:buildcache-${{env.PLATFORM_PAIR}},mode=max
- name: Export digest
run: |
mkdir -p /tmp/digests
digest="${{ steps.build.outputs.digest }}"
touch "/tmp/digests/${digest#sha256:}"
- name: Upload digest
uses: actions/upload-artifact@v4
with:
name: digests-${{ env.PLATFORM_PAIR }}
path: /tmp/digests/*
if-no-files-found: error
retention-days: 1
docker-merge:
runs-on: ubuntu-latest
needs:
- docker-build
steps:
- name: Download digests
uses: actions/download-artifact@v4
with:
path: /tmp/digests
pattern: digests-*
merge-multiple: true
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY_IMAGE }}
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ vars.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Create manifest list and push
working-directory: /tmp/digests
run: |
docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \
$(printf '${{ env.REGISTRY_IMAGE }}@sha256:%s ' *)
- name: Inspect image
run: |
docker buildx imagetools inspect ${{ env.REGISTRY_IMAGE }}:${{ steps.meta.outputs.version }}