feat(ci-cd): Add auto release

This commit is contained in:
Myzel394 2024-11-09 21:28:50 +01:00
parent 346b14bd53
commit a37a47f5d1
No known key found for this signature in database
GPG Key ID: ED20A1D1D423AF3F
3 changed files with 46 additions and 0 deletions

22
.github/workflows/release.yaml vendored Normal file
View File

@ -0,0 +1,22 @@
name: Build and release
on:
release:
types: [published]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Add SSH identity key
run: |
mkdir -p ~/.ssh
echo "${{ secrets.SSH_PRIVATE_KEY }}" > ~/.ssh/id_rsa
chmod 600 ~/.ssh/id_rsa
ssh-keyscan -H ${{ secrets.SERVER_IP }} >> ~/.ssh/known_hosts
- name: Build & upload image
run: ./upload_to_server.sh ${{ secrets.SERVER_IP }} ${{ secrets.SSH_USER }}

15
Dockerfile Normal file
View File

@ -0,0 +1,15 @@
FROM oven/bun:alpine
WORKDIR /app
COPY entrypoint.sh ./
COPY package.json ./
COPY bun.lockb ./
COPY src ./src
RUN bun install
EXPOSE 3000
ENTRYPOINT ["bun", "run", "start"]

9
upload_to_server.sh Executable file
View File

@ -0,0 +1,9 @@
ip=$1
user=$2
docker buildx build --platform linux/amd64 . --tag amiopen:latest
docker save -o amiopen.tar amiopen:latest
scp amiopen.tar $user@$ip:~/amiopen/amiopen.tar
ssh $user@$ip "cd ~/amiopen && docker container stop amiopen && docker container rm amiopen && docker load -i amiopen.tar && docker compose up -d"