Skip to content

Commit

Permalink
fix/ci: build with environment specific API URI value (#4)
Browse files Browse the repository at this point in the history
  • Loading branch information
fredrikmonsen authored Aug 8, 2024
1 parent 518585b commit 325285d
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .github/workflows/ci_pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,9 @@ jobs:
context: .
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
build-args: |
HTTP_PROXY=${{ secrets.HTTP_PROXY }}
HTTPS_PROXY=${{ secrets.HTTPS_PROXY }}
deploy-to-stage:
name: Deploy stage environment
Expand Down Expand Up @@ -145,6 +148,7 @@ jobs:
run: |
echo "Deploying to stage version ${{ env.APP_VERSION }}"
sed -i "s|<image>|${{ steps.import-harbor-secrets.outputs.HARBOR_URL }}/tekst/moki:${{ needs.build-and-publish.outputs.image_version }}|g" k8s/stage/moki.yml
sed -i "s/<api_host_url>/${{ steps.import-k8s-secrets.outputs.K8S_HOST_URL }}/g" k8s/stage/moki.yml
sed -i "s/<host_url>/${{ steps.import-k8s-secrets.outputs.K8S_HOST_URL }}/g" k8s/stage/moki.yml
kubectl config set-cluster stagecl --server=${{ steps.import-k8s-secrets.outputs.K8S_STAGE_SERVER }}
kubectl config set clusters.stagecl.certificate-authority-data ${{ steps.import-k8s-secrets.outputs.K8S_STAGE_NB_NO_CA }}
Expand Down Expand Up @@ -197,6 +201,7 @@ jobs:
run: |
echo "Deploying to production version ${{ env.APP_VERSION }}"
sed -i "s|<image>|${{ steps.import-harbor-secrets.outputs.HARBOR_URL }}/tekst/moki:${{ needs.build-and-publish.outputs.image_version }}|g" k8s/prod/moki.yml
sed -i "s/<api_host_url>/${{ steps.import-k8s-secrets.outputs.K8S_HOST_URL }}/g" k8s/prod/moki.yml
sed -i "s/<host_url>/${{ steps.import-k8s-secrets.outputs.K8S_PRODUCTION_HOST_URL }}/g" k8s/prod/moki.yml
kubectl config set-cluster prodcl --server=${{ steps.import-k8s-secrets.outputs.K8S_PROD_SERVER }}
kubectl config set clusters.prodcl.certificate-authority-data ${{ steps.import-k8s-secrets.outputs.K8S_PROD_NB_NO_CA }}
Expand Down
12 changes: 10 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
FROM nginx:1.27.0-alpine

ARG HTTP_PROXY
ARG HTTPS_PROXY

ENV HTTP_PROXY=$HTTP_PROXY
ENV HTTPS_PROXY=$HTTPS_PROXY

COPY dist/moki/browser /usr/share/nginx/html/moki
COPY nginx /opt
RUN rm /etc/nginx/conf.d/default.conf

COPY ./nginx.conf /etc/nginx/conf.d/default.conf
RUN apk add --no-cache bash

EXPOSE 80

CMD ["nginx-debug", "-g", "daemon off;"]
CMD /bin/bash -c "bash /opt/inject-env.sh /opt/nginx.conf /etc/nginx/conf.d/nginx.conf && exec nginx -g 'daemon off;'"
3 changes: 3 additions & 0 deletions k8s/prod/moki.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ spec:
ports:
- name: app-port
containerPort: 4200
env:
- name: API_HOST_URL
value: <api_host_url>
imagePullPolicy: Always
livenessProbe:
httpGet:
Expand Down
3 changes: 3 additions & 0 deletions k8s/stage/moki.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ spec:
ports:
- name: app-port
containerPort: 4200
env:
- name: API_HOST_URL
value: <api_host_url>
imagePullPolicy: Always
livenessProbe:
httpGet:
Expand Down
14 changes: 14 additions & 0 deletions nginx/inject-env.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/usr/bin/env bash

NGINX_TEMPLATE_FILE=$1
NGINX_OUTPUT_FILE=$2

if [[ ! -f ${NGINX_TEMPLATE_FILE} ]]
then
echo "ERROR: Parameter 1 nginx.conf file ('$NGINX_TEMPLATE_FILE') does not exist."
exit 1
fi


sed -e s~%API_HOST_URL%~"${API_HOST_URL}"~g \
"${NGINX_TEMPLATE_FILE}" > "${NGINX_OUTPUT_FILE}"
4 changes: 4 additions & 0 deletions nginx.conf → nginx/nginx.conf
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,8 @@ server {
add_header 'Content-Type' 'text/plain';
return 200 "Healthy\n";
}

location ^~ /moki/papi/proddb {
proxy_pass https://%API_HOST_URL%/papi;
}
}
7 changes: 5 additions & 2 deletions src/proxy.conf.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
{
"/papi": {
"target": "http://localhost:8087",
"target": "http://localhost:8087/papi",
"secure": false,
"logLevel": "debug",
"changeOrigin": true
"changeOrigin": true,
"pathRewrite": {
"^/papi": ""
}
}
}

0 comments on commit 325285d

Please sign in to comment.