GitlabからCodeCommitへミラーリング

1. CodeCommitでレポジトリを作成します

2. ミラーリングに必要な権限のIAMポリシー作成

{
  "Version": "2012-10-17",
  "Statement" : [
    {
      "Effect" : "Allow",
      "Action" : [
        "codecommit:GitPull",
        "codecommit:GitPush"
      ],
      "Resource" : "arn:aws:codecommit:ap-northeast-1:xxxx:mirroring"
    }
  ]
}

作成したポリシーのarnは後ほど使用する
arn:aws:iam::xxxx:policy/CodeCommitPolicy

IAM Userを作成する
name: gitlab-mirroring-user
credential type: Access key – Programmatic access
CodeCommitPolicyをattach

HTTPS Git credentials for AWS CodeCommit を作成

### Gitlab
project作成
Mirroring repositories

5分くらい時間がかかってるが、ちゃんと反映されている!
なんか、codecommit, pipelineでデプロイした方が良さそう

[Docker] CentOSでPHPを動かしたい

Dockerfile

FROM centos:centos7
RUN yum update -y && yum clean all
RUN yum install -y epel-release
RUN yum -y install install http://rpms.famillecollet.com/enterprise/remi-release-7.rpm
RUN yum install -y httpd
RUN yum -y install --enablerepo=remi,remi-php74 php php-devel php-mbstring php-pdo php-xml php-gd php-fpm php-mysqlnd php-opcache php-pecl-zip libzip5
COPY . /var/www/html/
EXPOSE 80 443
CMD ["/usr/sbin/httpd", "-D", "FOREGROUND"]

sudo docker build -t mycentos .
sudo docker run -dit –name myapp -p 8080:80 mycentos

なるほど、少し見えてきた
apacheのドキュメントルート変更、環境変数の設定周りをやりたい

[Docker] CentOSを動かしたい

Dockerfile

FROM centos:centos7
RUN yum install -y httpd
COPY . /var/www/html/
EXPOSE 80
CMD ["/usr/sbin/httpd", "-D", "FOREGROUND"]

※EXPOSE 80で80番ポートを開ける

$ sudo docker build -t mycentos .
$ sudo docker run -dit –name myapp -p 8080:80 mycentos

apache, nginxに比べると、若干複雑になるね

[PostgreSQL] よく使うSQL

### 文字から数値、数値から文字へ変換
cast(A as B) で型変換を行う

select cast(‘0123’ as integer);
select cast(‘0123.45’ as numeric);
select cast(‘1234567.345’ as numeric(10,2));
select cast(‘1234567.345’ as numeric(10,3));
select cast(‘1234567.345’ as numeric(10,5));
select cast(‘-123456.789’ as numeric);
select cast(‘-123456.789’ as numeric(8,2));
select cast(‘abc’ as integer);

### 文字の切り取り
select * from left(‘abcedfghijk’, 3);
select * from left(‘abcedfghijk’, 5);
select * from right(‘abcedfghijk’, 3);
select * from right(‘abcedfghijk’, 5);
select * from substring(‘abcedfghijk’, 3,4);
select * from substring(‘abcedfghijk’, 5,3);
select * from substring(‘abcedfghijk’, 3,length(‘abcedfghijk’));
select * from substring(‘abcedfghijk’, 3,length(‘abcedfghijk’)-3);

### 前0埋め、後0埋め
– 前
select lpad(‘12345’, 8, ‘0’);
– 後
select rpad(‘12345’, 8, ‘0’);

### 数値を文字に変換
select * from to_char(12345.67, ‘FM999,999.999’);

### 日付、週、月
日付 + cast( ‘5 days’ as INTERVAL ) — 5日加える
日付 + cast( ‘5 weeks’ as INTERVAL ) — 5週加える
日付 + cast( ‘5 months’ as INTERVAL ) — 5か月加える

–年月日時分の書式
select to_char(now(),’YYYY/MM/DD HH24:MI:SS’); –2020/04/01 22:34:56

–年月日の書式
select to_char(now(),’YYYYMMDD’); –20200401
select to_char(now(),’YYYY/MM/DD’); –2020/04/01
select to_char(now(),’YYYY.MM.DD’); –2020.04.01
select to_char(now(),’YYYY年MM月DD日’); –2020年04月01日

–月日の書式
select to_char(now(),’MMDD’); –0401
select to_char(now(),’MM/DD’); –04/01
select to_char(now(),’MM.DD’); –04.01
select to_char(now(),’MM月DD日’); –04月01日

–時刻の書式
select to_char(now(), ‘HH:MI:SS’); –10:34:56(12時間表記)
select to_char(now(), ‘HH24:MI:SS’); –22:34:56(24時間表記)
select to_char(now(), ‘HH24時MI分SS秒’); –22時34分56秒

### 配列の要素数を取得
array_length(配列や配列の変数名, 1)

ニャルほどー
さて、Dockerやるかー

[PostgreSQL] ユーザ作成

create user user1;
create user user1 with password ‘pass’;
create user user1 with password ‘pass’ valid until ‘Jan 1 2022’;
create user user1 with password ‘pass’ superuser;
create user user1 with password ‘pass’ createdb createrole;

オプション
h: サーバホスト
p: ポート
U: user
d: データベース作成権限
D: データベース作成できない権限
l: ログイン権限
L: ログイン不可権限
r: ユーザー作成権限
R: ユーザー作成不可権限
s: スーパーユーザー権限
S: スーパーユーザー不可権限
P: パスワード設定

なるほど、少しPostgreSQLにも慣れてきた。というより、CRUDまでいくと、やった感はある。

[PostgreSQL] データ型

### character型
– character(整数)と書き、その桁数分、必ず文字で埋まる列
– 文字が定義した長さに満たない場合、半角スペースで埋まる
– 長さがオーバーしている場合はそこで自動的に切られる

create table ${table} (${列名} character(桁数));
alter table ${table} add column ${列名} character(10);
select cast(‘Hello’ as character(10));

### character varying(整数)、character varying
– character varying(整数)とvarchar(整数)は同じ
– スペース埋めがされない、登録した文字の長さになる
– 整数を省略したcharacter varingは1GBまで入る文字列

create table ${table} (${列名} character varing(桁数));
alter table ${table} add column ${列名} character varing(10);
select cast(‘Hello’ as character varing(10));

### text型
character varyingと同じもの

### integer
整数値を保存できる型
最小値は-2,147,483,648、最大値は2,147,483,647
select cast(2.4 as integer);
select cast(2.5 as integer);

### smallint, bigint
smallint, bigintはintegerと同じく整数値を保存できる型
smallintは、最小値は-32,768、最大値は32,767
bigintは、最小値は-9,223,372,036,854,775,808、最大値は9,223,372,036,854,775,807

### numeric, decimal
numericとdecimalは小数が可能な数値型。どちらも同じ意味

### boolean
true, false, nullの3つの値

なるほど、大分OKだわ

[PostgreSQL] CRUD

### データ挿入
insert into department (department_code, department_name) values (‘a’, ‘営業部’);
insert into department (department_code, department_name) values (‘b’, ‘総務部’);
insert into department values (‘c’, ‘製造部’);
insert into department (department_code, department_name) values (‘d’, ‘経理部’);
insert into department (department_code, department_name) values (‘e’, ‘人事部’);
insert into department (department_code, department_name) values (‘f’, ‘物流部’);

### データ取得
select * from department;
select department_code, department_name from department;
select department_code as “部署コード”, department_name as “部署名” from department;
select department_code, department_name from department where department_code = ‘b’;

### データ更新
update department set department_name = ‘hoge’ where department_code = ‘a’;

### データ削除
delete from department;
delete from department where department_code = ‘c’;
delete from department where department_code in(‘a’, ‘c’, ‘e’);