diff --git a/.github/workflows/ci-cd.yml b/.github/workflows/ci-cd.yml index 8b23c08c..89d40b7e 100644 --- a/.github/workflows/ci-cd.yml +++ b/.github/workflows/ci-cd.yml @@ -78,6 +78,13 @@ jobs: docker build -f Dockerfile.prod -t ${{ secrets.DOCKER_REPO }}/clubber-backend-prod . docker push ${{ secrets.DOCKER_REPO }}/clubber-backend-prod + - name: docker build and push to prod nginx + if: contains(github.ref, 'main') + run: | + docker login -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_PASSWORD }} + docker build -f Dockerfile.nginx.prod -t ${{ secrets.DOCKER_REPO }}/clubber-nginx-prod . + docker push ${{ secrets.DOCKER_REPO }}/clubber-nginx-prod + - name: Copy docker-compose.yml to EC2 DEV if: contains(github.ref, 'dev') uses: appleboy/scp-action@master @@ -126,5 +133,6 @@ jobs: sudo docker rm -f $(docker ps -qa) sudo docker pull ${{ secrets.DOCKER_REPO }}/clubber-backend-prod sudo docker pull ${{ secrets.DOCKER_REPO }}/clubber-front-prod + sudo docker pull ${{ secrets.DOCKER_REPO }}/clubber-nginx-prod sudo docker-compose -f docker-compose-prod.yml up -d sudo docker image prune -f \ No newline at end of file diff --git a/Dockerfile.nginx.prod b/Dockerfile.nginx.prod new file mode 100644 index 00000000..45b04075 --- /dev/null +++ b/Dockerfile.nginx.prod @@ -0,0 +1,43 @@ +# Use the official NGINX base image +FROM nginx:1.24.0 + +# Install dependencies +RUN apt-get update && \ + apt-get install -y --no-install-recommends \ + wget \ + curl \ + build-essential \ + libpcre3-dev \ + zlib1g-dev \ + libmaxminddb-dev \ + git \ + && rm -rf /var/lib/apt/lists/* + +# Download and extract NGINX source code +ARG NGINX_VERSION=1.24.0 +WORKDIR /usr/src +RUN wget http://nginx.org/download/nginx-${NGINX_VERSION}.tar.gz && \ + tar -zxvf nginx-${NGINX_VERSION}.tar.gz && \ + rm nginx-${NGINX_VERSION}.tar.gz + +# Clone ngx_http_geoip2_module +RUN git clone https://github.com/leev/ngx_http_geoip2_module.git + +# Build NGINX with geoip2 module +WORKDIR /usr/src/nginx-${NGINX_VERSION} +RUN ./configure \ + --with-compat \ + --add-dynamic-module=../ngx_http_geoip2_module && \ + make modules + +# Copy the built module to the NGINX modules directory +RUN mkdir -p /usr/lib/nginx/modules/ +RUN cp objs/ngx_http_geoip2_module.so /usr/lib/nginx/modules/ + +# Clean up +RUN apt-get purge -y --auto-remove \ + wget \ + curl \ + build-essential \ + git && \ + rm -rf /usr/src/* \ No newline at end of file diff --git a/docker-compose-prod.yml b/docker-compose-prod.yml index b2469243..f61a1b8c 100644 --- a/docker-compose-prod.yml +++ b/docker-compose-prod.yml @@ -24,13 +24,14 @@ services: nginx: container_name: nginx - image: nginx:latest + image: ssuclubber/clubber-nginx-prod environment: - TZ=Asia/Seoul volumes: - ./nginx/:/etc/nginx/ - ./data/certbot/conf:/etc/letsencrypt - ./data/certbot/www:/var/www/certbot + - /var/lib/GeoIP/GeoLite2-Country.mmdb:/var/lib/GeoIP/GeoLite2-Country.mmdb ports: - "80:80" - "443:443"