From f8a335f276c8e5a040ded2d88c8814c6fe0686d3 Mon Sep 17 00:00:00 2001 From: Ilya Che Date: Wed, 29 Jun 2022 20:12:15 +0400 Subject: [PATCH] Soroka 90 (#18) * fix: update all dependencies * feat: add Dockerfile * feat: build docker image on PR open/update * feat: deploy stage on PR close * feat: deploy prod on release * fix: prod container build wrong path * fix: build wit env and catch non-root path --- .github/workflows/deploy-release.yml | 3 ++- .github/workflows/deploy-staging.yml | 1 - .github/workflows/docker-image.yml | 3 +++ Dockerfile | 7 +++++++ default.conf | 16 ++++++++++++++++ 5 files changed, 28 insertions(+), 2 deletions(-) create mode 100644 default.conf diff --git a/.github/workflows/deploy-release.yml b/.github/workflows/deploy-release.yml index 56db4d6..fd86011 100644 --- a/.github/workflows/deploy-release.yml +++ b/.github/workflows/deploy-release.yml @@ -52,6 +52,8 @@ jobs: uses: docker/build-push-action@v3 with: context: . + build-args: + REACT_APP_API_URL: ${{ env.REACT_APP_API_URL }} target: prod push: true tags: ${{ steps.meta.outputs.tags }} @@ -68,7 +70,6 @@ jobs: docker pull ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} docker rm -f ${{ env.NAME }} docker run -dp 8086:${{ env.SERVER_PORT }} --name ${{ env.NAME }} \ - -e REACT_APP_API_URL=${{ env.REACT_APP_API_URL }} \ ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} docker logout diff --git a/.github/workflows/deploy-staging.yml b/.github/workflows/deploy-staging.yml index 80b71c2..abb5f0e 100644 --- a/.github/workflows/deploy-staging.yml +++ b/.github/workflows/deploy-staging.yml @@ -34,7 +34,6 @@ jobs: docker pull ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:pr-${{ github.event.pull_request.number }} docker rm -f ${{ env.NAME }} docker run -dp 8085:${{ env.SERVER_PORT }} --name ${{ env.NAME }} \ - -e REACT_APP_API_URL=${{ env.REACT_APP_API_URL }} \ ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:pr-${{ github.event.pull_request.number }} docker logout diff --git a/.github/workflows/docker-image.yml b/.github/workflows/docker-image.yml index 6b12c0e..e20df13 100644 --- a/.github/workflows/docker-image.yml +++ b/.github/workflows/docker-image.yml @@ -9,6 +9,7 @@ on: env: REGISTRY: ghcr.io IMAGE_NAME: ${{ github.repository }} + REACT_APP_API_URL: https://soroka.f128.science/restapi/v1 jobs: @@ -38,6 +39,8 @@ jobs: uses: docker/build-push-action@v3 with: context: . + build-args: + REACT_APP_API_URL=${{ env.REACT_APP_API_URL }} target: prod push: true tags: ${{ steps.meta.outputs.tags }} diff --git a/Dockerfile b/Dockerfile index a4f69bf..37bea0f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,5 +1,8 @@ FROM node:lts-alpine AS builder +ARG REACT_APP_API_URL +ENV REACT_APP_API_URL ${REACT_APP_API_URL} + WORKDIR /opt/app COPY . /opt/app @@ -10,9 +13,13 @@ RUN npm run build FROM nginx:stable-alpine AS prod COPY --from=builder /opt/app/build /usr/share/nginx/html +COPY default.conf /etc/nginx/conf.d/default.conf FROM node:lts AS dev +ARG REACT_APP_API_URL +ENV REACT_APP_API_URL $REACT_APP_API_URL + WORKDIR /opt/app COPY --from=builder /opt/app /opt/app diff --git a/default.conf b/default.conf new file mode 100644 index 0000000..1d49023 --- /dev/null +++ b/default.conf @@ -0,0 +1,16 @@ +server { + listen 80; + listen [::]:80; + server_name localhost; + + root /usr/share/nginx/html; + index index.html; + + location / { + try_files $uri $uri/ /index.html; + } + error_page 500 502 503 504 /50x.html; + location = /50x.html { + root /usr/share/nginx/html; + } +} \ No newline at end of file