Added docker configuration and ci github workflows

This commit is contained in:
Dmitriy Shishkov 2021-07-17 16:52:10 +05:00
parent 6b2f4420fb
commit 898737a7ad
No known key found for this signature in database
GPG Key ID: 14358F96FCDD8060
6 changed files with 128 additions and 2 deletions

3
.dockerignore Normal file
View File

@ -0,0 +1,3 @@
node_modules/
package-lock.json
build/

47
.github/workflows/main-ci.yml vendored Normal file
View File

@ -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

60
.github/workflows/release-ci.yml vendored Normal file
View File

@ -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 }}

16
Dockerfile Normal file
View File

@ -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", "."]

View File

@ -10,7 +10,7 @@
"@types/react": "^17.0.4", "@types/react": "^17.0.4",
"@types/react-dom": "^17.0.3", "@types/react-dom": "^17.0.3",
"@types/snowpack-env": "^2.3.3", "@types/snowpack-env": "^2.3.3",
"snowpack": "^3.3.5", "snowpack": "^3.8.0",
"snowpack-plugin-svgr": "^0.1.2", "snowpack-plugin-svgr": "^0.1.2",
"typescript": "^4.2.4" "typescript": "^4.2.4"
}, },

View File

@ -12,7 +12,7 @@ module.exports = {
src: "/dist", src: "/dist",
}, },
optimize: { optimize: {
bundle: true, // bundle: true,
}, },
routes: [ routes: [
{ match: "routes", src: "robots.txt", dest: "/robots.txt" }, { match: "routes", src: "robots.txt", dest: "/robots.txt" },