From d1379d233517eb9dc5c907763c22970f9de58a7f Mon Sep 17 00:00:00 2001 From: Bob Ong Date: Thu, 11 Jul 2024 14:57:50 +0800 Subject: [PATCH] [digitalocean deploy] commit deploy config including Dockerfile, nginx.conf, starcoin-explorer-deployment.yaml etc. --- .dockerignore | 27 ++++++++++++ .github/workflows/docker_build.yaml | 57 ++++++++++++++++++++++++++ Dockerfile | 24 +++++++++++ kube/starcoin-explorer-deployment.yaml | 31 ++++++++++++++ nginx.conf | 21 ++++++++++ 5 files changed, 160 insertions(+) create mode 100644 .dockerignore create mode 100644 .github/workflows/docker_build.yaml create mode 100644 Dockerfile create mode 100644 kube/starcoin-explorer-deployment.yaml create mode 100644 nginx.conf diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..d2bf1e6 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,27 @@ +# dependencies +/node_modules +/.pnp +.pnp.js + +# testing +/coverage + +# production +/build + +# misc +.DS_Store +.env.local +.env.development.local +.env.test.local +.env.production.local + +npm-debug.log* +yarn-debug.log* +yarn-error.log* + +.eslintcache +lintout.json + +# editors +.idea \ No newline at end of file diff --git a/.github/workflows/docker_build.yaml b/.github/workflows/docker_build.yaml new file mode 100644 index 0000000..b7525db --- /dev/null +++ b/.github/workflows/docker_build.yaml @@ -0,0 +1,57 @@ +name: Build and Deploy Docker Image + +on: + push: + branches: + - main + workflow_dispatch: + release: + types: [published] + +jobs: + build-and-deploy: + name: Build and Deploy Docker Image + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v2 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v1 + + - name: Login to DockerHub + uses: docker/login-action@v1 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + + - name: Build and push Docker image + uses: docker/build-push-action@v2 + with: + context: . + file: ./Dockerfile + push: true + tags: | + starcoin/starcoin_explorer:latest + starcoin/starcoin_explorer:${{ github.sha }} + build-args: | + REACT_APP_STARCOIN_API_URL=https://doapi.stcscan.io + REACT_APP_STARCOIN_NETWORKS=main,banard,proxima,halley,vega + + - name: Image digest + run: echo ${{ steps.docker_build.outputs.digest }} + + - name: Verify push to DockerHub + run: | + echo "Image pushed to DockerHub successfully!" + echo "Tags:" + echo " - starcoin/starcoin_explorer:latest" + echo " - starcoin/starcoin_explorer:${{ github.sha }}" + + - name: Deployment notification + if: success() + run: | + echo "Docker image has been successfully built and pushed to DockerHub." + echo "You can pull the latest image using:" + echo "docker pull starcoin/starcoin_explorer:latest" \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..f9fcb63 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,24 @@ +FROM node:16-alpine as build + +WORKDIR /app + +COPY package*.json yarn*.lock ./ + +# Set enviroments +ENV REACT_APP_STARCOIN_API_URL=https://doapi.stcscan.io +ENV REACT_APP_STARCOIN_NETWORKS=main,banard,proxima,halley,vega + +COPY . . + +# Build project +RUN yarn install && yarn build + +FROM nginx:alpine + +COPY --from=build /app/build /usr/share/nginx/html + +COPY nginx.conf /etc/nginx/conf.d/default.conf + +EXPOSE 80 + +CMD ["nginx", "-g", "daemon off;"] diff --git a/kube/starcoin-explorer-deployment.yaml b/kube/starcoin-explorer-deployment.yaml new file mode 100644 index 0000000..ef1ab0d --- /dev/null +++ b/kube/starcoin-explorer-deployment.yaml @@ -0,0 +1,31 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: starcoin-explorer-deployment + namespace: starcoin-client +spec: + replicas: 1 + selector: + matchLabels: + app: starcoin-client + template: + metadata: + labels: + app: starcoin-client + spec: + containers: + - name: react-app + image: starcoin_explorer:v1.9.10 + ports: + - containerPort: 80 +--- +apiVersion: v1 +kind: Service +metadata: + name: starcoin-explorer +spec: + type: LoadBalancer + ports: + - port: 80 + selector: + app: react-app \ No newline at end of file diff --git a/nginx.conf b/nginx.conf new file mode 100644 index 0000000..0975433 --- /dev/null +++ b/nginx.conf @@ -0,0 +1,21 @@ +server { + listen 80; + server_name localhost; + + root /usr/share/nginx/html; + index index.html; + + location /static/ { + try_files $uri $uri/ =404; + } + + location /locales/ { + try_files $uri $uri/ =404; + } + + location / { + try_files $uri /index.html; + } + + error_page 404 /index.html; +}