diff --git a/.github/workflows/docker-publish.yml b/.github/workflows/docker-publish.yml new file mode 100644 index 00000000..6434958e --- /dev/null +++ b/.github/workflows/docker-publish.yml @@ -0,0 +1,44 @@ +name: Docker Build and Publish + +on: + release: + types: [published] + +env: + REGISTRY: ghcr.io + IMAGE_NAME: ${{ github.repository }} + +jobs: + build-and-push: + runs-on: ubuntu-latest + permissions: + contents: read + packages: write + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Log in to the Container registry + uses: docker/login-action@v3 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Extract metadata (tags, labels) for Docker + id: meta + uses: docker/metadata-action@v5 + with: + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + tags: | + type=semver,pattern={{version}} + type=raw,value=latest,enable={{is_default_branch}} + + - name: Build and push Docker image + uses: docker/build-push-action@v5 + with: + context: . + push: true + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000..86eab14e --- /dev/null +++ b/Dockerfile @@ -0,0 +1,29 @@ +# Build stage +FROM node:20-alpine as build + +WORKDIR /app +COPY package*.json ./ +RUN npm ci + +COPY . . +RUN npm run build + +# Production stage +FROM nginx:alpine + +# Copy built files +COPY --from=build /app/dist /usr/share/nginx/html/web + +# Configure nginx to handle SPA routing +RUN echo 'server { \ + listen 80; \ + location /web { \ + alias /usr/share/nginx/html/web; \ + try_files $uri $uri/ /web/index.html; \ + } \ + location / { \ + return 301 /web; \ + } \ +}' > /etc/nginx/conf.d/default.conf + +EXPOSE 80 diff --git a/README.md b/README.md index 05010e90..e1ecd4b0 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,29 @@ Welcome to the next generation of the TeddyCloud Administration Frontend! +## Docker Deployment + +You can run the application in a Docker container. The container is optimized for production use and uses nginx to serve the static files. + +### Building the Docker Image + +Build the Docker image: +```bash +docker build -t teddycloud-web:latest . +``` + +### Running the Container + +The container serves static files at the /web path. All application configuration (API URL, web base path, etc.) should be configured in your runtime environment where the application is accessed. + +Run the container exposing port 80: +```bash +docker run -d -p 80:80 teddycloud-web:latest +``` + +The application will be available at http://localhost/web + + If you are using this repository for the first time, please refer to the **General React Information** section first. ## TeddyCloud configuration