inital commit
Some checks failed
Publish Docker Image / docker (push) Failing after 20s

This commit is contained in:
Lee 2023-10-26 11:51:16 +01:00
parent ce2e3e5c09
commit 2b3cff5823
3 changed files with 171 additions and 0 deletions

View File

@ -0,0 +1,76 @@
name: Publish Docker Image
on:
push:
branches:
- "master"
jobs:
docker:
runs-on: ubuntu-22.04
steps:
- name: Get branch name
id: branch-name
uses: tj-actions/branch-names@v7
- name: Checkout
uses: actions/checkout@v4
- name: Restore Docker Cache
uses: actions/cache@v3
id: docker-cache
with:
path: /usr/bin/docker
key: ${{ runner.os }}-docker
- name: Install Docker (if not cached)
if: steps.docker-cache.outputs.cache-hit != 'true'
run: |
wget -q -O /tmp/docker.tgz https://download.docker.com/linux/static/stable/x86_64/docker-20.10.23.tgz \
&& tar --extract --file /tmp/docker.tgz --directory /usr/bin --strip-components 1 --no-same-owner docker/docker \
&& rm -rf /tmp/* &&
echo "Done"
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to Repo
uses: docker/login-action@v3
with:
username: ${{ secrets.REPO_USERNAME }}
password: ${{ secrets.REPO_TOKEN }}
- name: Restore Docker Build Cache
uses: actions/cache@v3
id: build-cache
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx
- name: Build and Push (Latest)
uses: docker/build-push-action@v5
if: steps.branch-name.outputs.current_branch == 'master'
with:
push: true
context: .
tags: fascinated/nginx-with-fancyindex:latest
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache
- name: Build and Push (Other Branches)
uses: docker/build-push-action@v5
if: steps.branch-name.outputs.current_branch != 'master'
with:
push: true
context: .
tags: fascinated/nginx-with-fancyindex:${{ steps.branch-name.outputs.current_branch }}
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache
- name: Save Docker Build Cache
if: steps.build-cache.outputs.cache-hit != 'true'
run: |
mkdir -p /tmp/.buildx-cache
cp -r /tmp/.buildx-cache/. /tmp/.buildx-cache-new
rm -rf /tmp/.buildx-cache
mv /tmp/.buildx-cache-new /tmp/.buildx-cache

42
Dockerfile Normal file
View File

@ -0,0 +1,42 @@
# Stage 1: Build Nginx from source
FROM alpine:latest AS build
# Install build tools and dependencies
RUN apk update && apk upgrade
RUN apk add build-base wget pcre-dev zlib-dev git
# Download Nginx source code
WORKDIR /tmp
RUN wget http://nginx.org/download/nginx-1.25.3.tar.gz
RUN tar -zxvf nginx-*.tar.gz
RUN git clone git clone https://github.com/aperezdc/ngx-fancyindex.git ngx-fancyindex
# Build Nginx from source
WORKDIR /tmp/nginx-*
RUN ./configure --prefix=/usr/local/nginx \
--sbin-path=/usr/local/sbin/nginx \
--conf-path=/etc/nginx/nginx.conf \
--error-log-path=/var/log/nginx/error.log \
--http-log-path=/var/log/nginx/access.log \
--with-http_ssl_module \
--add-module=../ngx-fancyindex
RUN make
RUN make install
# Stage 2: Create a minimal runtime image
FROM alpine:latest
# Copy Nginx binary and configuration from the build stage
COPY --from=build /usr/local/nginx /usr/local/nginx
COPY --from=build /etc/nginx /etc/nginx
# Copy custom Nginx configuration
COPY ./docker/nginx.conf /etc/nginx/nginx.conf
# Expose the default HTTP port
EXPOSE 80
# Start Nginx when the container runs
CMD ["/usr/local/sbin/nginx", "-g", "daemon off;"]

53
nginx.conf Normal file
View File

@ -0,0 +1,53 @@
events {
worker_connections 4096;
}
http {
# Log format
log_format main '[$time_local] "$request" $status $body_bytes_sent "$http_referer" "$http_user_agent"';
access_log /dev/stdout main; # Log access to stdout
error_log /dev/stdout; # Log errors to stdout
include mime.types; # Include the mime types file
default_type application/octet-stream; # Default type
sendfile on; # Send files directly from disk
keepalive_timeout 15; # Keep connections alive for 15 seconds
types_hash_max_size 4096; # Max number of mime types
# TCP optimizations
tcp_nopush on; # Send headers in one packet
tcp_nodelay on; # Don't wait for packets to be full
server {
server_name _; # Listen on all hostnames
listen 80; # Listen on port 80
root /var/www/html; # Serve files from /var/www/html
index index.html index.htm; # Serve index.html and index.htm by default
# Gzip
gzip on;
gzip_disable "msie6";
gzip_vary on;
gzip_proxied any;
gzip_comp_level 8;
gzip_buffers 16 64k;
gzip_types text/plain text/css application/json application/javascript application/x-javascript text/xml application/xml application/xml+rss text/javascript;
# Serve your files
location / {
expires 7d;
open_file_cache max=1000 inactive=60s;
open_file_cache_valid 60s;
open_file_cache_min_uses 1;
open_file_cache_errors on;
fancyindex on; # Enable fancy indexes.
fancyindex_exact_size off; # Output human-readable file sizes.
}
}
}