From 898737a7adf24c43ac6d92e3851399133beb9958 Mon Sep 17 00:00:00 2001 From: dm1sh Date: Sat, 17 Jul 2021 16:52:10 +0500 Subject: [PATCH] Added docker configuration and ci github workflows --- .dockerignore | 3 ++ .github/workflows/main-ci.yml | 47 +++++++++++++++++++++++++ .github/workflows/release-ci.yml | 60 ++++++++++++++++++++++++++++++++ Dockerfile | 16 +++++++++ package.json | 2 +- snowpack.config.js | 2 +- 6 files changed, 128 insertions(+), 2 deletions(-) create mode 100644 .dockerignore create mode 100644 .github/workflows/main-ci.yml create mode 100644 .github/workflows/release-ci.yml create mode 100644 Dockerfile diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..7d245c9 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,3 @@ +node_modules/ +package-lock.json +build/ \ No newline at end of file diff --git a/.github/workflows/main-ci.yml b/.github/workflows/main-ci.yml new file mode 100644 index 0000000..f9e549b --- /dev/null +++ b/.github/workflows/main-ci.yml @@ -0,0 +1,47 @@ +name: Publish Docker image on the Container registry + +on: push + +jobs: + docker: + runs-on: ubuntu-latest + permissions: + packages: write + contents: read + + steps: + - name: Checkout + uses: actions/checkout@v2 + + - name: Set up Docker Buildx + id: buildx + uses: docker/setup-buildx-action@v1 + + - name: Cache Docker layers + uses: actions/cache@v2 + with: + path: /tmp/.buildx-cache + key: ${{ runner.os }}-buildx-${{ github.sha }} + restore-keys: | + ${{ runner.os }}-buildx- + + - name: Login to the Container registry + if: github.event_name != 'pull_request' + uses: docker/login-action@v1 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Build and push + uses: docker/build-push-action@v2 + with: + context: . + file: ./Dockerfile + + builder: ${{ steps.buildx.outputs.name }} + cache-from: type=local,src=/tmp/.buildx-cache + cache-to: type=local,dest=/tmp/.buildx-cache + + push: ${{ github.event_name != 'pull_request' }} + tags: ghcr.io/${{ github.repository }}:${{ github.sha }},ghcr.io/${{ github.repository }}:latest diff --git a/.github/workflows/release-ci.yml b/.github/workflows/release-ci.yml new file mode 100644 index 0000000..bc51b09 --- /dev/null +++ b/.github/workflows/release-ci.yml @@ -0,0 +1,60 @@ +name: Publish Docker image on Dockerhub + +on: + release: + types: [published] + +jobs: + docker: + runs-on: ubuntu-latest + permissions: + packages: write + contents: read + + steps: + - name: Checkout + uses: actions/checkout@v2 + + - name: Docker meta + id: meta + uses: docker/metadata-action@v3 + with: + images: publite/frontend + tags: | + type=ref,event=branch + type=ref,event=pr + type=semver,pattern={{version}} + type=semver,pattern={{major}}.{{minor}} + + - name: Set up Docker Buildx + id: buildx + uses: docker/setup-buildx-action@v1 + + - name: Cache Docker layers + uses: actions/cache@v2 + with: + path: /tmp/.buildx-cache + key: ${{ runner.os }}-buildx-${{ github.sha }} + restore-keys: | + ${{ runner.os }}-buildx- + + - name: Login to DockerHub + uses: docker/login-action@v1 + with: + username: dm1sh + password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }} + + - name: Build and push + id: docker_build + uses: docker/build-push-action@v2 + with: + context: . + file: ./Dockerfile + + builder: ${{ steps.buildx.outputs.name }} + cache-from: type=local,src=/tmp/.buildx-cache + cache-to: type=local,dest=/tmp/.buildx-cache + + push: true + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..2dbb36d --- /dev/null +++ b/Dockerfile @@ -0,0 +1,16 @@ +FROM node:alpine AS builder + +WORKDIR /app +COPY ./package.json ./ +RUN npm install +COPY ./ ./ +ENV SNOWPACK_PUBLIC_API_URL=https://publitebackend.dmitriy.icu +ENV SNOWPACK_PUBLIC_BASE_URL=https://publite.dmitriy.icu +RUN NODE_ENV=production npm run build + +FROM node:alpine +RUN npm install serve -g --silent +WORKDIR /app +COPY --from=builder /app/build . +EXPOSE 5002 +CMD ["serve", "-p", "5000", "-s", "."] \ No newline at end of file diff --git a/package.json b/package.json index e0bfee8..cce0709 100644 --- a/package.json +++ b/package.json @@ -10,7 +10,7 @@ "@types/react": "^17.0.4", "@types/react-dom": "^17.0.3", "@types/snowpack-env": "^2.3.3", - "snowpack": "^3.3.5", + "snowpack": "^3.8.0", "snowpack-plugin-svgr": "^0.1.2", "typescript": "^4.2.4" }, diff --git a/snowpack.config.js b/snowpack.config.js index fdaf886..abe1a45 100644 --- a/snowpack.config.js +++ b/snowpack.config.js @@ -12,7 +12,7 @@ module.exports = { src: "/dist", }, optimize: { - bundle: true, + // bundle: true, }, routes: [ { match: "routes", src: "robots.txt", dest: "/robots.txt" },