Skip to content

Commit c94f5ea

Browse files
authored
Merge pull request #3 from javascriptcm/feat/continuous-deployment-dev
🚀 Mise à jour de la configuration Docker et du déploiement
2 parents 22c56dc + d05af60 commit c94f5ea

13 files changed

Lines changed: 268 additions & 28 deletions

File tree

.dockerignore

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
build
2+
node_modules
3+
.env
4+
.git
5+
.gitignore
6+
.dockerignore
7+
.github
8+
.vscode

.env.example

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,12 @@ DB_PORT=3306
1010
DB_USER=root
1111
DB_PASSWORD=root
1212
DB_DATABASE=app
13-
GITHUB_CLIENT_ID=
14-
GITHUB_CLIENT_SECRET=
15-
GITHUB_CALLBACK_URL=
13+
GITHUB_CLIENT_ID=e
14+
GITHUB_CLIENT_SECRET=e
15+
GITHUB_CALLBACK_URL=e
16+
DB_CONNECTION=mysqle
17+
MYSQL_HOST=localhost
18+
MYSQL_PORT=3306
19+
MYSQL_USER=root
20+
MYSQL_PASSWORD=
21+
MYSQL_DB_NAME=javascript_cm

.github/workflows/deploy.dev.yml

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
name: Déploiement sur VPS (dev)
2+
3+
4+
5+
on:
6+
push:
7+
branches: [main, develop]
8+
pull_request:
9+
branches: [main, develop]
10+
workflow_dispatch:
11+
12+
env:
13+
APP_NAME: ${{ github.event.repository.name }}.dev
14+
APP_PATH: /home/apps/${{ github.event.repository.name }}.dev
15+
DATABASE_NAME: javascript_cm
16+
17+
jobs:
18+
deploy:
19+
runs-on: ubuntu-latest
20+
environment: dev
21+
steps:
22+
- name: Vérifier le code
23+
uses: actions/checkout@v4
24+
25+
- name: Créer le dossier de l'application sur le VPS
26+
uses: appleboy/ssh-action@v1.0.3
27+
with:
28+
host: ${{ secrets.VPS_HOST }}
29+
username: ${{ secrets.VPS_USERNAME }}
30+
key: ${{ secrets.VPS_SSH_KEY }}
31+
port: ${{ secrets.VPS_PORT }}
32+
script: |
33+
mkdir -p ${{ env.APP_PATH }}
34+
cd ${{ env.APP_PATH }}
35+
if [ -d "app" ]; then
36+
rm -rf app
37+
fi
38+
mkdir -p app
39+
40+
- name: Ecrire le fichier .env
41+
uses: appleboy/ssh-action@v1.0.3
42+
with:
43+
host: ${{ secrets.VPS_HOST }}
44+
username: ${{ secrets.VPS_USERNAME }}
45+
key: ${{ secrets.VPS_SSH_KEY }}
46+
port: ${{ secrets.VPS_PORT }}
47+
script: |
48+
cd ${{ env.APP_PATH }}/app
49+
echo "NODE_ENV=production" > .env
50+
echo "APP_NAME=${{ env.APP_NAME }}" >> .env
51+
echo "APP_PATH=${{ env.APP_PATH }}" >> .env
52+
echo "TZ=UTC" >> .env
53+
echo "PORT=3333" >> .env
54+
echo "HOST=0.0.0.0" >> .env
55+
echo "LOG_LEVEL=INFO" >> .env
56+
echo "APP_KEY=onsklvmesdlvmnrsdmvlrks" >> .env
57+
echo "SESSION_DRIVER=cookie" >> .env
58+
echo "DB_CONNECTION=mysql" >> .env
59+
echo "DB_HOST=mysql" >> .env
60+
echo "DB_PORT=3307" >> .env
61+
echo "DB_USER=root" >> .env
62+
echo "DB_PASSWORD=root" >> .env
63+
echo "DB_DATABASE=${{ env.DATABASE_NAME }}" >> .env
64+
echo "MYSQL_HOST=mysql" >> .env
65+
echo "MYSQL_PORT=3307" >> .env
66+
echo "MYSQL_USER=root" >> .env
67+
echo "MYSQL_PASSWORD=root" >> .env
68+
echo "MYSQL_DB_NAME=${{ env.DATABASE_NAME }}" >> .env
69+
echo "MYSQL_DATABASE=${{ env.DATABASE_NAME }}" >> .env
70+
echo "GITHUB_CLIENT_ID=github_client_id" >> .env
71+
echo "GITHUB_CLIENT_SECRET=github_client_secret" >> .env
72+
echo "GITHUB_CALLBACK_URL=http://0.0.0.0:3333/auth/github/callback" >> .env
73+
74+
- name: Copier les fichiers de l'application
75+
uses: appleboy/scp-action@v0.1.7
76+
with:
77+
host: ${{ secrets.VPS_HOST }}
78+
username: ${{ secrets.VPS_USERNAME }}
79+
key: ${{ secrets.VPS_SSH_KEY }}
80+
port: ${{ secrets.VPS_PORT }}
81+
source: "."
82+
target: "${{ env.APP_PATH }}/app"
83+
strip_components: 0
84+
85+
- name: Mettre à jour le docker-compose avec le nom de l'application
86+
uses: appleboy/ssh-action@v1.0.3
87+
with:
88+
host: ${{ secrets.VPS_HOST }}
89+
username: ${{ secrets.VPS_USERNAME }}
90+
key: ${{ secrets.VPS_SSH_KEY }}
91+
port: ${{ secrets.VPS_PORT }}
92+
script: |
93+
cd "${{ env.APP_PATH }}/app"
94+
sed -i "1s/^/name: ${{ env.APP_NAME }}\n/" compose.yaml
95+
96+
- name: Construire et démarrer les conteneurs Docker
97+
uses: appleboy/ssh-action@v1.0.3
98+
with:
99+
host: ${{ secrets.VPS_HOST }}
100+
username: ${{ secrets.VPS_USERNAME }}
101+
key: ${{ secrets.VPS_SSH_KEY }}
102+
port: ${{ secrets.VPS_PORT }}
103+
script: |
104+
cd "${{ env.APP_PATH }}/app"
105+
docker compose -f compose.yaml down || true
106+
docker compose -f compose.yaml build --no-cache
107+
docker compose -f compose.yaml up -d
108+
109+
docker system prune -f

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,4 @@ yarn-error.log
2323

2424
# Platform specific
2525
.DS_Store
26+
memory-bank/

adonisrc.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,14 @@ export default defineConfig({
9090
pattern: 'resources/views/**/*.edge',
9191
reloadServer: false,
9292
},
93+
{
94+
pattern: 'resources/images/**/*',
95+
reloadServer: false,
96+
},
97+
{
98+
pattern: 'resources/**/*.{png,jpg,jpeg,gif,svg,ico}',
99+
reloadServer: false,
100+
},
93101
{
94102
pattern: 'public/**',
95103
reloadServer: false,

compose.yaml

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
services:
2+
app:
3+
build:
4+
context: .
5+
dockerfile: docker/node/Dockerfile
6+
container_name: jscm-app
7+
env_file:
8+
- .env
9+
ports:
10+
- "${PORT}:3333"
11+
environment:
12+
- NODE_ENV=production
13+
- DB_HOST=mysql
14+
- DB_PORT=3306
15+
- DB_DATABASE=${DB_DATABASE}
16+
- DB_USERNAME=${DB_USERNAME}
17+
- DB_PASSWORD=${DB_PASSWORD}
18+
- PORT=${PORT}
19+
- HOST=${HOST}
20+
- LOG_LEVEL=${LOG_LEVEL}
21+
- APP_KEY=${APP_KEY}
22+
- SESSION_DRIVER=${SESSION_DRIVER}
23+
- DB_CONNECTION=${DB_CONNECTION}
24+
- GITHUB_CLIENT_ID=${GITHUB_CLIENT_ID}
25+
- GITHUB_CLIENT_SECRET=${GITHUB_CLIENT_SECRET}
26+
- GITHUB_CALLBACK_URL=${GITHUB_CALLBACK_URL}
27+
- TZ=${TZ}
28+
depends_on:
29+
- mysql
30+
31+
mysql:
32+
build:
33+
context: .
34+
dockerfile: docker/mysql/Dockerfile
35+
container_name: jscm-mysql
36+
env_file:
37+
- .env
38+
ports:
39+
- "${MYSQL_PORT}:3306"
40+
environment:
41+
- MYSQL_ROOT_PASSWORD=${DB_PASSWORD}
42+
- MYSQL_DATABASE=${DB_DATABASE}
43+
- MYSQL_USER=${DB_USERNAME}
44+
- MYSQL_PASSWORD=${DB_PASSWORD}
45+
volumes:
46+
- mysql_data:/var/lib/mysql
47+
48+
migrations:
49+
build:
50+
context: .
51+
dockerfile: docker/node/Dockerfile
52+
target: deps
53+
container_name: jscm-migrations
54+
env_file:
55+
- .env
56+
volumes:
57+
- .:/app
58+
- /app/node_modules
59+
environment:
60+
- NODE_ENV=development
61+
- DB_HOST=mysql
62+
- DB_PORT=3306
63+
- DB_DATABASE=${DB_DATABASE}
64+
- DB_USERNAME=${DB_USERNAME}
65+
- DB_PASSWORD=${DB_PASSWORD}
66+
depends_on:
67+
- mysql
68+
command: sh -c "node ace migration:run"
69+
70+
volumes:
71+
mysql_data:

config/logger.ts

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import env from '#start/env'
2-
import app from '@adonisjs/core/services/app'
3-
import { defineConfig, targets } from '@adonisjs/core/logger'
2+
import { defineConfig } from '@adonisjs/core/logger'
43

54
const loggerConfig = defineConfig({
65
default: 'app',
@@ -14,12 +13,6 @@ const loggerConfig = defineConfig({
1413
enabled: true,
1514
name: env.get('APP_NAME'),
1615
level: env.get('LOG_LEVEL'),
17-
transport: {
18-
targets: targets()
19-
.pushIf(!app.inProduction, targets.pretty())
20-
.pushIf(app.inProduction, targets.file({ destination: 1 }))
21-
.toArray(),
22-
},
2316
},
2417
},
2518
})

database/init.sql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
CREATE TABLE IF NOT EXISTS DATABASE javascript_cm;

database/migrations/17368394109899_create_articles_table.ts renamed to database/migrations/1736839410989_create_articles_table.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ export default class extends BaseSchema {
1111
table.text('excerpt').notNullable()
1212
table.text('content').notNullable()
1313
table.integer('user_id').unsigned().references('id').inTable('users').onDelete('CASCADE')
14+
table.integer('author_id').unsigned().references('id').inTable('users').onDelete('CASCADE')
1415
table.boolean('is_published').defaultTo(false)
1516
table.timestamp('published_at').nullable()
1617
table.timestamps(true, true)

database/migrations/1736839410999_add_author_id_to_articles.ts

Lines changed: 0 additions & 17 deletions
This file was deleted.

0 commit comments

Comments
 (0)