Skip to content

Commit 628f84a

Browse files
authored
Merge pull request #30 from attogram/feature/dev-container-setup
feat: Add Docker and Codespaces development environments
2 parents 9b1ab12 + d8f6fea commit 628f84a

46 files changed

Lines changed: 674 additions & 131 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.devcontainer/Dockerfile

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# .devcontainer/Dockerfile
2+
FROM mcr.microsoft.com/vscode/devcontainers/php:8.2
3+
4+
# Install system dependencies
5+
RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
6+
&& apt-get -y install --no-install-recommends \
7+
libpq-dev \
8+
libpng-dev \
9+
libjpeg-dev \
10+
libzip-dev
11+
12+
# Install PHP extensions
13+
RUN docker-php-ext-install \
14+
pdo_pgsql \
15+
bcmath \
16+
gd \
17+
zip
18+
19+
# Install Node.js
20+
RUN curl -fsSL https://deb.nodesource.com/setup_18.x | bash - \
21+
&& apt-get install -y nodejs
22+
23+
# [Optional] Set the default user. Omit if you want to keep the default as root.
24+
ARG USER_UID=1000
25+
ARG USER_GID=$USER_UID
26+
RUN if [ "$USER_UID" -ne "0" ]; then \
27+
groupadd --gid $USER_GID vscode \
28+
&& useradd --uid $USER_UID --gid $USER_GID -m vscode \
29+
&& apt-get install -y sudo \
30+
&& echo vscode ALL=\(ALL\) NOPASSWD:ALL > /etc/sudoers.d/vscode \
31+
&& chmod 0440 /etc/sudoers.d/vscode; \
32+
fi
33+
34+
# Add aliases to .bashrc
35+
RUN echo '' >> /home/vscode/.bashrc && \
36+
echo '# Custom aliases' >> /home/vscode/.bashrc && \
37+
echo 'alias pa="php artisan"' >> /home/vscode/.bashrc && \
38+
echo 'alias pest="./vendor/bin/pest"' >> /home/vscode/.bashrc && \
39+
echo 'alias pint="./vendor/bin/pint"' >> /home/vscode/.bashrc && \
40+
echo 'alias format="composer format"' >> /home/vscode/.bashrc && \
41+
echo 'alias test="composer test"' >> /home/vscode/.bashrc
42+
43+
# Switch to the non-root user
44+
USER vscode

.devcontainer/devcontainer.json

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,20 @@
11
{
2-
"image": "mcr.microsoft.com/devcontainers/base:ubuntu-20.04",
3-
"features": {
4-
"ghcr.io/devcontainers/features/php:1": {
5-
"version": "8.2",
6-
"installComposer": true
7-
}
8-
},
9-
"postCreateCommand": "sudo apt update && sudo apt install -y libssl1.1",
2+
"name": "OTE v2 Dev Container",
3+
"dockerComposeFile": "docker-compose.yml",
4+
"service": "app",
5+
"workspaceFolder": "/workspace",
6+
7+
"postCreateCommand": "composer install && cp .env.example .env && php artisan key:generate && php artisan migrate && php artisan db:seed",
8+
109
"customizations": {
1110
"vscode": {
1211
"extensions": [
13-
"bmewburn.vscode-intelephense-client"
12+
"bmewburn.vscode-intelephense-client",
13+
"dbaeumer.vscode-eslint",
14+
"esbenp.prettier-vscode"
1415
]
1516
}
16-
}
17+
},
18+
19+
"remoteUser": "vscode"
1720
}

.devcontainer/docker-compose.yml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# .devcontainer/docker-compose.yml
2+
version: '3'
3+
4+
services:
5+
app:
6+
build:
7+
context: .
8+
dockerfile: Dockerfile
9+
volumes:
10+
- ..:/workspace:cached
11+
ports:
12+
- 8000:8000
13+
depends_on:
14+
- db
15+
- redis
16+
environment:
17+
- DB_CONNECTION=pgsql
18+
- DB_HOST=db
19+
- DB_PORT=5432
20+
- DB_DATABASE=laravel
21+
- DB_USERNAME=laravel
22+
- DB_PASSWORD=secret
23+
- REDIS_HOST=redis
24+
25+
db:
26+
image: postgres:16-alpine
27+
environment:
28+
- POSTGRES_DB=laravel
29+
- POSTGRES_USER=laravel
30+
- POSTGRES_PASSWORD=secret
31+
volumes:
32+
- ote-db-data:/var/lib/postgresql/data
33+
34+
redis:
35+
image: redis:7-alpine
36+
37+
volumes:
38+
ote-db-data:

.dockerignore

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
.git
2+
.env
3+
.idea
4+
.vscode
5+
node_modules
6+
vendor
7+
storage/logs
8+
storage/framework/sessions
9+
storage/framework/cache
10+
storage/framework/views
11+
docker

Dockerfile

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

README.md

Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,3 +87,129 @@ Multilingual Online Resources for Minority Languages of a Campus Community
8787
## License
8888

8989
The Open Translation Engine is open-sourced software licensed under the [MIT license](https://opensource.org/licenses/MIT).
90+
91+
## Development Environment with Docker
92+
93+
This project includes a Docker-based development environment that allows you to run the application and its dependencies in isolated containers.
94+
95+
### Prerequisites
96+
97+
- [Docker](https://docs.docker.com/get-docker/)
98+
- [Docker Compose](https://docs.docker.com/compose/install/)
99+
100+
### Setup
101+
102+
1. **Build and start the containers:**
103+
104+
```bash
105+
docker compose -f compose.dev.yml up --build -d
106+
```
107+
108+
This command will build the Docker images and start the services in detached mode.
109+
110+
2. **Install Composer dependencies:**
111+
112+
Open a new terminal and run the following command to install the PHP dependencies using Composer.
113+
114+
```bash
115+
docker compose -f compose.dev.yml exec workspace composer install
116+
```
117+
118+
3. **Copy the environment file:**
119+
120+
```bash
121+
cp .env.example .env
122+
```
123+
124+
4. **Generate the application key:**
125+
126+
```bash
127+
docker compose -f compose.dev.yml exec workspace php artisan key:generate
128+
```
129+
130+
5. **Run database migrations:**
131+
132+
```bash
133+
docker compose -f compose.dev.yml exec workspace php artisan migrate
134+
```
135+
136+
6. **Seed the database (optional):**
137+
138+
To populate the database with sample data, run the following command:
139+
```bash
140+
docker compose -f compose.dev.yml exec workspace php artisan db:seed
141+
```
142+
143+
### Usage
144+
145+
- **Accessing the application:**
146+
147+
Once the containers are running, you can access the application in your web browser at [http://localhost](http://localhost).
148+
149+
- **Running Artisan commands:**
150+
151+
To run any `artisan` command, use `docker compose exec workspace php artisan <command>`. For example:
152+
153+
```bash
154+
docker compose -f compose.dev.yml exec workspace php artisan route:list
155+
```
156+
157+
- **Running Composer commands:**
158+
159+
To run any `composer` command, use `docker compose exec workspace composer <command>`. For example:
160+
161+
```bash
162+
docker compose -f compose.dev.yml exec workspace composer update
163+
```
164+
165+
- **Running NPM commands:**
166+
167+
To run any `npm` command, use `docker compose exec workspace npm <command>`. For example, to compile the frontend assets:
168+
169+
```bash
170+
docker compose -f compose.dev.yml exec workspace npm install
171+
docker compose -f compose.dev.yml exec workspace npm run dev
172+
```
173+
174+
- **Stopping the environment:**
175+
176+
To stop the containers, run:
177+
178+
```bash
179+
docker compose -f compose.dev.yml down
180+
```
181+
182+
## Development with GitHub Codespaces
183+
184+
This repository is configured to use [GitHub Codespaces](https://github.com/features/codespaces) for a cloud-based development environment.
185+
186+
### Getting Started
187+
188+
1. Click the "Code" button on the repository's main page.
189+
2. Select the "Codespaces" tab.
190+
3. Click "Create codespace on main".
191+
192+
GitHub will then create a new Codespace and set up the environment for you automatically. This includes:
193+
- Building the Docker containers for the application, database, and Redis.
194+
- Installing all Composer dependencies.
195+
- Creating the `.env` file.
196+
- Generating the application key.
197+
- Running database migrations and seeding it with sample data.
198+
199+
### Usage
200+
201+
- **Accessing the application:**
202+
Once the Codespace is ready, it will automatically forward the application's port (8000). You can access the application from the "Ports" tab in the VS Code editor or by clicking the notification that appears.
203+
204+
- **Running Artisan commands:**
205+
You can run `artisan` commands directly in the VS Code terminal:
206+
```bash
207+
php artisan route:list
208+
```
209+
210+
- **Running NPM commands:**
211+
You can also run `npm` commands in the terminal:
212+
```bash
213+
npm install
214+
npm run dev
215+
```

app/Console/Commands/AddAttribute.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22

33
namespace App\Console\Commands;
44

5-
use Illuminate\Console\Command;
65
use App\Models\LexicalEntry;
7-
use App\Models\Attribute;
6+
use Illuminate\Console\Command;
87

98
class AddAttribute extends Command
109
{
1110
protected $signature = 'ote:add-attribute {entry_id} {key} {value}';
11+
1212
protected $description = 'Adds an attribute to a lexical entry.';
1313

1414
public function handle()
@@ -19,8 +19,9 @@ public function handle()
1919

2020
$entry = LexicalEntry::find($entryId);
2121

22-
if (!$entry) {
22+
if (! $entry) {
2323
$this->error("Lexical entry with ID {$entryId} not found.");
24+
2425
return Command::FAILURE;
2526
}
2627

app/Console/Commands/AddEntry.php

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,15 @@
22

33
namespace App\Console\Commands;
44

5-
use Illuminate\Console\Command;
6-
use App\Models\Token;
75
use App\Models\Language;
86
use App\Models\LexicalEntry;
7+
use App\Models\Token;
8+
use Illuminate\Console\Command;
99

1010
class AddEntry extends Command
1111
{
1212
protected $signature = 'ote:add-entry {token} {language}';
13+
1314
protected $description = 'Creates a new lexical entry linking a token and a language.';
1415

1516
public function handle()
@@ -20,13 +21,15 @@ public function handle()
2021
$token = Token::where('text', $tokenText)->first();
2122
$language = Language::where('code', $langCode)->first();
2223

23-
if (!$token) {
24+
if (! $token) {
2425
$this->error("Token '{$tokenText}' not found. Please add it first.");
26+
2527
return Command::FAILURE;
2628
}
2729

28-
if (!$language) {
30+
if (! $language) {
2931
$this->error("Language '{$langCode}' not found. Please add it first.");
32+
3033
return Command::FAILURE;
3134
}
3235

app/Console/Commands/AddLanguage.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,13 @@
22

33
namespace App\Console\Commands;
44

5-
use Illuminate\Console\Command;
65
use App\Models\Language;
6+
use Illuminate\Console\Command;
77

88
class AddLanguage extends Command
99
{
1010
protected $signature = 'ote:add-language {code} {name}';
11+
1112
protected $description = 'Adds a new language to the lexicon.';
1213

1314
public function handle()
@@ -19,7 +20,7 @@ public function handle()
1920
$language = Language::create(['code' => $code, 'name' => $name]);
2021
$this->info("Language '{$name}' ({$code}) added successfully with ID {$language->id}.");
2122
} catch (\Exception $e) {
22-
$this->error("Failed to add language: A language with this code may already exist.");
23+
$this->error('Failed to add language: A language with this code may already exist.');
2324
}
2425
}
2526
}

0 commit comments

Comments
 (0)