parc02 / parc02.github.io

https://parc02.github.io/
Other
0 stars 0 forks source link

github action 따라하기 #21

Open parc02 opened 9 months ago

parc02 commented 9 months ago

https://github.com/beyond-sw-camp/be01-101/issues/39#issue-2135881343

parc02 commented 9 months ago

step 1

echo "start pull-->" date "+%Y-%m-%d %H:%M:%S"

cd /home/parc02/code/parc02.github.io git pull

echo "<--end pull"

parc02 commented 9 months ago

step 2

$ vi blog-pull-cronjob
$ cp blog-pull-cronjob /etc/cron.d
$ crontab /etc/cron.d/blog-pull-cronjob
$ crontab -l

[FYI]

  1. cp blog-pull-cronjob /etc/cron.d: 이 명령은 blog-pull-cronjob 파일을 /etc/cron.d 디렉토리로 복사합니다.

  2. crontab /etc/cron.d/blog-pull-cronjob: 이 명령은 /etc/cron.d 디렉토리에 있는 blog-pull-cronjob 설정 파일을 사용하여 cron 작업을 설정합니다.

  3. crontab -l: 이 명령은 현재 사용자에 대한 cron 작업을 나열합니다. 이 명령을 실행하여 blog-pull-cronjob가 성공적으로 설치되었는지 확인할 수 있습니다. -CHAT GPT

$ sh pull.sh
start pull-->
2024-02-15 21:28:01
Already up to date.
<--end pull
start pull-->
2024-02-15 21:29:01
Already up to date.
<--end pull
start pull-->
2024-02-15 21:30:01
Already up to date.
<--end pull
start pull-->
2024-02-15 21:31:01
Already up to date.
<--end pull
start pull-->
2024-02-15 21:32:01
Already up to date.
<--end pull
parc02 commented 9 months ago

step 3 Dockerfile 만들기

parc02 commented 9 months ago
$vi Dockerfile
FROM ubuntu:22.04

RUN apt update
RUN apt install -y nginx
RUN apt install -y git
RUN apt install cron
RUN rm -rf /var/www/html

RUN git clone https://github.com/parc02/parc02.github.io.git /var/www/html

COPY pull.sh /var/www/html/
COPY blog-pull-cronjob /etc/cron.d

RUN crontab /etc/cron.d/blog-pull-cronjob
RUN crontab -l

CMD service cron start; nginx -g 'daemon off;'

blog-pull-cronjob 수정

* * * * * sh /var/www/html//pull.sh >> /var/log/pull.log 2>&1
# new crontab file is missing newline before EOF, can't install.

pull.sh 수정

#!/bin/bash

echo "start pull-->"
date "+%Y-%m-%d %H:%M:%S"

cd /var/www/html
git pull

echo "<--end pull"

BUILD DOCKERFILE

$sudo docker build -t cron-1 .
[+] Building 24.8s (15/15) FINISHED                                                                                                                        docker:default
 => [internal] load build definition from Dockerfile                                                                                                                 0.0s
 => => transferring dockerfile: 342B                                                                                                                                 0.0s
 => [internal] load metadata for docker.io/library/ubuntu:22.04                                                                                                      0.0s
 => [internal] load .dockerignore                                                                                                                                    0.0s
 => => transferring context: 1.33kB                                                                                                                                  0.0s
 => [internal] load build context                                                                                                                                    0.1s
 => => transferring context: 51.36kB                                                                                                                                 0.1s
 => [ 1/10] FROM docker.io/library/ubuntu:22.04                                                                                                                      0.0s
 => CACHED [ 2/10] RUN apt update                                                                                                                                    0.0s
 => CACHED [ 3/10] RUN apt install -y nginx                                                                                                                          0.0s
 => [ 4/10] RUN apt install -y git                                                                                                                                  15.9s
 => [ 5/10] RUN apt install cron                                                                                                                                     3.7s
 => [ 6/10] COPY . /var/www/html/                                                                                                                                    2.3s
 => [ 7/10] COPY pull.sh /var/www/html/                                                                                                                              0.2s
 => [ 8/10] COPY blog-pull-cronjob /etc/cron.d                                                                                                                       0.1s
 => [ 9/10] RUN crontab /etc/cron.d/blog-pull-cronjob                                                                                                                0.7s
 => [10/10] RUN crontab -l                                                                                                                                           0.6s
 => exporting to image                                                                                                                                               0.9s
 => => exporting layers                                                                                                                                              0.8s
 => => writing image sha256:0bac0db7f7f3a74060465012ba390e50f1e8df96018198d74355a803d81b918b                                                                         0.0s
 => => naming to docker.io/library/cron-1                                                                                                                            0.0s
$ sudo docker images
REPOSITORY     TAG       IMAGE ID       CREATED              SIZE
cron-1         latest    0bac0db7f7f3   About a minute ago   393MB
$ sudo docker run -it -p 8111:80 --name cron-1 73b3c17ccf88 bash
parc02 commented 9 months ago

BUG1-도커 내부에서

$ sh pull.sh
start pull-->
2024-02-15 14:12:18
The authenticity of host 'github.com (20.200.245.247)' can't be established.
ED25519 key fingerprint is SHA256:+DiY3wvvV6TuJJhbpZisF/zLDA0zPMSvHdkr4UvCOqU.
This key is not known by any other names
Are you sure you want to continue connecting (yes/no/[fingerprint])? ^C

=>풀 땡길때 인증이 안된거 같다

BUG1 해결방법

parc02 commented 9 months ago

BUG2- DOCKERFILE CMD ISUUE

확인방법

BUG2 해결방법

parc02 commented 9 months ago

그치만 안돼,,,,,, 현시각 02/16 00:48 너무 늦은 관계로 자고 아침에 다시 해보겠숩미다 ㅜ

parc02 commented 9 months ago

BUG2 해결완료