Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

支持通过github action自动构建docker镜像、自动打包app、自动release #42

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
183 changes: 183 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,183 @@
name: release
env:
DOCKER_REGISTRY: ghcr.io
on:
push:
tags:
- 'v*'
jobs:

build-static:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Setup Node
uses: actions/setup-node@v4
with:
node-version: '20'
cache: npm
- name: Build
run: |
npm install
npm run build
- name: Upload Static
uses: actions/upload-artifact@v4
with:
name: dist
path: dist
build-app:
strategy:
fail-fast: false
matrix:
include:
- os: windows-latest
target: x86_64-pc-windows-msvc
- os: macos-latest
target: x86_64-apple-darwin
runs-on: ${{ matrix.os }}
needs: [ build-static ]
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Download Artifact
uses: actions/download-artifact@v4
- name: Install Rust for windows-latest
uses: dtolnay/rust-toolchain@stable
with:
toolchain: stable
target: ${{ matrix.target }}
- name: Setup Node
uses: actions/setup-node@v4
with:
node-version: '20'
- name: Install Pake cli
run: |
npm install pake-cli
- name: Rust cache restore
uses: actions/cache/restore@v3
id: cache_store
with:
path: |
~/.cargo/bin/
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
node_modules/pake-cli/src-tauri/target/
key: ${{ matrix.os }}-cargo-${{ hashFiles('node_modules/pake-cli/src-tauri/Cargo.lock') }}
- name: Pake
run: |
npx pake ./dist/index.html --name pic-smaller --use-local-file
- name: Upload App Installer
uses: actions/upload-artifact@v4
if: matrix.os == 'windows-latest'
with:
name: windows-installer
path: pic-smaller.msi
- name: Upload App Installer
uses: actions/upload-artifact@v4
if: matrix.os == 'macos-latest'
with:
name: mac-installer
path: pic-smaller.dmg
- name: Rust cache store
uses: actions/cache/save@v3
if: steps.cache_store.outputs.cache-hit != 'true'
with:
path: |
~/.cargo/bin/
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
node_modules/pake-cli/src-tauri/target/
key: ${{ matrix.os }}-cargo-${{ hashFiles('node_modules/pake-cli/src-tauri/Cargo.lock') }}
build-docker-image:
runs-on: ubuntu-latest
needs: [ build-static ]
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Release version
id: release_version
run: |
app_version=$(jq -r '.version' package.json)
echo "app_version=$app_version" >> $GITHUB_ENV
- name: Download Artifact
uses: actions/download-artifact@v4
- name: Set Up Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to the Container registry
uses: docker/login-action@v3
with:
registry: ${{ env.DOCKER_REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Docker Meta
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.DOCKER_REGISTRY }}/${{ github.actor }}/pic-smaller
tags: |
type=raw,value=${{ env.app_version }}
type=raw,value=latest
- name: Build Image
uses: docker/build-push-action@v5
with:
context: .
file: Dockerfile.slim
platforms: |
linux/amd64
linux/arm64/v8
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha, scope=${{ github.workflow }}-docker
cache-to: type=gha, scope=${{ github.workflow }}-docker
create-release:
permissions: write-all
runs-on: ubuntu-latest
needs: [ build-app, build-docker-image ]
steps:
- uses: actions/checkout@v2
- name: Release version
id: release_version
run: |
app_version=$(jq -r '.version' package.json)
echo "app_version=$app_version" >> $GITHUB_ENV

- name: Download Artifact
uses: actions/download-artifact@v4

- name: get release_informations
shell: bash
run: |
mkdir releases
ls -l
mv ./mac-installer/pic-smaller.dmg ./releases/PicSmaller_Mac_v${{ env.app_version }}.dmg
mv ./windows-installer/pic-smaller.msi ./releases/PicSmaller_Win_v${{ env.app_version }}.msi

- name: Create Release
id: create_release
uses: actions/create-release@latest
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: v${{ env.app_version }}
release_name: v${{ env.app_version }}
body: |
## changelog
${{ github.event.commits[0].message }}
## Docker images
- ${{ env.DOCKER_REGISTRY }}/${{ github.actor }}/pic-smaller:latest
- ${{ env.DOCKER_REGISTRY }}/${{ github.actor }}/pic-smaller:${{ env.app_version }}
draft: false
prerelease: false

- name: Upload Release Asset
uses: dwenegar/upload-release-assets@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
release_id: ${{ steps.create_release.outputs.id }}
assets_path: |
./releases/
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@ npm run dev

## Deploy

If you want to independently deploy this project on your own server, the following document based on Docker, and [Dockerfile](./Dockerfile) script has been tested. Within the project root directory, follow the instructions to start docker application
If you want to independently deploy this project on your own server, the following document based on Docker, follow the instructions to start docker application

```bash
# Build docker image from Dockerfile
docker build -t picsmaller .
# Pull docker image from ghcr.io
docker pull ghcr.io/joye61/pic-smaller:latest

# Start a container
docker run -p 3001:3001 -d picsmaller
Expand Down