-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
133 additions
and
51 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
node_modules |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,55 +1,76 @@ | ||
name: CI | ||
|
||
|
||
|
||
on: | ||
push: | ||
branches: ["main"] | ||
|
||
# Allows you to run this workflow manually from the Actions tab | ||
workflow_dispatch: | ||
|
||
# Sets the GITHUB_TOKEN permissions to allow deployment to GitHub Pages | ||
permissions: | ||
contents: read | ||
pages: write | ||
id-token: write | ||
|
||
# Allow one concurrent deployment | ||
concurrency: | ||
group: 'pages' | ||
cancel-in-progress: true | ||
push: | ||
tags: | ||
- 'v*' | ||
|
||
env: | ||
REGISTRY: ghcr.io | ||
IMAGE_NAME: ${{ github.repository }} | ||
|
||
jobs: | ||
# Single deploy job since we're just deploying | ||
deploy: | ||
environment: | ||
name: github-pages | ||
url: ${{ steps.deployment.outputs.page_url }} | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v3 | ||
- name: Set up Node | ||
uses: actions/setup-node@v3 | ||
with: | ||
node-version: 18 | ||
cache: 'npm' | ||
- name: Install dependencies | ||
run: npm install | ||
- name: Build | ||
# We need to pass the repository name directly to the Vite build command | ||
# as the "base" parameter. | ||
# This is necessary because it aligns with how GitHub Pages functions. | ||
# Here's how you can achieve this: | ||
run: npm run build -- -- --base /${{ github.event.repository.name }} | ||
- name: Create 404.html | ||
run: cp ./app/dist/index.html ./app/dist/404.html | ||
- name: Setup Pages | ||
uses: actions/configure-pages@v3 | ||
- name: Upload artifact | ||
uses: actions/upload-pages-artifact@v1 | ||
with: | ||
# Upload dist repository | ||
path: './app/dist' | ||
- name: Deploy to GitHub Pages | ||
id: deployment | ||
uses: actions/deploy-pages@v1 | ||
build-prod-image: | ||
name: Собираем production Docker | ||
runs-on: ubuntu-latest | ||
permissions: | ||
contents: read | ||
packages: write | ||
|
||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v4 | ||
|
||
- name: Log in to the Container registry | ||
uses: docker/login-action@v2 | ||
with: | ||
registry: ${{ env.REGISTRY }} | ||
username: ${{ github.actor }} | ||
password: ${{ secrets.GITHUB_TOKEN }} | ||
|
||
- name: Define production metadata | ||
id: meta-prod | ||
uses: docker/metadata-action@v4 | ||
with: | ||
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} | ||
tags: | | ||
type=ref,event=tag,enable=true | ||
type=raw,value=prod,enable=true | ||
type=raw,value=latest,enable=true | ||
- name: Build and push production Docker | ||
uses: docker/build-push-action@v4 | ||
with: | ||
file: ./deployment/Dockerfile | ||
context: . | ||
push: true | ||
build-args: | | ||
BUILD_MODE=production | ||
LAUNCH_MODE=production | ||
APP_VERSION=${{ github.ref_name }} | ||
tags: ${{ steps.meta-prod.outputs.tags }} | ||
labels: ${{ steps.meta-prod.outputs.labels }} | ||
|
||
deploy-production: | ||
name: Раскатываем production среду | ||
runs-on: [self-hosted, Linux] | ||
needs: [build-prod-image] | ||
environment: | ||
name: Production | ||
url: https://vu.profcomff.com/ | ||
env: | ||
CONTAINER_NAME: com_profcomff_app | ||
permissions: | ||
packages: read | ||
steps: | ||
- name: Run docker container | ||
run: | | ||
docker pull ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:prod | ||
docker stop ${{ env.CONTAINER_NAME }} || true && docker rm ${{ env.CONTAINER_NAME }} || true | ||
docker run \ | ||
--detach \ | ||
--restart always \ | ||
--network=web \ | ||
--name ${{ env.CONTAINER_NAME }} \ | ||
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:prod |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
FROM node:18 AS build | ||
|
||
WORKDIR /app | ||
ADD . /app | ||
RUN npm install && npm run build | ||
|
||
|
||
FROM nginx:1.21 | ||
|
||
ADD ./deployment/nginx.conf /etc/nginx/conf.d/default.conf | ||
ADD ./deployment/docker_entrypoint.sh /docker_entrypoint.sh | ||
COPY --from=build /app/app/dist /usr/share/nginx/html | ||
|
||
RUN chmod +x /docker_entrypoint.sh && /docker_entrypoint.sh |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#!/bin/bash | ||
|
||
export APPJS_NAME=$(cd /usr/share/nginx/html && ls js/app.*.js) | ||
if [ ! -z ${APPJS_NAME} ] | ||
then | ||
echo 'app.js is ${APPJS_NAME}' | ||
sed -i 's|APPJS_NAME|'${APPJS_NAME}'|g' /etc/nginx/conf.d/default.conf | ||
sed -i 's|# ||g' /etc/nginx/conf.d/default.conf | ||
else | ||
echo 'app.js is app.js, no changes' | ||
fi |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
log_format json_combined escape=json | ||
'{' | ||
'"timestamp":"$time_iso8601",' | ||
'"remote_addr":"$remote_addr",' | ||
'"remote_user":"$remote_user",' | ||
'"request":"$request",' | ||
'"status": "$status",' | ||
'"body_bytes_sent":"$body_bytes_sent",' | ||
'"request_time":"$request_time",' | ||
'"http_referrer":"$http_referer",' | ||
'"http_user_agent":"$http_user_agent"' | ||
'}'; | ||
|
||
server { | ||
access_log /dev/stdout json_combined; | ||
|
||
listen 80; | ||
listen [::]:80; | ||
server_name localhost; | ||
|
||
location / { | ||
root /usr/share/nginx/html; | ||
index index.html index.htm; | ||
try_files $uri /index.html; | ||
} | ||
|
||
error_page 500 502 503 504 /50x.html; | ||
location = /50x.html { | ||
root /usr/share/nginx/html; | ||
} | ||
} |