Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds a way to deploy to an externally hosted develop environment. #460

Draft
wants to merge 31 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
99b6ff5
Merge branch 'develop' into feature/dev-deploy-setup
pablojmarti Apr 21, 2023
b8d6f19
Creates deployment configuration file
pablojmarti Apr 21, 2023
6a91c4f
feat: configures next for develop deployment
pablojmarti Apr 25, 2023
84d9abc
feat: initial commit for docker config
pablojmarti Apr 25, 2023
7df4527
feat: creates .dockeringore, adds build steps to dockerG
pablojmarti Apr 25, 2023
8c32d54
feat: adds docker build to deploy
pablojmarti Apr 25, 2023
301c020
feat: fix syntax error
pablojmarti Apr 25, 2023
1659eeb
feat: updates dockerignore to ingore .next files
pablojmarti Apr 26, 2023
bbfb576
feat: get initial configuration for docker container working
pablojmarti Apr 26, 2023
a4a2445
feat: additional folders needed to be copied over
pablojmarti Apr 26, 2023
25219b2
feat: adds login for packages
pablojmarti Apr 26, 2023
27b3714
fix: yaml syntax
pablojmarti Apr 26, 2023
60919ee
feat: adds metadata extraction for tagging docker images
pablojmarti Apr 26, 2023
c7fbe2c
feat: removes old build step, renames docker build, adds puh to registry
pablojmarti Apr 26, 2023
ce3b26f
fix: wrong variable name
pablojmarti Apr 26, 2023
8710866
fix: remove image name that does not exist
pablojmarti Apr 26, 2023
5ae1891
feat: adds docker.10up.com support
pablojmarti Apr 26, 2023
174bd05
fix: var name
pablojmarti Apr 26, 2023
ec9c086
feat: adds platform to docker build
pablojmarti Apr 26, 2023
b743f4e
feat: adds pipeline trigger to push node changes to kube
pablojmarti Apr 27, 2023
e914f5d
fix: syntax
pablojmarti Apr 27, 2023
e0fb08e
fix: hardcode path for testing
pablojmarti Apr 27, 2023
651e989
feat: adds next specific buildargs
pablojmarti Apr 27, 2023
e9863a4
fix: syntax
pablojmarti Apr 27, 2023
aecc3e4
fix: syntax
pablojmarti Apr 27, 2023
89625b7
feat: add redis url
pablojmarti Apr 27, 2023
9fe8e54
revert: hardcode
pablojmarti Apr 27, 2023
b6c95ac
test: moving redis directly
pablojmarti Apr 27, 2023
ed2d65e
test: copy packages directly into node_modules
pablojmarti Apr 28, 2023
4a36c6b
Merge branch 'develop' into feature/dev-deploy-setup
pablojmarti Jun 1, 2023
c8c5278
feat: remove feature branch from deploy in order to get ready for PR
pablojmarti Jun 1, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
**/node_modules
**/.env*
deploy/*
!deploy/entrypoint.sh
**/.next
.git
README.md
.dockerignore
Dockerfile
2 changes: 1 addition & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ dist
node_modules
vendor
./examples/**/**
projects/docs/public
projects/docs/public
73 changes: 73 additions & 0 deletions .github/workflows/deploy_to_develop.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
name: Deploy to Develop ( headless.10uplabs.com )

on:
push:
branches:
- develop

jobs:
build_and_push:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3

# useful for emulation and building for different architectures
- name: Set Up QEMU
uses: docker/setup-qemu-action@v2

# Use Dockers Buildx build plugin
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2

- name: Login to 10up Docker
uses: docker/login-action@v2
with:
registry: docker.10up.com
username: ${{ secrets.DOCKER_USER }}
password: ${{ secrets.DOCKER_PASSWORD }}

- name: Login to Github Packages
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

# set image tag to the branch name
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v4
with:
tags: |
type=ref,enable=true,priority=600,prefix=,suffix,event=branch
images: |
${{ secrets.IMAGE_NAME }}
ghcr.io/${{ github.repository }}

# TODO: Login to docker hub
- name: Build container and push to Github Packages
uses: docker/build-push-action@v4
with:
file: deploy/Dockerfile
build-args: |
HOST_URL=${{ secrets.HOST_URL }}
NEXT_PUBLIC_HEADLESS_WP_URL=${{ secrets.NEXT_PUBLIC_HEADLESS_WP_URL }}
tags: ${{ steps.meta.outputs.tags }}
platforms: linux/amd64,linux/arm64
push: true
context: .

deploy:
needs: build_and_push

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3

- name: Trigger Pipeline
run: curl --request POST --form token=${{ secrets.PIPELINE_TOKEN }} --form ref=trunk "${{ secrets.PIPELINE_URL }}"


45 changes: 45 additions & 0 deletions deploy/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
FROM node:16-alpine AS builder

ARG BUILD_TYPE="dev"

# disable telemetry data
ARG NEXT_TELEMETRY_DISABLED=1

ARG HOST_URL

ARG NEXT_PUBLIC_HEADLESS_WP_URL

ARG NEXT_REDIS_URL="redis"

WORKDIR /app

COPY . .

# Install Packages
RUN npm install
# Build node modules
RUN npm run build:packages

# build headless project
RUN npm run build -- --filter=./projects/wp-nextjs

FROM node:16-alpine AS runner

WORKDIR /app

# Setup node and next user/groups
RUN addgroup --system --gid 1001 nodejs
RUN adduser --system --uid 1001 nextjs

# Copy Next configuration files to runner
COPY --from=builder --chown=nextjs:nodejs /app/projects/wp-nextjs/.next/standalone ./
COPY --from=builder --chown=nextjs:nodejs /app/projects/wp-nextjs/.next/server ./projects/wp-nextjs/.next/server
COPY --from=builder --chown=nextjs:nodejs /app/projects/wp-nextjs/.next/static ./projects/wp-nextjs/.next/static
COPY --from=builder --chown=nextjs:nodejs /app/projects/wp-nextjs/.next/standalone/packages ./node_modules/packages

# Copy entrypoint script
COPY --from=builder --chown=nexjs:nodejs /app/deploy/entrypoint.sh ./

USER nextjs

CMD ["/bin/sh" , "./entrypoint.sh"]
3 changes: 3 additions & 0 deletions deploy/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env sh

node projects/wp-nextjs/server.js
9 changes: 9 additions & 0 deletions projects/wp-nextjs/next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ const nextConfig = {
eslint: {
ignoreDuringBuilds: true,
},

output: 'standalone',
};

// if you are not using polylang integration you can remove this code
Expand All @@ -26,4 +28,11 @@ if (process.env?.ENABLE_POLYLANG_INTEGRATION === 'true') {
};
}

// if the redis URL is set, configure redis caching system
if (process.env?.NEXT_REDIS_URL) {
nextConfig.experimental = {
incrementalCacheHandlerPath: require.resolve('@10up/next-redis-cache-provider'),
};
}

module.exports = withBundleAnalyzer(withHeadlessConfig(nextConfig, headlessConfig));