diff --git a/.github/workflows/cd.yaml b/.github/workflows/cd.yaml index 7bbf8966..8e9b3e7e 100644 --- a/.github/workflows/cd.yaml +++ b/.github/workflows/cd.yaml @@ -4,11 +4,12 @@ on: push: branches: - "main" - pull_request: + - "devops" env: PROJECT_ID: ${{ secrets.GKE_PROJECT }} GKE_CLUSTER: ${{ secrets.GKE_CLUSTER_NAME }} + ENV_PROD: ${{ secrets.ENV_PROD }} GKE_ZONE: us-central1-c IMAGE: api-cct MY_ENV: production @@ -53,6 +54,10 @@ jobs: location: ${{ env.GKE_ZONE }} credentials: ${{ secrets.GKE_SA_KEY }} + - name: Mount env + run: |- + echo $ENV_PROD > .env + - name: Build Docker image run: |- docker build \ @@ -66,15 +71,13 @@ jobs: - name: Set up Kustomize run: |- + cd ./.kubernetes/prod curl -sfLo kustomize https://github.com/kubernetes-sigs/kustomize/releases/download/v3.1.0/kustomize_3.1.0_linux_amd64 chmod u+x ./kustomize - - name: Set up Kustomize - run: |- - envsubst < kustomization.yaml.tmpl > kustomization.yaml - - name: Deploy run: |- + cd ./.kubernetes/prod ./kustomize edit set image gcr.io/PROJECT_ID/IMAGE_API:TAG=gcr.io/$PROJECT_ID/$IMAGE:$GITHUB_SHA ./kustomize build . | kubectl apply -n cct -f - kubectl get services -n cct -o wide diff --git a/.kubernetes/prod/k8s.yml b/.kubernetes/prod/k8s.yml index 1149487a..e7bb6de6 100644 --- a/.kubernetes/prod/k8s.yml +++ b/.kubernetes/prod/k8s.yml @@ -20,17 +20,7 @@ spec: spec: containers: - name: cct-api - image: gcr.io/rj-smtr/api-cct:1.0.1-rc.1 - command: - [ - "sh", - "-c", - "sed", - "-i", - "'14s/.*/DATABASE_PASWORD=${DATABASE_PASSWORD}/'", - "-f", - "/usr/src/app/.env", - ] + image: gcr.io/PROJECT_ID/IMAGE_APP:TAG ports: - containerPort: 3000 # resources: diff --git a/Dockerfile b/Dockerfile index c1da0b53..08f7bd75 100644 --- a/Dockerfile +++ b/Dockerfile @@ -14,7 +14,7 @@ RUN sed -i 's/\r//g' /opt/wait-for-it.sh RUN sed -i 's/\r//g' /opt/startup.dev.sh WORKDIR /usr/src/app -RUN cp env-deploy .env +RUN cp .env .env RUN npm run build CMD ["/opt/startup.dev.sh"]