Merge pull request #362 from Sunagatov/feature/github-issue-274 #325
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 MAIL_PASSWORD=${{ secrets.MAIL_PASSWORD }} \ | |
-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 |