ci: add server publisher

This commit is contained in:
Brendan Allan 2022-04-24 02:53:12 +08:00
parent fb69ccb265
commit 16294ea128
3 changed files with 90 additions and 6 deletions

View file

@ -1,5 +1,5 @@
name: Install deskop dependencies
description: Installs OS-specific dependencies for desktop builds
name: Install dependencies
description: Installs OS-specific dependencies for builds
runs:
using: "composite"
steps:

View file

@ -0,0 +1,53 @@
name: Publish Server
description: Builds and publishes the docker image for the Spacedrive server
inputs:
gh_token:
description: 'A Github PAT'
required: true
runs:
using: 'composite'
steps:
- name: Log in to the Container registry
uses: docker/login-action@v1
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ inputs.gh_token }}
- name: Build Server
shell: bash
run: |
cargo build --release -p server
cp ./target/release/server ./apps/server/server
- name: Determine image name & tag
shell: bash
run: |
if [ "$GITHUB_EVENT_NAME" == "release" ]; then
export IMAGE_TAG=${GITHUB_REF##*/}
else
export IMAGE_TAG=$(git rev-parse --short "$GITHUB_SHA")
fi
export GITHUB_REPOSITORY_LOWER=$(echo $GITHUB_REPOSITORY | awk '{print tolower($0)}')
export IMAGE_NAME="ghcr.io/$GITHUB_REPOSITORY_LOWER/server"
echo "IMAGE_NAME=$IMAGE_NAME" >> $GITHUB_ENV
echo "IMAGE_TAG=$IMAGE_TAG" >> $GITHUB_ENV
echo "Building $IMAGE_NAME:$IMAGE_TAG"
- name: Build & push Docker image
shell: bash
run: |
docker build ./apps/server --tag $IMAGE_NAME:$IMAGE_TAG
docker push $IMAGE_NAME:$IMAGE_TAG
- name: Tag & push image as latest staging image
if: github.event_name != 'release'
shell: bash
run: |
docker tag $IMAGE_NAME:$IMAGE_TAG $IMAGE_NAME:staging
docker push $IMAGE_NAME:staging
- name: Tag & push image as latest production image
if: github.event_name == 'release'
shell: bash
run: |
docker tag $IMAGE_NAME:$IMAGE_TAG $IMAGE_NAME:production
docker push $IMAGE_NAME:production

View file

@ -70,8 +70,8 @@ jobs:
- name: Checkout repository
uses: actions/checkout@v2
- name: Install desktop dependencies
uses: ./.github/actions/install-desktop-deps
- name: Install dependencies
uses: ./.github/actions/install-deps
- name: Setup Node
uses: actions/setup-node@v1
@ -112,8 +112,8 @@ jobs:
- name: Checkout repository
uses: actions/checkout@v2
- name: Install desktop dependencies
uses: ./.github/actions/install-desktop-deps
- name: Install dependencies
uses: ./.github/actions/install-deps
- name: Setup Node
uses: actions/setup-node@v1
@ -157,3 +157,34 @@ jobs:
- name: Publish artifacts
uses: ./.github/actions/publish-desktop-artifacts
deploy-server:
name: Deploy server
runs-on: ubuntu-latest
needs: build-rust
steps:
- name: Checkout repository
uses: actions/checkout@v
- name: Install dependencies
uses: ./.github/actions/install-deps
- name: Install Rust stable
uses: actions-rs/toolchain@v1
with:
toolchain: stable
profile: minimal
override: true
components: rustfmt, rust-src
- name: Cache Rust Dependencies
uses: Swatinem/rust-cache@cb2cf0cc7c5198d3364b9630e2c3d457f160790c
with:
sharedKey: all-${{ matrix.platform }}
- name: Publish docker image
uses: ./.github/actions/publish-server
with:
gh_token: ${{ secrets.GITHUB_TOKEN }}
# TODO: Trigger deploy