Skip to content

Commit

Permalink
ci(image-search-server): use docker
Browse files Browse the repository at this point in the history
  • Loading branch information
SunsetTechuila committed Dec 30, 2024
1 parent a4050de commit 7656f04
Show file tree
Hide file tree
Showing 6 changed files with 81 additions and 40 deletions.
25 changes: 25 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
.cache
.github
.husky
.vscode
node_modules
commitlintrc.json
.dockerignore
.editorconfig
.gitattributes
.npmrc
Dockerfile*
docker-compose*
LICENSE

**/eslint.config.*
**/.prettier*
**/.gitignore
**/*.md
**/.env*

# mtcute
client.session*

packages/image-search-bot
!packages/image-search-bot/package.json
63 changes: 24 additions & 39 deletions .github/workflows/deploy_server.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ on:

jobs:
check-credentials:
name: Check credentials
name: Check for SSH credentials
runs-on: ubuntu-latest
environment: production
outputs:
is_set: ${{ steps.check.outputs.is_set }}
steps:
- name: Check SSH credentials
- name: Perform check
id: check
run: |
if [[ '${{ secrets.SSH_KEY }}' && '${{ secrets.SSH_HOST }}' && '${{ secrets.SSH_USERNAME }}' ]]; then
Expand All @@ -35,63 +35,48 @@ jobs:
with:
cwd: packages/image-search-server

# blocker for commented: https://github.com/oven-sh/bun/issues/6567
deploy:
name: Deploy server
runs-on: ubuntu-latest
needs: check-package
environment: production
defaults:
run:
working-directory: packages/image-search-server
steps:
# - name: Checkout repo
# uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
- name: Checkout repo
uses: actions/checkout@cbb722410c2e876e24abbe8de2cc27693e501dcb

- name: Build image
run: |
docker build --platform linux/arm64 --pull --rm -f 'Dockerfile' -t image-search-server:latest '.'
docker save -o image-search-server.tar image-search-server:latest
- name: Package image
run: gzip image-search-server.tar

- name: Setup SSH
run: |
mkdir -p ~/.ssh
echo '${{ secrets.SSH_KEY }}' > ~/.ssh/id_rsa
chmod 600 ~/.ssh/id_rsa
echo 'StrictHostKeyChecking no' >> ~/.ssh/config
working-directory: .

# - name: Setup Bun
# uses: oven-sh/setup-bun@f4d14e03ff726c06358e5557344e1da148b56cf7

# - name: Install dependencies
# run: bun install --frozen-lockfile --production

# - name: Build
# run: bun run build
# - name: Deploy
# run: |
# scp dist/image-search-server '${{ secrets.SSH_USERNAME }}@${{ secrets.SSH_HOST }}:~/image-search-server/image-search-server_new'
# ssh '${{ secrets.SSH_USERNAME }}@${{ secrets.SSH_HOST }}' /bin/bash << EOF
# pkill -f image-search-server || true
# cd ~/image-search-server
# mv image-search-server_new image-search-server
# nohup ./image-search-server > /dev/null 2>&1 &
# EOF
- name: Deploy image
run: scp image-search-server.tar.gz docker-compose.yml ${{ secrets.SSH_USERNAME }}@${{ secrets.SSH_HOST }}:/tmp/

# temporary solution
- name: Deploy
- name: Run container
uses: appleboy/ssh-action@66aa4d343bf909ac4fa0ac52f4e62a9adc354c95
with:
host: ${{ secrets.SSH_HOST }}
username: ${{ secrets.SSH_USERNAME }}
key: ${{ secrets.SSH_KEY }}
script: |
cd
repository_name="$(basename '${{ github.repository }}')"
if [[ ! -d "$repository_name" ]]; then
git clone '${{ github.server_url }}/${{ github.repository }}'
if [[ ! -d "image-search-server" ]]; then
echo "Create the image-search-server folder with the .env file in it first." >&2
exit 1
fi
cd "$repository_name"
pkill -f 'bun run start$'
git fetch --all
git reset --hard origin/master
cd packages/image-search-server
bun install --frozen-lockfile --production
nohup bun run start > /dev/null 2>&1 &
cd image-search-server
docker compose down
docker rmi image-search-server:latest
mv -f /tmp/image-search-server.tar.gz /tmp/docker-compose.yml ./
docker load -i image-search-server.tar.gz
docker compose up -d
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
node_modules/
.env*
.cache/
image-search-server.tar*
3 changes: 2 additions & 1 deletion .vscode/extensions.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"dbaeumer.vscode-eslint",
"esbenp.prettier-vscode",
"oven.bun-vscode",
"github.vscode-github-actions"
"github.vscode-github-actions",
"ms-azuretools.vscode-docker"
]
}
18 changes: 18 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# syntax=docker/dockerfile:1.7-labs

FROM oven/bun:1 AS base

FROM base AS install
WORKDIR /temp
COPY --exclude=**/src . .
RUN cd packages/image-search-server && bun install --frozen-lockfile --production

FROM base AS release
WORKDIR /server
COPY --from=install /temp/node_modules node_modules
COPY . .
RUN cd /server/packages/image-search-server && bun install --frozen-lockfile --production

USER bun
EXPOSE 3000/tcp
ENTRYPOINT [ "bun", "run", "--cwd", "packages/image-search-server", "start" ]
11 changes: 11 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
services:
server:
image: image-search-server:latest
container_name: image-search-server
restart: unless-stopped
tty: true
volumes:
- ./keys:/packages/image-search-server/keys
env_file: .env
ports:
- 3000:3000

0 comments on commit 7656f04

Please sign in to comment.