-
-
Notifications
You must be signed in to change notification settings - Fork 111
75 lines (68 loc) · 3.58 KB
/
dev-branch-pr-deployment-pipeline.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
name: Build and Deploy
on:
push:
branches:
- development
jobs:
build-and-push-docker-image:
name: Build and push a new docker image
runs-on: ubuntu-latest
steps:
- name: Checkout the source code from the Github repository
uses: actions/checkout@v4
- name: Login to Dockerhub
uses: docker/login-action@v3
with:
username: ${{ vars.DOCKER_HUB_ACCOUNT_NAME }}
password: ${{ secrets.DOCKER_HUB_TOKEN }}
- name: Build a new docker image
run: docker build -t ${{ vars.DOCKER_HUB_ACCOUNT_NAME }}/${{ vars.DOCKER_IMAGE_NAME }}:latest-version .
- name: Push a new docker image into Dockerhub
run: docker push ${{ vars.DOCKER_HUB_ACCOUNT_NAME }}/${{ vars.DOCKER_IMAGE_NAME }}:latest-version
deploy-app-to-server:
name: Deploy application to remote server via SSH
runs-on: ubuntu-latest
needs: build-and-push-docker-image
steps:
- name: Set DOCKER_IMAGE_TAG
run: echo "DOCKER_IMAGE_TAG=latest" >> $GITHUB_ENV
- name: Deploy image via SSH
uses: appleboy/[email protected]
with:
host: ${{ secrets.DEV_SSH_HOST }}
port: ${{ secrets.DEV_SSH_PORT }}
username: ${{ secrets.DEV_SSH_USER }}
password: ${{ secrets.DEV_SSH_PASSWORD }}
script: |
echo "${{ secrets.DOCKER_HUB_TOKEN }}" | docker login -u ${{ vars.DOCKER_HUB_ACCOUNT_NAME }} --password-stdin
docker stop ${{ vars.DOCKER_CONTAINER_NAME }} || true
docker rm ${{ vars.DOCKER_CONTAINER_NAME }} || true
docker rmi ${{ vars.DOCKER_HUB_ACCOUNT_NAME }}/${{ vars.DOCKER_IMAGE_NAME }}:latest-version || true
docker pull ${{ vars.DOCKER_HUB_ACCOUNT_NAME }}/${{ vars.DOCKER_IMAGE_NAME }}:latest-version
docker run -d \
--name ${{ vars.DOCKER_CONTAINER_NAME }} \
--network=${{ vars.DOCKER_NETWORK }} \
-e APP_SERVER_PORT=${{ vars.APP_SERVER_PORT }} \
-e APP_JWT_SECRET=${{ secrets.APP_JWT_SECRET }} \
-e APP_JWT_REFRESH_SECRET=${{ secrets.APP_JWT_REFRESH_SECRET }} \
-e DATASOURCE_PORT=${{ vars.DATASOURCE_PORT }} \
-e DATASOURCE_NAME=${{ vars.DATASOURCE_NAME }} \
-e DATASOURCE_USERNAME=${{ vars.DATASOURCE_USERNAME }} \
-e DATASOURCE_PASSWORD=${{ secrets.DATASOURCE_PASSWORD }} \
-e DATASOURCE_HOST=${{ vars.DATASOURCE_HOST }} \
-e AWS_ACCESS_KEY=${{ secrets.AWS_ACCESS_KEY }} \
-e AWS_SECRET_KEY=${{ secrets.AWS_SECRET_KEY }} \
-e AWS_REGION=${{ vars.AWS_REGION }} \
-e AWS_USER_BUCKET=${{ vars.AWS_USER_BUCKET }} \
-e AWS_PRODUCT_BUCKET=${{ vars.AWS_PRODUCT_BUCKET }} \
-e AWS_DEFAULT_PRODUCT_IMAGES_PATH=${{ vars.AWS_DEFAULT_PRODUCT_IMAGES_PATH }} \
-e GOOGLE_AUTH_CLIENT_ID=${{ vars.GOOGLE_AUTH_CLIENT_ID }} \
-e GOOGLE_AUTH_CLIENT_SECRET=${{ vars.GOOGLE_AUTH_CLIENT_SECRET }} \
-e GOOGLE_AUTH_REDIRECT_URI=${{ vars.GOOGLE_AUTH_REDIRECT_URI }} \
-e REDIS_PORT=${{ vars.REDIS_PORT }} \
-e SPRING_AI_OPENAI_API_KEY=${{ secrets.SPRING_AI_OPENAI_API_KEY }} \
-e STRIPE_SECRET_KEY=${{ secrets.STRIPE_SECRET_KEY }} \
-e STRIPE_WEBHOOK_SECRET=${{ secrets.STRIPE_WEBHOOK_SECRET }} \
-v ${{ vars.APP_DATA_PATH_ON_THE_REMOTE_SERVER }}:/usr/app/logs \
-v ${{ vars.APP_DATA_PATH_ON_THE_REMOTE_SERVER }}/products:/usr/app/products \
zufarexplainedit/iced-latte-backend:latest-version