Skip to content

Commit

Permalink
Merge pull request #4 from ashenBlade/deploy
Browse files Browse the repository at this point in the history
Deploy
  • Loading branch information
ashenBlade authored Oct 28, 2022
2 parents ef2d824 + 9c1b3bf commit 0384eab
Show file tree
Hide file tree
Showing 29 changed files with 319 additions and 652 deletions.
87 changes: 87 additions & 0 deletions .github/workflows/yandex-cloud.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
name: Docker Image CI

on:
pull:
branches: [ "main" ]

env:
FRONTEND_IMAGE: ${{ secrets.DOCKER_HUB_USERNAME }}/text-to-image-frontend:${{ github.sha }}
BACKEND_IMAGE: ${{ secrets.DOCKER_HUB_USERNAME }}/text-to-image-api:${{ github.sha }}
NGINX_IMAGE: ${{ secrets.DOCKER_HUB_USERNAME }}/text-to-image-nginx:${{ github.sha }}

jobs:
build-docker:
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v3

- name: Login to Dockerhub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKER_HUB_USERNAME }}
password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }}

- name: Setup Docker Buildx
uses: docker/setup-buildx-action@v2

- name: Build Backend
uses: docker/build-push-action@v3
with:
context: src/backend
file: ./Dockerfile
push: true
tags: ${{ env.BACKEND_IMAGE }}

- name: Build Frontend
uses: docker/build-push-action@v3
with:
context: src/backend
file: ./Dockerfile
push: true
build-args: |
server_url: ${{ secrets.API_SERVER_URL }}
tags: ${{ env.FRONTEND_IMAGE }}

- name: Compose together with Nginx
uses: docker/build-push-action@v3
with:
context: nginx
file: ./Dockerfile
push: true
tags: ${{ env.NGINX_IMAGE }}


update-yc:
runs-on: ubuntu-latest
needs: [build-docker]
steps:

- name: Login to Yandex Cloud
id: logic-cr
uses: yc-actions/yc-cr-login@v1
with:
yc-sa-json-credentials: ${{ secrets.YC_SA_JSON_CREDENTIALS }}


- name: Deploy COI VM
id: deploy-coi
uses: yc-actions/yc-coi-deploy@v1
env:
BACKEND_IMAGE: $BACKEND_IMAGE
FRONTEND_IMAGE: $FRONTEND_IMAGE
NGINX_IMAGE: $NGINX_IMAGE
FRONTEND_ORIGINS: ${{ secrets.FRONTEND_ORIGINS }}
YC_VM_SSH: ${{ secrets.YC_VM_SSH }}
with:
yc-sa-json-credentials: ${{ secrets.YC_SA_JSON_CREDENTIALS }}
folder-id: ${{ secrets.YC_FOLDER_ID }}
VM-name: ${{ secrets.YC_VM_NAME }}
vm-service-account-id: ${{ secrets.YC_SERVICE_ACCOUNT_ID }}
vm-cores: 1
vm-memory: 1Gb
vm-core-fraction: 20
vm-subnet-id: ${{ secrets.YC_SUBNET_ID }}
docker-compose-path: './yandex-cloud/docker-compose.yc.yml'
user-data-path: './yandex-cloud/user-data.yml'
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -130,3 +130,5 @@ dmypy.json

# PyCharm folders
.idea

*.local.*
5 changes: 5 additions & 0 deletions nginx/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
FROM nginx:alpine

COPY ./nginx.yc.conf /etc/nginx/conf.d/default.conf
EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]
11 changes: 11 additions & 0 deletions nginx/nginx.yc.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
server {
listen 80;

location /api {
proxy_pass http://backend;
}

location / {
proxy_pass http://frontend;
}
}
Loading

0 comments on commit 0384eab

Please sign in to comment.