Skip to content

Commit

Permalink
Upgrade (#2)
Browse files Browse the repository at this point in the history
* add taskfile

* build workflow

* fix build command

* setup docker workflow
  • Loading branch information
Pistonight authored Mar 11, 2024
1 parent 4de70c2 commit c192e54
Show file tree
Hide file tree
Showing 29 changed files with 6,295 additions and 5,996 deletions.
2 changes: 0 additions & 2 deletions .dockerignore

This file was deleted.

53 changes: 53 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
name: Build
on:
push:
branches:
- main
pull_request:
branches:
- main

jobs:
build-client:
name: Build Client
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: arduino/setup-task@v2
with:
version: 3.x
repo-token: ${{ secrets.GITHUB_TOKEN }}
- uses: actions/setup-node@v4
with:
node-version: 18.x
- uses: Swatinem/rust-cache@v2
- run: npm ci
- run: task client:build --output group
- uses: actions/upload-artifact@v4
with:
path: target/frontend
name: app
retention-days: 3

build-server:
name: Build Server
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: arduino/setup-task@v2
with:
version: 3.x
repo-token: ${{ secrets.GITHUB_TOKEN }}
- uses: awalsh128/cache-apt-pkgs-action@latest
with:
packages: musl-tools
- uses: dtolnay/rust-toolchain@stable
with:
targets: x86_64-unknown-linux-musl
- uses: Swatinem/rust-cache@v2
- run: cargo build --bin start --release --target x86_64-unknown-linux-musl
- uses: actions/upload-artifact@v4
with:
path: target/x86_64-unknown-linux-musl/release/start
name: bin
retention-days: 3
48 changes: 48 additions & 0 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
name: Docker
on:
workflow_dispatch:
inputs:
version:
description: "Version tag of the image (e.g. 0.2.0-beta)"
required: true

env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}

jobs:
build-docker:
name: Publish Docker Image
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- uses: actions/checkout@v4
- uses: dawidd6/action-download-artifact@v2
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
workflow: build.yml
commit: ${{ github.sha }}
path: docker/dist
- uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- uses: docker/setup-buildx-action@v3
- uses: docker/metadata-action@v5
id: meta
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=sha
type=sha,format=long
type=raw,value=${{ github.event.inputs.version }}
type=raw,value=latest
- uses: docker/build-push-action@v5
with:
push: true
context: docker
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
39 changes: 39 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: Lint
on:
push:
branches:
- main
pull_request:
branches:
- main

jobs:
lint-typescript:
name: Lint Client
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
submodules: recursive
- uses: arduino/setup-task@v2
with:
version: 3.x
repo-token: ${{ secrets.GITHUB_TOKEN }}
- uses: actions/setup-node@v4
with:
node-version: 18.x
- run: npm ci
- run: task client:check

lint-rust:
name: Lint Server
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: arduino/setup-task@v2
with:
version: 3.x
repo-token: ${{ secrets.GITHUB_TOKEN }}
- uses: dtolnay/rust-toolchain@stable
- uses: Swatinem/rust-cache@v2
- run: task server:check
4 changes: 4 additions & 0 deletions .prettierrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module.exports = {
tabWidth: 4,
endOfLine: "auto",
};
14 changes: 0 additions & 14 deletions Dockerfile

This file was deleted.

28 changes: 0 additions & 28 deletions Justfile

This file was deleted.

38 changes: 7 additions & 31 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,37 +12,13 @@ These icons are inspired by assets from Breath of the Wild and Age of Calamity.

Check out all available icons [here](https://icons.pistonite.org)

# Tech Stack
This project uses [http-rs/tide](https://github.com/http-rs/tide) on the backend for icon manipulation,
and uses [vite](https://vitejs.dev/) + [TypeScript](https://www.typescriptlang.org/) + [React](https://reactjs.org/) on the frontend
for the icon picker web app.

The app is dockerized with an alpine image for efficiency. Check it out on [DockerHub](https://hub.docker.com/repository/docker/pistonite/icons/general)
# Development

## Requirements
Install nodejs and cargo, then install Just:
```
cargo install just
```

Install other cargo and npm dependencies
```
just install
```

## Workflows
|Command|Usage|
|-|-|
|`just server`|Run the server in watch mode (`cargo run` to run in non-watch mode)|
|`just client`|Run the client in watch mode.|
|`just build`|Build the client.|
|`just docker`|Build the docker image (may require `sudo`)|

Note that the server also serves frontend files. If you are not changing the client, you can build the client and only run the server for testing.
## Tools
Make sure you have the following tools:
- A Rust toolchain
- NodeJS
- [task](https://taskfile.dev), used to run commands.

## Docker
To push the docker image:
```
docker push pistonite/icons
```
Once you install those, run `task install` to install the tools and packages.
Then, run `task --list` to see the commands
70 changes: 70 additions & 0 deletions Taskfile.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
version: '3'

tasks:
install:
desc: Install tools and dependencies
cmds:
- rustup update
- cargo install cargo-watch
- npm i

client:dev:
desc: Run client in watch mode
cmds:
- npx vite -- --host

client:build:
desc: Build client
cmds:
- npx tsc
- npx vite build

client:check:
desc: Check for lint and format errors
cmds:
# - task: client:eslint
# vars:
# ESLINT_ARGS: ""
- task: client:prettier
vars:
PRETTIER_ARGS: --check

client:fix:
desc: Fix lint and format errors
cmds:
- task: client:prettier
vars:
PRETTIER_ARGS: --write
# - task: client:eslint
# vars:
# ESLINT_ARGS: --fix

client:prettier:
cmds:
- npx prettier "./**/*.{ts,tsx,json,js,jsx,cjs,css}" {{.PRETTIER_ARGS}}

client:eslint:
cmds:
- npx eslint src --ext ts,tsx --report-unused-disable-directives --max-warnings 0 --cache {{.ESLINT_ARGS}}

server:dev:
desc: Run server in watch mode
cmds:
- cargo watch -x run

server:build:
desc: Build server
cmds:
- cargo build --release

server:check:
desc: Check for lint and format errors
cmds:
- cargo clippy -- -D warnings -D clippy::todo
- cargo fmt --check

server:fix:
desc: Fix lint and format errors
cmds:
- cargo fmt --all

10 changes: 10 additions & 0 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
FROM alpine:latest
EXPOSE 80
ENV APP_DIR=/opt/app
COPY ./dist $APP_DIR
COPY ../img $APP_DIR/img
RUN chmod +x $APP_DIR/bin/start

WORKDIR $APP_DIR

CMD ["./bin/start", "80", "dist/"]
Loading

0 comments on commit c192e54

Please sign in to comment.