目錄

Cloud Workstation With Hugo Env

GCP Cloud Worksation 提供的預配置的基本映像只包含一個最小的環境,包括 IDE、基本的 Linux 終端和語言工具和一個 sshd 伺服器。為了加快特定開發用例的環境設定,我們可以建立自定義容器映像,將這些基本映像擴充套件到預安裝工具和依賴項,並執行自動化指令碼。

Cloud Worksation 提供以下基本映像檔

ImageDescription
us-central1-docker.pkg.dev/cloud-workstations-images/predefined/code-oss:latestCloud Workstations base editor based on Code-OSS. (Default).
us-central1-docker.pkg.dev/cloud-workstations-images/predefined/base:latestBase image with no IDE installed.
us-central1-docker.pkg.dev/cloud-workstations-images/predefined/clion:latestCLion IDE. Accessible only through JetBrains Gateway
us-central1-docker.pkg.dev/cloud-workstations-images/predefined/goland:latestGoLand IDE. Accessible only through JetBrains Gateway.
us-central1-docker.pkg.dev/cloud-workstations-images/predefined/intellij-ultimate:latestIntelliJ IDEA Ultimate IDE. Accessible only through JetBrains Gateway.
us-central1-docker.pkg.dev/cloud-workstations-images/predefined/phpstorm:latestPhpStorm IDE. Accessible only through JetBrains Gateway.
us-central1-docker.pkg.dev/cloud-workstations-images/predefined/pycharm:latestPyCharm Professional IDE. Accessible only through JetBrains Gateway.
us-central1-docker.pkg.dev/cloud-workstations-images/predefined/rider:latestRider IDE. Accessible only through JetBrains Gateway.
us-central1-docker.pkg.dev/cloud-workstations-images/predefined/rubymine:latestRubyMine IDE. Accessible only through JetBrains Gateway.
us-central1-docker.pkg.dev/cloud-workstations-images/predefined/webstorm:latestWebStorm IDE. Accessible only through JetBrains Gateway.

Hugo env

透過 Worksation 搭建 Hugo 開發環境

 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
FROM us-central1-docker.pkg.dev/cloud-workstations-images/predefined/code-oss:latest

RUN sudo apt update
# VARIANT can be either 'hugo' for the standard version or 'hugo_extended' for the extended version.
ARG VARIANT=hugo
# VERSION can be either 'latest' or a specific version number
ARG VERSION=latest

# Download Hugo
RUN apt-get update && apt-get install -y ca-certificates openssl git curl && \
    rm -rf /var/lib/apt/lists/* && \
    case ${VERSION} in \
    latest) \
    export VERSION=$(curl -s https://api.github.com/repos/gohugoio/hugo/releases/latest | grep "tag_name" | awk '{print substr($2, 3, length($2)-4)}') ;;\
    esac && \
    echo ${VERSION} && \
    wget -O ${VERSION}.tar.gz https://github.com/gohugoio/hugo/releases/download/v${VERSION}/${VARIANT}_${VERSION}_Linux-64bit.tar.gz && \
    tar xf ${VERSION}.tar.gz && \
    mv hugo /usr/bin/hugo

# Download Extension
RUN wget https://open-vsx.org/api/bungcip/better-toml/0.3.2/file/bungcip.better-toml-0.3.2.vsix && \
unzip bungcip.better-toml-0.3.2.vsix "extension/*" &&\
mv extension /opt/code-oss/extensions/better-toml

RUN wget https://open-vsx.org/api/DavidAnson/vscode-markdownlint/0.48.1/file/DavidAnson.vscode-markdownlint-0.48.1.vsix && \
unzip DavidAnson.vscode-markdownlint-0.48.1.vsix "extension/*" &&\
mv extension /opt/code-oss/extensions/markdownlint

RUN wget https://open-vsx.org/api/wmaurer/change-case/1.0.0/file/wmaurer.change-case-1.0.0.vsix && \
unzip wmaurer.change-case-1.0.0.vsix "extension/*" &&\
mv extension /opt/code-oss/extensions/change-case

# Hugo dev server port
EXPOSE 1313

# [Optional] Uncomment this section to install additional OS packages you may want.
#
RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
    && apt-get -y install --no-install-recommends webp
1
$ docker build -t cage1016/hugo-evn .

Workstation

  1. 在 workstation configuration 設定中的配置客製化後的容器映像檔 docker.io/cage1016/hugo-env:latest configuration

  2. 在容器映像檔為公開時,可以不使用 Service Account

  3. 基於客製化的配置建立一台 workstation create workstation

  4. 啟動新建立的 workstation 並連線 start workstation

  5. 複製 Git 倉庫 https://github.com/526avijitgupta/gokarna.git clone repo

  6. 啟動 Hugo

    $ cd exampleSite/

    $ hugo server -D

    clone repo
  7. 透過 gcloud 指令執行 port-forward 來執行本地 Live preview gcloud port forward

  8. 訪問 http://localhost:1313

  9. 即可進行 Hugo 開發

    /posts/cloud-workstation-with-hugo-env/img/placeholder.gif