Skip to content

Commit 6a6c180

Browse files
- feat: Add github action dev yml
1 parent f1ca027 commit 6a6c180

File tree

1 file changed

+93
-0
lines changed

1 file changed

+93
-0
lines changed

.github/workflows/dev.yml

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
name: Dev Build, Push and Deploy
2+
3+
on:
4+
push:
5+
branches:
6+
- develop
7+
8+
jobs:
9+
build-and-push:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- name: Checkout
13+
uses: actions/checkout@v4
14+
15+
- name: Set up QEMU
16+
uses: docker/setup-qemu-action@v3
17+
18+
- name: Set up Docker Buildx
19+
uses: docker/setup-buildx-action@v3
20+
21+
- name: Log in to Docker Hub
22+
uses: docker/login-action@v3
23+
with:
24+
username: ${{ secrets.DOCKER_USERNAME }}
25+
password: ${{ secrets.DOCKER_PASSWORD }}
26+
27+
- name: Build and push Docker image
28+
uses: docker/build-push-action@v4
29+
with:
30+
context: .
31+
file: ./Dockerfile
32+
push: true
33+
tags: patterntechnology/pattern-core-api:latest
34+
platforms: linux/amd64
35+
cache-from: type=gha
36+
cache-to: type=gha,mode=max
37+
38+
deploy:
39+
needs: build-and-push
40+
runs-on: ubuntu-latest
41+
steps:
42+
- name: Deploy to Server
43+
uses: appleboy/ssh-action@v0.1.7
44+
with:
45+
host: ${{ secrets.SERVER_HOST_DEV }}
46+
username: ${{ secrets.SERVER_USER_DEV }}
47+
key: ${{ secrets.SERVER_SSH_KEY_DEV }}
48+
port: ${{ secrets.SERVER_SSH_PORT_DEV }}
49+
script: |
50+
echo "Pulling the latest Docker image..."
51+
docker pull patterntechnology/pattern-core-api:latest
52+
53+
echo "Stopping and removing the old container (if exists)..."
54+
docker stop pattern-core-api || true
55+
docker rm pattern-core-api || true
56+
57+
echo "Starting a new container with environment variables..."
58+
docker run -d \
59+
--name pattern-core-api \
60+
-p 5001:3000 \
61+
-e OPENAI_API_KEY=${{ secrets.OPENAI_API_KEY }} \
62+
-e POSTGRES_HOST=postgres \
63+
-e POSTGRES_PORT=5432 \
64+
-e POSTGRES_DB=pattern-core \
65+
-e POSTGRES_USERNAME=${{ secrets.POSTGRES_USERNAME }} \
66+
-e POSTGRES_PASSWORD=${{ secrets.POSTGRES_PASSWORD }} \
67+
-e JWT_SECRET_KEY=${{ secrets.JWT_SECRET_KEY }} \
68+
-e QDRANT_HOST=http://qdrant:6333 \
69+
-e QDRANT_COLLECTION=pattern-core \
70+
-e LANGCHAIN_API_KEY=${{ secrets.LANGCHAIN_API_KEY }} \
71+
-e GOOGLE_SEARCH_URL=https://google.serper.dev/search \
72+
-e REDDIT_SEARCH_URL=https://reddit-scraper2.p.rapidapi.com/search_posts \
73+
-e LINKEDIN_SEARCH_URL=https://linkedin-data-api.p.rapidapi.com/search-posts \
74+
-e WEATHER_URL=https://api.weatherapi.com/v1/current.json \
75+
-e ETH_RPC=https://ethereum-rpc.publicnode.com \
76+
-e GOLDRUSH_URL=https://api.covalenthq.com \
77+
-e EXA_URL=https://api.exa.ai \
78+
-e PERPLEXITY_URL=https://api.perplexity.ai \
79+
-e TAVILY_URL=https://api.tavily.com \
80+
-e SECRET_KEY=${{ secrets.SECRET_KEY }} \
81+
# Add additional environment variables as needed
82+
patterntechnology/pattern-core-api:latest
83+
84+
# Wait a few seconds to give the container time to start
85+
sleep 5
86+
87+
# Verify if the container is running
88+
if docker ps | grep -q pattern-core-api; then
89+
echo "Container is running successfully. Removing unused images..."
90+
docker image prune -f
91+
else
92+
echo "Container failed to start. Skipping image cleanup."
93+
fi

0 commit comments

Comments
 (0)