Gitpod & Docker WorkFlow Part 2

tags: yii gitpod

前情提要

接續part 1提到的gitpod環境所遇到的問題,底下就列出幾個關鍵調整的地方

Gitpod WorkFlow

  • 開啟gitpod.io網址開啟空白專案
    • 使用git clone將專案複製到這個環境
    • 使用volumes
      • 將當前的user與group的設定複製到container環境
      • 設定專案所需環境變數
    • 調整dockerFile
      • 將環境變數相關的檔案複製到container中

Gitpod的Base Image和Full Workspace兩者之間的關係

  • gitpod image的dependency會長得像這樣

Reference

Code

  • frontend/apache2/000-default.conf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
<Directory /app/frontend/web/>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>

<VirtualHost *:80>
# The ServerName directive sets the request scheme, hostname and port that
# the server uses to identify itself. This is used when creating
# redirection URLs. In the context of virtual hosts, the ServerName
# specifies what hostname must appear in the request's Host: header to
# match this virtual host. For the default virtual host (this file) this
# value is not decisive as it is used as a last resort host regardless.
# However, you must set it for any further virtual host explicitly.
#ServerName www.example.com

ServerAdmin webmaster@localhost
DocumentRoot /app/frontend/web

# Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
# error, crit, alert, emerg.
# It is also possible to configure the loglevel for particular
# modules, e.g.
#LogLevel info ssl:warn

ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined

# For most configuration files from conf-available/, which are
# enabled or disabled at a global level, it is possible to
# include a line for only one particular virtual host. For example the
# following line enables the CGI configuration for this host only
# after it has been globally disabled with "a2disconf".
#Include conf-available/serve-cgi-bin.conf
<Directory "/app/frontend/web/">
# use mod_rewrite for pretty URL support
RewriteEngine on
# If a directory or a file exists, use the request directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# Otherwise forward the request to index.php
RewriteRule . index.php

# use index.php as index file
DirectoryIndex index.php

# ...other settings...
# Apache 2.4
Require all granted

## Apache 2.2
# Order allow,deny
# Allow from all
</Directory>
</VirtualHost>
  • dockerFile
1
2
3
4
FROM yiisoftware/yii2-php:7.2-apache

# Change document root for Apache
COPY /apache2/000-default.conf /etc/apache2/sites-available/000-default.conf
  • docker-compose.yml

這兩行為關鍵:

  • /etc/passwd:/etc/passwd:ro
  • /etc/group:/etc/group:ro
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
version: '3.2'

services:
frontend:
build: frontend
ports:
- 20080:80
volumes:
# Re-use local composer cache via host-volume
- ~/.composer-docker/cache:/root/.composer/cache:delegated
# Mount source-code for development
- ./:/app
- /etc/passwd:/etc/passwd:ro
- /etc/group:/etc/group:ro
depends_on:
- mysql