Commit 41d4d0b9 authored by insun park's avatar insun park
Browse files

docker/README.md 및 docker 하위 프로젝트 일괄 추가

parent c384e1fe
#!/usr/bin/perl -w
# Copyright (C) 1997-2018 Free Software Foundation, Inc.
# This file is part of the GNU C Library.
# Contributed by Andreas Jaeger <aj@arthur.rhein-neckar.de>, 1997.
# The GNU C Library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
# The GNU C Library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
# You should have received a copy of the GNU Lesser General Public
# License along with the GNU C Library; if not, see
# <http://www.gnu.org/licenses/>.
$PACKAGE = "libc";
$progname = $0;
if ($ENV{CC}) {
$CC = $ENV{CC};
} else {
$CC= "gcc";
}
if ($ENV{LD_SO}) {
$LD_SO = $ENV{LD_SO};
} else {
$LD_SO = "";
}
sub usage {
print "Usage: test-installation [soversions.mk]\n";
print " --help print this help, then exit\n";
print " --version print version number, then exit\n";
exit 0;
}
sub installation_problem {
print "The script has found some problems with your installation!\n";
print "Please read the FAQ and the README file and check the following:\n";
print "- Did you change the gcc specs file (necessary after upgrading from\n";
print " Linux libc5)?\n";
print "- Are there any symbolic links of the form libXXX.so to old libraries?\n";
print " Links like libm.so -> libm.so.5 (where libm.so.5 is an old library) are wrong,\n";
print " libm.so should point to the newly installed glibc file - and there should be\n";
print " only one such link (check e.g. /lib and /usr/lib)\n";
print "You should restart this script from your build directory after you've\n";
print "fixed all problems!\n";
print "Btw. the script doesn't work if you're installing GNU libc not as your\n";
print "primary library!\n";
exit 1;
}
arglist: while (@ARGV) {
if ($ARGV[0] eq "--v" || $ARGV[0] eq "--ve" || $ARGV[0] eq "--ver" ||
$ARGV[0] eq "--vers" || $ARGV[0] eq "--versi" ||
$ARGV[0] eq "--versio" || $ARGV[0] eq "--version") {
print "test-installation (GNU $PACKAGE)\n";
print "Copyright (C) 2018 Free Software Foundation, Inc.\n";
print "This is free software; see the source for copying conditions. There is NO\n";
print "warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n";
print "Written by Andreas Jaeger <aj\@arthur.rhein-neckar.de>\n";
exit 0;
} elsif ($ARGV[0] eq "--h" || $ARGV[0] eq "--he" || $ARGV[0] eq "--hel" ||
$ARGV[0] eq "--help") {
&usage;
} elsif ($ARGV[0] =~ /^-/) {
print "$progname: unrecognized option `$ARGV[0]'\n";
print "Try `$progname --help' for more information.\n";
exit 1;
} else {
last arglist;
}
}
# We expect none or one argument.
if ($#ARGV == -1) {
$dir = ".";
$soversions="soversions.mk";
$config="config.make";
} elsif ($#ARGV == 0) {
if (-d $ARGV[0]) {
$dir = $ARGV[0];
$soversions = "$ARGV[0]/soversions.mk";
$config = "$ARGV[0]/config.make";
} else {
$soversions = $dir = $ARGV[0];
$dir =~ s!/?[^/]*/*$!!;
$config = $dir . "/config.make";
}
} else {
die "Wrong number of arguments.";
}
if (system ("grep -q \"build-mathvec = yes\" $config") == 0) {
$build_mathvec = 1;
} else {
$build_mathvec = 0;
}
# Read names and versions of all shared libraries that are part of
# glibc
open SOVERSIONS, $soversions
or die ("Couldn't open $soversions in build directory!");
$link_libs = "";
%versions = ();
while (<SOVERSIONS>) {
next if (/^all-sonames/);
chop;
if (/^lib/) {
($name, $version)= /^lib(.*)\.so-version=\.(.*)$/;
# Filter out some libraries we don't want to link:
# - nss_ldap since it's not yet available
# - libdb1 since it conflicts with libdb
# - libthread_db since it contains unresolved references
# - it's just a test NSS module
# - We don't provide the libgcc so we don't test it
# - libmvec if it wasn't built
next if ($build_mathvec == 0 && $name eq "mvec");
if ($name ne "nss_ldap" && $name ne "db1"
&& $name ne "thread_db"
&& $name ne "nss_test1" && $name ne "nss_test2" && $name ne "libgcc_s") {
$link_libs .= " -l$name";
$versions{$name} = $version;
}
} elsif ($LD_SO ne "") {
($ld_so_name, $ld_so_version) = split ('\.so\.', $LD_SO);
} else {
if (/^ld\.so/) {
($ld_so_name, $ld_so_version)= /=(.*)\.so\.(.*)$/;
}
}
}
close SOVERSIONS;
# Create test program and link it against all
# shared libraries
open PRG, ">$dir/test-prg$$.c"
or die ("Couldn't write test file $dir/test-prg$$.c");
print PRG '
#include <stdio.h>
#include <stdlib.h>
int main(void) {
printf ("Your new glibc installation seems to be ok.\n");
exit (0);
}
';
close PRG;
open GCC, "$CC $dir/test-prg$$.c $link_libs -o $dir/test-prg$$ 2>&1 |"
or die ("Couldn't execute $CC!");
while (<GCC>) {
print $_ if (! /warning/);
}
close GCC;
if ($?) {
print "Execution of $CC failed!\n";
&installation_problem;
}
# Test if test program is linked against the right versions of
# shared libraries
$ok = 1;
%found = ();
open LDD, "ldd $dir/test-prg$$ |"
or die ("Couldn't execute ldd");
while (<LDD>) {
if (/^\s*lib/) {
($name, $version1, $version2) =
/^\s*lib(\w*)\.so\.([0-9\.]*)\s*=>.*\.so\.([0-9\.]*)/;
$found{$name} = 1;
if ($versions{$name} ne $version1 || $version1 ne $version2) {
print "Library lib$name is not correctly installed.\n";
print "Please check your installation!\n";
print "Offending line of ldd output: $_\n";
$ok = 0;
}
}
if (/$ld_so_name/) {
($version1) = /$ld_so_name\.so\.([0-9\.]*)/;
if ($version1 ne $ld_so_version) {
print "The dynamic linker $ld_so_name.so is not correctly installed.\n";
print "Please check your installation!\n";
print "Offending line of ldd output: $_\n";
$ok = 0;
}
}
}
close LDD;
die "ldd execution failed" if $?;
foreach (keys %versions) {
unless ($found{$_}) {
print "Library lib$_ is not correctly installed since the test program\n";
print "was not linked dynamically against it.\n";
print "Do you have a file/link lib$_.so?\n";
$ok = 0;
}
}
&installation_problem unless $ok;
# Finally execute the test program
system ("$dir/test-prg$$") == 0
or die ("Execution of test program failed");
# Clean up after ourselves
unlink ("$dir/test-prg$$", "$dir/test-prg$$.c");
# Dockerfile
FROM python:3.10-slim-buster
WORKDIR /app
COPY ../../geumdo_analysis ./
RUN pip install --no-cache-dir -r requirements.txt; \
apt-get update; \
apt-get install -y --no-install-recommends \
git \
curl \
vim \
; \
apt-get remove -y --auto-remove \
wget \
; \
rm -rf /var/lib/apt/lists/*;
CMD unicorn --host=0.0.0.0 --port 8000 main:app
# 크롤링/분석 FastAPI 서버
이 프로젝트는 프로젝트 루트(`../../`)에 위치한 `geumdo_analysis` 디렉토리의 Python 애플리케이션을 FastAPI 서버로 실행하기 위한 Docker 환경입니다.
**경고: 이 Docker 설정은 외부 디렉토리에 강하게 의존하고 있으며, 빌드와 실행 방식에 혼동의 여지가 있습니다. 아래 설명을 주의 깊게 읽어주세요.**
## 프로젝트 구조 및 의존성
- **소스 코드 위치**: 이 Docker 컨테이너는 `docker/docker_crowling` 폴더의 상위 폴더인 프로젝트 루트에 있는 `geumdo_analysis` 라는 디렉토리의 소스 코드를 실행하도록 설계되었습니다.
- **애플리케이션 타입**: `unicorn`을 사용하는 것으로 보아, `geumdo_analysis`는 FastAPI 또는 Starlette 기반의 ASGI 웹 애플리케이션일 가능성이 높습니다.
- **Dockerfile 동작**: 빌드 시 `geumdo_analysis` 폴더의 내용을 이미지 안으로 복사(`COPY`)합니다.
- **docker-compose 동작**: 컨테이너 실행 시, `fastapi_app` 이라는 외부 Docker 볼륨을 컨테이너의 `/app` 디렉토리에 마운트합니다. **이 과정에서 Dockerfile에 의해 복사된 소스 코드는 볼륨에 의해 덮어씌워져 무시됩니다.**
결론적으로, 이 컨테이너가 정상적으로 동작하려면 **`fastapi_app` 볼륨 내부에 `geumdo_analysis`의 소스 코드가 사전에 존재해야 합니다.**
## 사전 요구사항
- [Docker](https://www.docker.com/get-started)
- [Docker Compose](https://docs.docker.com/compose/install/)
- 프로젝트 루트에 `geumdo_analysis` 소스 코드 폴더가 존재해야 합니다.
- `geumdo_analysis` 폴더 내에 `requirements.txt``main.py` 파일(`app` 객체 포함)이 있어야 합니다.
## 사용 방법
### 1. (최초 설정) 소스 코드를 볼륨에 복사
`rebuild.sh`는 빈 볼륨만 생성해주므로, 사용자가 직접 소스 코드를 볼륨으로 옮겨야 합니다.
```bash
# 1. 빌드 스크립트를 실행하여 빈 볼륨과 이미지를 생성하고, 임시 컨테이너를 실행
./rebuild.sh
# 2. 프로젝트 루트의 geumdo_analysis 폴더 전체를 fastapi_server 컨테이너의 /app 디렉토리로 복사
# (컨테이너의 /app 디렉토리는 fastapi_app 볼륨과 연결되어 있음)
docker cp ../../geumdo_analysis/. fastapi_server:/app/
# 3. 임시 컨테이너 재시작하여 코드 변경사항 반영
docker-compose restart
```
### 2. (이후) 서비스 시작
이미 볼륨에 소스 코드가 준비된 상태라면, 아래 명령어로 서비스를 시작할 수 있습니다.
```bash
docker-compose up -d
```
## 서비스 접속 정보
- **서비스 포트**: 호스트의 `8100`번 포트가 컨테이너의 `8000`번 포트로 매핑됩니다.
- **API 주소**: `http://<서버_IP>:8100`
\ No newline at end of file
version: '3'
services:
fastapi_server:
build:
context: .
dockerfile: .
ports:
- "8100:8000"
network_mode: bridge
volumes:
- fastapi_app:/app
volumes:
fastapi_app:
external: true
#!/bin/sh
create_volume() {
docker volume inspect $1 > /dev/null 2>&1
if [ $? -eq 0 ]; then
echo "Volume '$1' already exists."
else
docker volume create --name=$1
echo "Volume '$1' created."
fi
}
create_volume fastapi_app
docker build -t fastapi .
docker-compose up -d
# images
FROM ubuntu:20.04
# package procedure(update&upgrade&install)
RUN apt-get update && \
apt-get -y upgrade && \
apt-get install -y openssh-server && \
apt-get install -y vim net-tools && \
apt-get install -y apt-utils && \
apt-get install -y iputils-ping && \
apt-get install -y wget && \
apt-get install -y tar && \
apt-get install -y curl && \
apt-get install -y language-pack-ko && \
apt-get install -y mariadb-server mariadb-client && \
apt-get install -y telnet
#package clean unused
RUN apt-get clean && \
rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
# Set up configuration for SSH
RUN mkdir /var/run/sshd
RUN echo 'root:!@#gds$%^' | chpasswd
RUN sed -ri 's/^#?PermitRootLogin\s+.*/PermitRootLogin yes/' /etc/ssh/sshd_config
RUN echo " StrictHostKeyChecking no" >> /etc/ssh/ssh_config
# SSH login fix. Otherwise, user is kicked off after login
RUN sed 's@session\s*required\s*pam_loginuid.so@session optional pam_loginuid.so@g' -i /etc/pam.d/sshd
ENV NOTVISIBLE "in users profile"
RUN echo "export VISIBLE=now" >> /etc/profile
# mariadb install and setting
RUN sed -ri 's/^#?bind-address\s+.*/bind-address = 0.0.0.0/' /etc/mysql/mariadb.conf.d/50-server.cnf
RUN sed -ri 's/^#?max_allowed_packet\s+.*/max_allowed_packet = 16M/' /etc/mysql/mariadb.conf.d/50-server.cnf
RUN echo lower_case_table_names=1 >> /etc/mysql/mariadb.conf.d/50-server.cnf
RUN echo default-time-zone='+9:00' >> /etc/mysql/mariadb.conf.d/50-server.cnf
RUN echo skip-character-set-client-handshake >> /etc/mysql/mariadb.conf.d/50-server.cnf
COPY make_root_remote_host.sh .
RUN chmod +x ./make_root_remote_host.sh
COPY setting.sql .
# Expose port
EXPOSE 22 3306 9011 9013
# Run ssh,db
ENTRYPOINT ["/bin/bash", "-c", "\
source /etc/profile && \
service mysql start && \
service ssh start && \
sh ./make_root_remote_host.sh && \
tail -f /dev/null"]
This diff is collapsed.
This diff is collapsed.
#!/bin/sh
mysql -u root -p!@#gds$%^ < setting.sql;
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
docker_fastapi @ 560d72c9
This diff is collapsed.
docker_fastapi_new @ a5d7d902
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment