-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #17 from Vizzuality/infrastructure
Infrastructure
- Loading branch information
Showing
38 changed files
with
1,153 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,137 @@ | ||
name: Run deploy | ||
|
||
on: | ||
workflow_dispatch: | ||
push: | ||
branches: | ||
- develop | ||
paths: | ||
- 'client/**' | ||
- 'cms/**' | ||
- '.github/workflows/*' | ||
|
||
env: | ||
PROJECT_NAME: "esa-gda-comms" | ||
IMAGE_REGISTRY: "registry.digitalocean.com/esa-gda-comms" | ||
|
||
jobs: | ||
build_client_image: | ||
name: Build Client image and push to DO Container Registry | ||
runs-on: ubuntu-22.04 | ||
|
||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v3 | ||
|
||
- name: Extract branch name | ||
shell: bash | ||
run: echo "branch=${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}}" >> $GITHUB_OUTPUT | ||
id: extract_branch | ||
|
||
- name: Copy env variables to docker | ||
env: | ||
ENVIRONMENT: ${{ steps.extract_branch.outputs.branch == 'main' && 'PROD' || 'STAGING' }} | ||
run: | | ||
echo "${{ secrets[format('{0}_CLIENT_ENV_FILE', env.ENVIRONMENT)] }}" > client/.env.local | ||
- name: Build and tag Client image | ||
env: | ||
IMAGE_NAME: ${{ env.PROJECT_NAME }}-${{ steps.extract_branch.outputs.branch == 'main' && 'production' || 'staging' }}-client | ||
run: | | ||
docker build -f client/Dockerfile.prod -t $IMAGE_REGISTRY/$IMAGE_NAME:$GITHUB_SHA . | ||
- name: Install doctl | ||
uses: digitalocean/action-doctl@v2 | ||
with: | ||
token: ${{ secrets.DIGITALOCEAN_ACCESS_TOKEN }} | ||
|
||
- name: Log in to DO Container Registry | ||
run: doctl registry login --expiry-seconds 600 | ||
|
||
- name: Push image to DigitalOcean Container Registry | ||
env: | ||
IMAGE_NAME: ${{ env.PROJECT_NAME }}-${{ steps.extract_branch.outputs.branch == 'main' && 'production' || 'staging' }}-client | ||
run: docker push $IMAGE_REGISTRY/$IMAGE_NAME:$GITHUB_SHA | ||
|
||
- name: Remove old images from Container Registry | ||
uses: ripplr-io/docr-image-remove@v1 | ||
with: | ||
image_repository: ${{ env.PROJECT_NAME }}-${{ steps.extract_branch.outputs.branch == 'main' && 'production' || 'staging' }}-client | ||
buffer_size: 5 | ||
|
||
build_cms_image: | ||
name: Build CMS image and push to DO Container Registry | ||
runs-on: ubuntu-22.04 | ||
|
||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v3 | ||
|
||
- name: Extract branch name | ||
shell: bash | ||
run: echo "branch=${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}}" >> $GITHUB_OUTPUT | ||
id: extract_branch | ||
|
||
- name: Copy env variables to docker | ||
env: | ||
ENVIRONMENT: ${{ steps.extract_branch.outputs.branch == 'main' && 'PROD' || 'STAGING' }} | ||
run: | | ||
echo "${{ secrets[format('{0}_CMS_ENV_FILE', env.ENVIRONMENT)] }}" > cms/.env | ||
- name: Build and tag CMS image | ||
env: | ||
IMAGE_NAME: ${{ env.PROJECT_NAME }}-${{ steps.extract_branch.outputs.branch == 'main' && 'production' || 'staging' }}-cms | ||
run: | | ||
docker build -f cms/Dockerfile.prod -t $IMAGE_REGISTRY/$IMAGE_NAME:$GITHUB_SHA . | ||
- name: Install doctl | ||
uses: digitalocean/action-doctl@v2 | ||
with: | ||
token: ${{ secrets.DIGITALOCEAN_ACCESS_TOKEN }} | ||
|
||
- name: Log in to DO Container Registry | ||
run: doctl registry login --expiry-seconds 600 | ||
|
||
- name: Push image to DigitalOcean Container Registry | ||
env: | ||
IMAGE_NAME: ${{ env.PROJECT_NAME }}-${{ steps.extract_branch.outputs.branch == 'main' && 'production' || 'staging' }}-cms | ||
run: docker push $IMAGE_REGISTRY/$IMAGE_NAME:$GITHUB_SHA | ||
|
||
- name: Remove old images from Container Registry | ||
uses: ripplr-io/docr-image-remove@v1 | ||
with: | ||
image_repository: ${{ env.PROJECT_NAME }}-${{ steps.extract_branch.outputs.branch == 'main' && 'production' || 'staging' }}-cms | ||
buffer_size: 5 | ||
|
||
deploy: | ||
name: Deploy Client and CMS to DO APP Platform | ||
needs: [build_client_image, build_cms_image] | ||
runs-on: ubuntu-22.04 | ||
|
||
steps: | ||
- name: DigitalOcean App Platform deployment | ||
uses: digitalocean/[email protected] | ||
env: | ||
IMAGE_NAME_CLIENT: ${{ env.PROJECT_NAME }}-${{ steps.extract_branch.outputs.branch == 'main' && 'production' || 'staging' }}-client | ||
IMAGE_NAME_CMS: ${{ env.PROJECT_NAME }}-${{ steps.extract_branch.outputs.branch == 'main' && 'production' || 'staging' }}-cms | ||
with: | ||
app_name: ${{ env.PROJECT_NAME }}-${{ steps.extract_branch.outputs.branch == 'main' && 'production' || 'staging' }} | ||
token: ${{ secrets.DIGITALOCEAN_ACCESS_TOKEN }} | ||
images: '[ | ||
{ | ||
"name": "${{ env.IMAGE_NAME_CLIENT }}", | ||
"image":{ | ||
"registry_type": "DOCR", | ||
"repository": "${{ env.IMAGE_NAME_CLIENT }}", | ||
"tag": "${{ github.sha }}" | ||
} | ||
}, | ||
{ | ||
"name": "${{ env.IMAGE_NAME_CMS }}", | ||
"image":{ | ||
"registry_type": "DOCR", | ||
"repository": "${{ env.IMAGE_NAME_CMS }}", | ||
"tag": "${{ github.sha }}" | ||
} | ||
} | ||
]' |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
# Build all the things | ||
FROM node:18.15.0-bullseye-slim AS build | ||
RUN apt-get update -y && \ | ||
apt-get upgrade -y && \ | ||
apt-get install -y libc6 && \ | ||
apt-get clean | ||
ENV NODE_ENV production | ||
ENV NEXT_TELEMETRY_DISABLED 1 | ||
|
||
WORKDIR /app | ||
COPY .yarn ./.yarn | ||
COPY package.json .yarnrc.yml yarn.lock .prettierrc.js ./ | ||
|
||
WORKDIR /app/client | ||
COPY ./client/package.json ./ | ||
RUN yarn install | ||
|
||
COPY ./client . | ||
|
||
RUN yarn build | ||
|
||
# Copy only the built files into the final image | ||
FROM node:18.15.0-bullseye-slim AS runner | ||
ENV NODE_ENV production | ||
ENV NEXT_TELEMETRY_DISABLED 1 | ||
|
||
WORKDIR /app | ||
|
||
RUN addgroup --system --gid 1001 nodejs | ||
RUN adduser --system --uid 1001 nextjs | ||
|
||
COPY --from=build --chown=nextjs:nodejs /app/client/.next ./.next | ||
COPY --from=build --chown=nextjs:nodejs /app/client/entrypoint.sh ./entrypoint.sh | ||
COPY --from=build /app/node_modules ./node_modules | ||
COPY --from=build /app/client/package.json ./package.json | ||
|
||
USER nextjs | ||
|
||
EXPOSE 3000 | ||
ENV PORT 3000 | ||
|
||
ENTRYPOINT ["/app/entrypoint.sh"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#!/bin/sh | ||
set -e | ||
|
||
case "${NODE_ENV}" in | ||
development) | ||
echo "Running Development Server" | ||
exec yarn dev | ||
;; | ||
test) | ||
echo "Running Test" | ||
exec yarn test | ||
;; | ||
production) | ||
echo "Running Production Server" | ||
exec yarn start | ||
;; | ||
*) | ||
echo "Unknown NODE environment: \"${NODE_ENV}\"" | ||
esac |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
FROM node:18.15.0-bullseye-slim | ||
# Install dependencies | ||
RUN apt-get update -y && \ | ||
apt-get upgrade -y && \ | ||
apt-get install -y \ | ||
build-essential \ | ||
gcc autoconf \ | ||
automake \ | ||
zlib1g-dev \ | ||
libpng-dev \ | ||
nasm bash \ | ||
libvips-dev \ | ||
&& apt-get clean | ||
|
||
WORKDIR /app/ | ||
COPY .yarn ./.yarn | ||
COPY package.json .yarnrc.yml yarn.lock ./ | ||
|
||
WORKDIR /app/cms | ||
COPY ./cms/package.json ./ | ||
RUN yarn install | ||
|
||
ENV PATH /app/node_modules/.bin:$PATH | ||
|
||
COPY ./cms . | ||
RUN chown -R node:node /app/cms | ||
USER node | ||
RUN ["yarn", "prebuild"] | ||
RUN ["yarn", "build"] | ||
EXPOSE 1337 | ||
ENTRYPOINT ["/app/cms/entrypoint.sh"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
# Build all the things | ||
FROM node:18.15.0-bullseye-slim as build | ||
RUN apt-get update -y && \ | ||
apt-get upgrade -y && \ | ||
apt-get install -y \ | ||
build-essential \ | ||
gcc autoconf \ | ||
automake \ | ||
zlib1g-dev \ | ||
libpng-dev \ | ||
nasm bash \ | ||
libvips-dev \ | ||
&& apt-get clean | ||
|
||
ENV NODE_ENV production | ||
|
||
WORKDIR /app | ||
COPY .yarn ./.yarn | ||
COPY package.json .yarnrc.yml yarn.lock ./ | ||
|
||
WORKDIR /app/cms | ||
COPY ./cms/package.json ./ | ||
RUN yarn install | ||
|
||
COPY ./cms . | ||
RUN yarn prebuild | ||
RUN yarn build | ||
|
||
# Copy only the built files into the final image | ||
FROM node:18.15.0-bullseye-slim AS runner | ||
RUN apt-get update -y && \ | ||
apt-get upgrade -y && \ | ||
apt-get install -y libvips-dev && \ | ||
apt-get clean | ||
|
||
ENV NODE_ENV production | ||
|
||
WORKDIR /app | ||
|
||
RUN addgroup --system --gid 1001 nodejs | ||
RUN adduser --system --uid 1001 strapi | ||
|
||
COPY --from=build --chown=strapi:nodejs /app/cms ./ | ||
COPY --from=build /app/node_modules ./node_modules | ||
|
||
USER strapi | ||
|
||
EXPOSE 1337 | ||
ENTRYPOINT ["/app/entrypoint.sh"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#!/bin/bash | ||
set -e | ||
|
||
case "${NODE_ENV}" in | ||
development) | ||
echo "Running Development Server" | ||
exec yarn dev | ||
;; | ||
test) | ||
echo "Running Test" | ||
exec yarn test | ||
;; | ||
production) | ||
echo "Running Production Server" | ||
exec yarn start | ||
;; | ||
*) | ||
echo "Unknown NODE environment: \"${NODE_ENV}\"" | ||
esac |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.