2
Help us understand the problem. What are the problem?

posted at

gasを管理するclaspのdocker環境を作成する

gasを管理するclaspが、nodeのversionを高く求めてくるようになってきたので、docker環境でclaspが使えるようにする。個人的にclasp cloneとか、pullができれば良いので、gitなどもホストで管理する考えです。
ため、ファイルのオーナーが、ホストのユーザと同じでないと管理がめんどくさいので、パスワードファイルを共用するようにしました
(参考)
https://qiita.com/yohm/items/047b2e68d008ebb0f001

Dockerfile
nodeは、node:slimイメージでも問題なさそう

FROM node:slim
RUN npm i @google/clasp -g

docker-compose.yml
homeフォルダは、事前に作成しておく(フォルダのオーナーをあわせるため、dockerが作成するとrootになる)
clasp(google)のログインのcrednetial情報が、ユーザのhome直下に作成するためhomeフォルダをマウントしておくことにした。

version: '3'
services:
  clasp:
    image: clasp:sample
    build: .
    tty: true
    volumes:
      - "./home/:${HOME}"
      - /etc/passwd:/etc/passwd:ro
      - /etc/group:/etc/group:ro
    working_dir: ${HOME}

事前状態。

[ec2-user@ip-192-168-100-10 mailform-gas]$ mkdir home
[ec2-user@ip-192-168-100-10 mailform-gas]$ ls -al
合計 12
drwxrwxr-x 4 ec2-user ec2-user  92  9月 30 07:45 .
drwxrwxr-x 3 ec2-user ec2-user  35  9月 29 12:58 ..
drwxrwxr-x 8 ec2-user ec2-user 185  9月 30 07:45 .git
-rw-rw-r-- 1 ec2-user ec2-user 624  9月 29 12:54 .gitignore
-rw-rw-r-- 1 ec2-user ec2-user  42  9月 29 13:33 Dockerfile
-rw-rw-r-- 1 ec2-user ec2-user 222  9月 30 07:42 docker-compose.yml
drwxrwxr-x 2 ec2-user ec2-user 148  9月 30 07:44 home

homeフォルダが、使用するユーザであることを確認する。

docker-compose run 開発するしかないので、使用後はrmする。-u $(id -u $usr)で、ホストと同じユーザでdockerにログインする。

[ec2-user@ip-192-168-100-10 mailform-gas]$ docker-compose run --rm -u $(id -u $usr) clasp /bin/bash
Creating mailform-gas_clasp_run ... done
ec2-user@6e80e0300571:~$
ec2-user@6e80e0300571:~$
ec2-user@6e80e0300571:~$ ls
ec2-user@6e80e0300571:~$ ls -atrl
total 8
-rw------- 1 ec2-user ec2-user 2280 Sep 29 22:39 .clasprc.json
-rw------- 1 ec2-user ec2-user  102 Sep 29 22:40 .bash_history
drwxrwxr-x 2 ec2-user ec2-user   48 Sep 29 22:40 .
drwxr-xr-x 1 root     root       22 Sep 29 22:42 ..

clasp loginは、--no-localhostオプションで、リダイレクトせずにすむようにする。
(参考)
https://qiita.com/ONO_Keyboard/items/5d9f9bac0e52e9c0cacf


ec2-user@6e80e0300571:~$ clasp login --no-localhost
Logging in globally…
🔑 Authorize clasp by visiting this url:
https://accounts.google.com/o/oauth2/v2/auth?access_type=offline&scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fscript.deployments%20https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fscript.projects%20https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fscript.webapp.deploy%20https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fdrive.metadata.readonly%20https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fdrive.file%20https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fservice.management%20https%3A%2F%2Fwww.googleapis.com%2Fauth%2Flogging.read%20https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fuserinfo.email%20https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fuserinfo.profile%20https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fcloud-platform&response_type=code&client_id=1072944905499-vm2v2i5dvn0a0d2o4ca36i1vge8cvbn0.apps.googleusercontent.com&redirect_uri=urn%3Aietf%3Awg%3Aoauth%3A2.0%3Aoob

Enter the code from that page here: 4/1AX4XfWhGESciC0x-SYqeR3JudXAiWpCkSiyj-Ezw1NYcQfpnS6R2RbOM-7g
Authorization successful.

Default credentials saved to: /home/ec2-user/.clasprc.json.
ec2-user@6e80e0300571:~$ clasp clone 1vGNV1qAZeVhD5PgOwktgnKQkGYSrMROeCpcdI3NIipLlkTyxCk7yKAYj
Warning: files in subfolder are not accounted for unless you set a '/home/ec2-user/.claspignore' file.
Cloned 4 files.
└─ /home/ec2-user/appsscript.json
└─ /home/ec2-user/awslibrary.js
└─ /home/ec2-user/chatwork.js
└─ /home/ec2-user/execute.js
Not ignored files:
└─ /home/ec2-user/appsscript.json
└─ /home/ec2-user/awslibrary.js
└─ /home/ec2-user/chatwork.js
└─ /home/ec2-user/execute.js

Ignored files:
└─ /home/ec2-user/.bash_history
└─ /home/ec2-user/.clasp.json
└─ /home/ec2-user/.clasprc.json


clasp clone に成功。
ホストの状態

ec2-user@6e80e0300571:~$ exit
[ec2-user@ip-192-168-100-10 mailform-gas]$ cd home
[ec2-user@ip-192-168-100-10 home]$ ls -al
合計 44
drwxrwxr-x 2 ec2-user ec2-user   148  9月 30 07:44 .
drwxrwxr-x 4 ec2-user ec2-user    92  9月 30 07:45 ..
-rw------- 1 ec2-user ec2-user   272  9月 30 07:44 .bash_history
-rw------- 1 ec2-user ec2-user   100  9月 30 07:44 .clasp.json
-rw------- 1 ec2-user ec2-user  2280  9月 30 07:44 .clasprc.json
-rw-r--r-- 1 ec2-user ec2-user   115  9月 30 07:44 appsscript.json
-rw-r--r-- 1 ec2-user ec2-user    29  9月 30 07:44 awslibrary.js
-rw-r--r-- 1 ec2-user ec2-user   400  9月 30 07:44 chatwork.js
-rw-r--r-- 1 ec2-user ec2-user 19869  9月 30 07:44 execute.js
[ec2-user@ip-192-168-100-10 home]$

gitもする。とくに問題なく

[ec2-user@ip-192-168-100-10 mailform-gas]$ git commit
[master 9cbc04d] initial commit
 Committer: EC2 Default User <ec2-user@ip-192-168-100-10.ap-northeast-1.compute.internal>
Your name and email address were configured automatically based
on your username and hostname. Please check that they are accurate.
You can suppress this message by setting them explicitly. Run the
following command and follow the instructions in your editor to edit
your configuration file:

    git config --global --edit

After doing this, you may fix the identity used for this commit with:

    git commit --amend --reset-author

 9 files changed, 343 insertions(+)
 create mode 100644 Dockerfile
 create mode 100644 docker-compose.yml
 create mode 100644 home/.bash_history
 create mode 100644 home/.clasp.json
 create mode 100644 home/.clasprc.json
 create mode 100644 home/appsscript.json
 create mode 100644 home/awslibrary.js
 create mode 100644 home/chatwork.js
 create mode 100644 home/execute.js
[ec2-user@ip-192-168-100-10 mailform-gas]$ git push
Enumerating objects: 13, done.
Counting objects: 100% (13/13), done.
Delta compression using up to 2 threads
Compressing objects: 100% (10/10), done.
Writing objects: 100% (12/12), 10.28 KiB | 3.42 MiB/s, done.
Total 12 (delta 0), reused 0 (delta 0)
To bitbucket.org:mailform-gas.git
   1689ce4..9cbc04d  master -> master

Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Sign upLogin
2
Help us understand the problem. What are the problem?