Deploy #28
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: Deploy | |
on: | |
workflow_dispatch: | |
env: | |
REGISTRY: ghcr.io | |
IMAGE_TAG: latest | |
jobs: | |
publish-image: | |
runs-on: ubuntu-latest | |
permissions: | |
contents: read | |
packages: write | |
steps: | |
- name: Get repository code | |
uses: actions/checkout@v4 | |
- name: Log in to the Container registry | |
uses: docker/login-action@v3 | |
with: | |
registry: ${{ env.REGISTRY }} | |
username: ${{ github.actor }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: Extract metadata (tags, labels) for Docker | |
id: meta | |
uses: docker/metadata-action@v5 | |
with: | |
images: ${{ env.REGISTRY }}/${{ github.repository }} | |
- name: Get image name in lowercase | |
id: formatting | |
uses: ASzc/change-string-case-action@v5 | |
with: | |
string: ${{ github.repository }} | |
- name: Build and push Frontend Docker image | |
uses: docker/build-push-action@v5 | |
with: | |
context: ./frontend | |
file: ./frontend/Dockerfile | |
push: true | |
tags: ${{ steps.meta.outputs.tags }},${{ env.REGISTRY }}/${{ steps.formatting.outputs.lowercase }}-frontend:${{env.IMAGE_TAG}} | |
labels: ${{ steps.meta.outputs.labels }} | |
- name: Build and push Backend Docker image | |
uses: docker/build-push-action@v5 | |
with: | |
context: ./backend | |
file: ./backend/Dockerfile | |
push: true | |
tags: ${{ steps.meta.outputs.tags }},${{ env.REGISTRY }}/${{ steps.formatting.outputs.lowercase }}-backend:${{env.IMAGE_TAG}} | |
labels: ${{ steps.meta.outputs.labels }} | |
# TODO: убрать хардкоды из путей и тд | |
deploy: | |
needs: [publish-image] | |
runs-on: ubuntu-latest | |
steps: | |
- name: Get repository code | |
uses: actions/checkout@v4 | |
- name: Stop all containers | |
uses: appleboy/[email protected] | |
with: | |
host: ${{ secrets.SERVER_IP }} | |
username: ${{ secrets.SERVER_USERNAME }} | |
password: ${{ secrets.SERVER_PASSWORD }} | |
script: docker stop $(docker ps -a -q) | |
- name: Pull latest frontend image version | |
uses: appleboy/[email protected] | |
with: | |
host: ${{ secrets.SERVER_IP }} | |
username: ${{ secrets.SERVER_USERNAME }} | |
password: ${{ secrets.SERVER_PASSWORD }} | |
script: docker pull ${{ env.REGISTRY }}/${{ github.repository }}-frontend:${{env.IMAGE_TAG}} | |
- name: Pull latest backend image version | |
uses: appleboy/[email protected] | |
with: | |
host: ${{ secrets.SERVER_IP }} | |
username: ${{ secrets.SERVER_USERNAME }} | |
password: ${{ secrets.SERVER_PASSWORD }} | |
script: docker pull ${{ env.REGISTRY }}/${{ github.repository }}-backend:${{env.IMAGE_TAG}} | |
- name: Copy docker compose config to remote server | |
uses: appleboy/[email protected] | |
with: | |
host: ${{ secrets.SERVER_IP }} | |
username: ${{ secrets.SERVER_USERNAME }} | |
password: ${{ secrets.SERVER_PASSWORD }} | |
source: "docker-compose.prod.yml" | |
target: /tmp | |
- name: Run container | |
uses: appleboy/[email protected] | |
with: | |
host: ${{ secrets.SERVER_IP }} | |
username: ${{ secrets.SERVER_USERNAME }} | |
password: ${{ secrets.SERVER_PASSWORD }} | |
script: NOTISEND_TOKEN=${{ secrets.NOTISEND_TOKEN }} docker compose -f /tmp/docker-compose.prod.yml up -d |