Merge pull request '81_switch-from-gitlab-ci-cd-to-gitea-actions' (#91) from 81_switch-from-gitlab-ci-cd-to-gitea-actions into main
Reviewed-on: LibreTunes/LibreTunes#91
This commit is contained in:
commit
bf89838297
119
.gitea/workflows/push.yaml
Normal file
119
.gitea/workflows/push.yaml
Normal file
@ -0,0 +1,119 @@
|
|||||||
|
name: Push Workflows
|
||||||
|
on: push
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Checkout repository
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
- name: Setup Rust toolchain
|
||||||
|
id: setup-toolchain
|
||||||
|
uses: dtolnay/rust-toolchain@stable
|
||||||
|
with:
|
||||||
|
toolchain: nightly
|
||||||
|
targets: wasm32-unknown-unknown,x86_64-unknown-linux-gnu
|
||||||
|
- name: Cache
|
||||||
|
uses: Swatinem/rust-cache@v2
|
||||||
|
with:
|
||||||
|
prefix-key: ${{ steps.setup-toolchain.outputs.cachekey }}
|
||||||
|
- name: Install cargo-leptos
|
||||||
|
run: cargo install cargo-leptos
|
||||||
|
- name: Build project
|
||||||
|
env:
|
||||||
|
RUSTFLAGS: "-D warnings"
|
||||||
|
run: cargo-leptos build
|
||||||
|
|
||||||
|
docker-build:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Checkout repository
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
- name: Set up Docker Buildx
|
||||||
|
uses: docker/setup-buildx-action@v3
|
||||||
|
- name: Login to Gitea container registry
|
||||||
|
uses: docker/login-action@v3
|
||||||
|
with:
|
||||||
|
registry: ${{ env.registry }}
|
||||||
|
username: ${{ env.actions_user }}
|
||||||
|
password: ${{ secrets.CONTAINER_REGISTRY_TOKEN }}
|
||||||
|
- name: Get Image Name
|
||||||
|
id: get-image-name
|
||||||
|
run: |
|
||||||
|
echo "IMAGE_NAME=$(echo ${{ env.registry }}/${{ gitea.repository }} | tr '[:upper:]' '[:lower:]')" >> $GITHUB_OUTPUT
|
||||||
|
- name: Build and push Docker image
|
||||||
|
uses: docker/build-push-action@v5
|
||||||
|
with:
|
||||||
|
push: true
|
||||||
|
tags: "${{ steps.get-image-name.outputs.IMAGE_NAME }}:${{ gitea.sha }}"
|
||||||
|
cache-from: type=registry,ref=${{ steps.get-image-name.outputs.IMAGE_NAME }}:${{ gitea.sha }}
|
||||||
|
cache-to: type=inline
|
||||||
|
- name: Build and push Docker image with "latest" tag
|
||||||
|
uses: docker/build-push-action@v5
|
||||||
|
if: gitea.ref == 'refs/heads/main'
|
||||||
|
with:
|
||||||
|
push: true
|
||||||
|
tags: "${{ steps.get-image-name.outputs.IMAGE_NAME }}:latest"
|
||||||
|
cache-from: type=registry,ref=${{ steps.get-image-name.outputs.IMAGE_NAME }}:latest
|
||||||
|
cache-to: type=inline
|
||||||
|
|
||||||
|
test:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Checkout repository
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
- name: Setup Rust toolchain
|
||||||
|
id: setup-toolchain
|
||||||
|
uses: dtolnay/rust-toolchain@stable
|
||||||
|
with:
|
||||||
|
toolchain: nightly
|
||||||
|
targets: wasm32-unknown-unknown,x86_64-unknown-linux-gnu
|
||||||
|
- name: Cache
|
||||||
|
uses: Swatinem/rust-cache@v2
|
||||||
|
with:
|
||||||
|
prefix-key: ${{ steps.setup-toolchain.outputs.cachekey }}
|
||||||
|
- name: Test project
|
||||||
|
run: cargo test --all-targets --all-features
|
||||||
|
|
||||||
|
leptos-test:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Checkout repository
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
- name: Setup Rust toolchain
|
||||||
|
id: setup-toolchain
|
||||||
|
uses: dtolnay/rust-toolchain@stable
|
||||||
|
with:
|
||||||
|
toolchain: nightly
|
||||||
|
targets: wasm32-unknown-unknown,x86_64-unknown-linux-gnu
|
||||||
|
- name: Cache
|
||||||
|
uses: Swatinem/rust-cache@v2
|
||||||
|
with:
|
||||||
|
prefix-key: ${{ steps.setup-toolchain.outputs.cachekey }}
|
||||||
|
- name: Install cargo-leptos
|
||||||
|
run: cargo install cargo-leptos
|
||||||
|
- name: Run Leptos tests
|
||||||
|
run: cargo-leptos test
|
||||||
|
|
||||||
|
docs:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Checkout repository
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
- name: Setup Rust toolchain
|
||||||
|
id: setup-toolchain
|
||||||
|
uses: dtolnay/rust-toolchain@stable
|
||||||
|
with:
|
||||||
|
toolchain: nightly
|
||||||
|
targets: wasm32-unknown-unknown,x86_64-unknown-linux-gnu
|
||||||
|
- name: Cache
|
||||||
|
uses: Swatinem/rust-cache@v2
|
||||||
|
with:
|
||||||
|
prefix-key: ${{ steps.setup-toolchain.outputs.cachekey }}
|
||||||
|
- name: Generate docs
|
||||||
|
run: cargo doc --no-deps
|
||||||
|
- name: Upload docs
|
||||||
|
uses: actions/upload-artifact@v3
|
||||||
|
with:
|
||||||
|
name: docs
|
||||||
|
path: target/doc
|
101
.gitlab-ci.yml
101
.gitlab-ci.yml
@ -1,101 +0,0 @@
|
|||||||
# Build the project
|
|
||||||
build:
|
|
||||||
needs: []
|
|
||||||
image: $CI_REGISTRY/libretunes/ops/docker-leptos:latest
|
|
||||||
variables:
|
|
||||||
RUSTFLAGS: "-D warnings"
|
|
||||||
script:
|
|
||||||
- cargo-leptos build
|
|
||||||
|
|
||||||
.docker:
|
|
||||||
image: docker:latest
|
|
||||||
services:
|
|
||||||
- docker:dind
|
|
||||||
tags:
|
|
||||||
- docker
|
|
||||||
before_script:
|
|
||||||
- docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
|
|
||||||
|
|
||||||
# Build the docker image and push it to the registry
|
|
||||||
docker-build:
|
|
||||||
needs: ["build"]
|
|
||||||
extends: .docker
|
|
||||||
script:
|
|
||||||
- docker build -t $CI_REGISTRY_IMAGE:$CI_COMMIT_SHORT_SHA .
|
|
||||||
# If running on the default branch, tag as latest
|
|
||||||
- if [ "$CI_COMMIT_BRANCH" == "$CI_DEFAULT_BRANCH" ]; then docker tag
|
|
||||||
$CI_REGISTRY_IMAGE:$CI_COMMIT_SHORT_SHA
|
|
||||||
$CI_REGISTRY_IMAGE:latest; fi
|
|
||||||
- docker push $CI_REGISTRY_IMAGE --all-tags
|
|
||||||
|
|
||||||
# Run leptos tests
|
|
||||||
leptos-tests:
|
|
||||||
needs: ["build"]
|
|
||||||
image: $CI_REGISTRY/libretunes/ops/docker-leptos:latest
|
|
||||||
script:
|
|
||||||
- cargo-leptos test
|
|
||||||
|
|
||||||
# Run all tests
|
|
||||||
tests:
|
|
||||||
needs: ["build"]
|
|
||||||
image: $CI_REGISTRY/libretunes/ops/docker-leptos:latest
|
|
||||||
script:
|
|
||||||
- cargo test --all-targets --all-features
|
|
||||||
|
|
||||||
# Generate docs
|
|
||||||
cargo-doc:
|
|
||||||
needs: []
|
|
||||||
image: rust:slim
|
|
||||||
script:
|
|
||||||
- cargo doc --no-deps
|
|
||||||
artifacts:
|
|
||||||
paths:
|
|
||||||
- target/doc
|
|
||||||
|
|
||||||
# Start the review environment
|
|
||||||
start-review:
|
|
||||||
extends: .docker
|
|
||||||
rules:
|
|
||||||
- if: $CI_PIPELINE_SOURCE == "merge_request_event"
|
|
||||||
when: manual
|
|
||||||
script:
|
|
||||||
- apk add curl openssl
|
|
||||||
- cd cicd
|
|
||||||
- echo "$CLOUDFLARE_TUNNEL_AUTH_JSON" > tunnel-auth.json
|
|
||||||
- ./add-dns.sh $CLOUDFLARE_ZONE_ID review-$CI_COMMIT_SHORT_SHA libretunes-auto-review $CLOUDFLARE_API_TOKEN $CLOUDFLARE_TUNNEL_ID
|
|
||||||
- ./create-tunnel-config.sh http://libretunes:3000 review-$CI_COMMIT_SHORT_SHA.libretunes.xyz $CLOUDFLARE_TUNNEL_ID
|
|
||||||
- export COMPOSE_PROJECT_NAME=review-$CI_COMMIT_SHORT_SHA
|
|
||||||
- export POSTGRES_PASSWORD=$(openssl rand -hex 16)
|
|
||||||
- export LIBRETUNES_VERSION=$CI_COMMIT_SHORT_SHA
|
|
||||||
- docker compose --file docker-compose-cicd.yml pull
|
|
||||||
- docker compose --file docker-compose-cicd.yml create
|
|
||||||
- export CONFIG_VOL_NAME=review-${CI_COMMIT_SHORT_SHA}_cloudflared-config
|
|
||||||
- export TMP_CONTAINER_NAME=$(docker run --rm -d -v $CONFIG_VOL_NAME:/data busybox sh -c "sleep infinity")
|
|
||||||
- docker cp tunnel-auth.json $TMP_CONTAINER_NAME:/data/auth.json
|
|
||||||
- docker cp cloudflared-tunnel-config.yml $TMP_CONTAINER_NAME:/data/config.yml
|
|
||||||
- docker stop $TMP_CONTAINER_NAME
|
|
||||||
- docker compose --file docker-compose-cicd.yml up -d
|
|
||||||
environment:
|
|
||||||
name: review/$CI_COMMIT_SHORT_SHA
|
|
||||||
url: https://review-$CI_COMMIT_SHORT_SHA.libretunes.xyz
|
|
||||||
on_stop: stop-review
|
|
||||||
auto_stop_in: 1 week
|
|
||||||
|
|
||||||
# Stop the review environment
|
|
||||||
stop-review:
|
|
||||||
needs: ["start-review"]
|
|
||||||
extends: .docker
|
|
||||||
rules:
|
|
||||||
- if: $CI_PIPELINE_SOURCE == "merge_request_event"
|
|
||||||
when: manual
|
|
||||||
allow_failure: true
|
|
||||||
script:
|
|
||||||
- apk add jq curl
|
|
||||||
- ./cicd/remove-dns.sh $CLOUDFLARE_ZONE_ID review-$CI_COMMIT_SHORT_SHA.libretunes.xyz libretunes-auto-review $CLOUDFLARE_API_TOKEN
|
|
||||||
- export COMPOSE_PROJECT_NAME=review-$CI_COMMIT_SHORT_SHA
|
|
||||||
- export LIBRETUNES_VERSION=$CI_COMMIT_SHORT_SHA
|
|
||||||
- docker compose --file cicd/docker-compose-cicd.yml down
|
|
||||||
- docker compose --file cicd/docker-compose-cicd.yml rm -f -v
|
|
||||||
environment:
|
|
||||||
name: review/$CI_COMMIT_SHORT_SHA
|
|
||||||
action: stop
|
|
Loading…
x
Reference in New Issue
Block a user