Skip to content

Commit

Permalink
fix(docker): stop building staging, prod, enterprise in favor of unif…
Browse files Browse the repository at this point in the history
…ied (#3281)

## Changes

- Stop building staging, prod, enterprise in favor of unified 
This means the unified `dockerfile` is built only once and not twice,
and I have removed enterprise staging and prod for server (aka we only
build one server).
After this is merged, the images won't be tagged by their env, it will
also save time on the CI and we might be able to deploy prod directly
from PR (handy for hot fixes but I need to test it first).

We still need to build `server-hosted` separately until we officially
support this use case. This already works but needs official
communication and deprecation period.
  • Loading branch information
bodinsamuel authored Jan 13, 2025
1 parent 40f3b0d commit c7a8410
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 105 deletions.
52 changes: 0 additions & 52 deletions .github/workflows/build-image-reusable.yaml

This file was deleted.

49 changes: 34 additions & 15 deletions .github/workflows/build-image.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,37 @@ on:

jobs:
build-image:
# TODO: remove this, it's only needed for the frontend
strategy:
matrix:
group:
- name: 'staging'
if: true

- name: 'prod'
if: ${{ github.ref == 'refs/heads/master' }}

secrets: inherit
uses: ./.github/workflows/build-image-reusable.yaml
with:
if: ${{ matrix.group.if }}
name: ${{ matrix.group.name }}
runs-on: ubuntu-latest
env:
CAN_PUSH: "${{ secrets.DOCKER_PASSWORD != '' && secrets.DOCKER_USERNAME != '' }}"
SHA: ${{ github.event.pull_request.head.sha || github.sha }}

steps:
- name: Check out
uses: actions/checkout@v4

- name: Set up QEMU
uses: docker/setup-qemu-action@v3

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Log in to Docker Hub
uses: docker/login-action@v3
if: env.CAN_PUSH == 'true'
with:
username: '${{ secrets.DOCKER_USERNAME }}'
password: '${{ secrets.DOCKER_PASSWORD }}'

# Needed for buildx gha cache to work
- name: Expose GitHub Runtime
uses: crazy-max/ghaction-github-runtime@v2

- name: Build image
run: |
./scripts/build_docker.sh build ${{ env.SHA }}
- name: Push image
if: env.CAN_PUSH == 'true'
run: |
docker push nangohq/nango:${{ env.SHA }}
22 changes: 3 additions & 19 deletions .github/workflows/build-images.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,14 @@ jobs:
with:
package: runner
run-cmd: ts-build
tags: -t nangohq/nango-runner:${{ github.event.pull_request.head.sha || github.sha }} ${{ github.ref == 'refs/heads/master' && format('-t nangohq/nango-runner:enterprise-{0} -t nangohq/nango-runner:enterprise -t nangohq/nango-runner:hosted-{1} -t nangohq/nango-runner:hosted', github.event.pull_request.head.sha || github.sha, github.event.pull_request.head.sha || github.sha) || '' }}
nango-server-staging:
tags: -t nangohq/nango-runner:${{ github.event.pull_request.head.sha || github.sha }}
nango-server:
uses: ./.github/workflows/push-container.yaml
secrets: inherit
with:
package: server
run-cmd: build:prod
tags: -t nangohq/nango-server:staging-${{ github.event.pull_request.head.sha || github.sha }}
nango-server-prod:
if: github.ref == 'refs/heads/master'
uses: ./.github/workflows/push-container.yaml
secrets: inherit
with:
package: server
run-cmd: build:prod
tags: -t nangohq/nango-server:production-${{ github.event.pull_request.head.sha || github.sha }}
tags: -t nangohq/nango-server:${{ github.event.pull_request.head.sha || github.sha }}
nango-server-self-hosted:
if: github.ref == 'refs/heads/master'
uses: ./.github/workflows/push-container.yaml
Expand All @@ -42,11 +34,3 @@ jobs:
package: server
run-cmd: build:hosted
tags: -t nangohq/nango-server:hosted -t nangohq/nango-server:hosted-${{ github.event.pull_request.head.sha || github.sha }}
nango-server-enterprise:
if: github.ref == 'refs/heads/master'
uses: ./.github/workflows/push-container.yaml
secrets: inherit
with:
package: server
run-cmd: build:prod
tags: -t nangohq/nango-server:enterprise -t nangohq/nango-server:enterprise-${{ github.event.pull_request.head.sha || github.sha }}
11 changes: 4 additions & 7 deletions .github/workflows/deploy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ jobs:
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Push tag
run: |
docker buildx imagetools create nangohq/nango-server:${{ inputs.stage }}-${{ github.sha }} --tag nangohq/nango-server:${{ inputs.stage }}
docker buildx imagetools create nangohq/nango-server:${{ github.sha }} --tag nangohq/nango-server:${{ inputs.stage }}
- name: Deploy server
run: |
SERVICE_ID=${{ fromJson('{ production: "srv-cfifsvha6gdq1k7u46a0", staging: "srv-cmj6t6da73kc739ol660" }')[inputs.stage] }}
Expand All @@ -58,8 +58,7 @@ jobs:
- name: Deploy jobs
run: |
SERVICE_ID=${{ fromJson('{ production: "srv-clvvtdug1b2c73cklps0", staging: "srv-clthttda73kc73ejflg0" }')[inputs.stage] }}
IMAGE_TAG_PREFIX=${{ fromJson('{ "production": "prod", "staging": "staging" }')[inputs.stage] }}
IMAGE="docker.io/nangohq/nango:${IMAGE_TAG_PREFIX}-${{ github.sha }}"
IMAGE="docker.io/nangohq/nango:${{ github.sha }}"
echo "Deploying $IMAGE to $SERVICE_ID"
Expand Down Expand Up @@ -108,8 +107,7 @@ jobs:
- name: Deploy persist
run: |
SERVICE_ID=${{ fromJson('{ "production": "srv-cmt150ol6cac73apstq0", "staging": "srv-cmsfiqqcn0vc73bhcod0" }')[inputs.stage] }}
IMAGE_TAG_PREFIX=${{ fromJson('{ "production": "prod", "staging": "staging" }')[inputs.stage] }}
IMAGE="docker.io/nangohq/nango:${IMAGE_TAG_PREFIX}-${{ github.sha }}"
IMAGE="docker.io/nangohq/nango:${{ github.sha }}"
echo "Deploying $IMAGE to $SERVICE_ID"
Expand All @@ -130,8 +128,7 @@ jobs:
- name: Deploy orchestrator
run: |
SERVICE_ID=${{ fromJson('{ "production": "srv-cp6bhl0l6cac738i3dm0", "staging": "srv-cp5qedsf7o1s739kjqtg" }')[inputs.stage] }}
IMAGE_TAG_PREFIX=${{ fromJson('{ "production": "prod", "staging": "staging" }')[inputs.stage] }}
IMAGE="docker.io/nangohq/nango:${IMAGE_TAG_PREFIX}-${{ github.sha }}"
IMAGE="docker.io/nangohq/nango:${{ github.sha }}"
echo "Deploying $IMAGE to $SERVICE_ID"
Expand Down
16 changes: 4 additions & 12 deletions scripts/build_docker.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,10 @@
set -e

ACTION=$1
ENV=$2 # enterprise | hosted | prod | staging \\ TODO: remove this, it's only needed for the frontend
GIT_HASH=$3
GIT_HASH=$2

USAGE="./build_docker.sh <build|push> <enterprise | hosted | prod | staging> GIT_HASH"
USAGE="./build_docker.sh <build|push> GIT_HASH"
RED='\033[0;31m'
YELLOW='\033[0;33m'
NC='\033[0m'

if [ "$ACTION" != "push" ] && [ "$ACTION" != "build" ]; then
Expand All @@ -17,12 +15,6 @@ if [ "$ACTION" != "push" ] && [ "$ACTION" != "build" ]; then
exit
fi

if [ "$ENV" != "enterprise" ] && [ "$ENV" != "hosted" ] && [ "$ENV" != "prod" ] && [ "$ENV" != "staging" ]; then
echo -e "${RED}Please specify an environment${NC}\n"
echo "$USAGE"
exit
fi

if [ -z $GIT_HASH ]; then
echo -e "${RED}GIT_HASH is empty${NC}"
exit
Expand All @@ -31,7 +23,7 @@ fi
# Move to here no matter where the file was executed
cd "$(dirname "$0")"

tags="-t nangohq/nango:${ENV}-${GIT_HASH}"
tags="-t nangohq/nango:${GIT_HASH}"

if [ $ACTION == 'build' ]; then
tags+=" --output=type=docker"
Expand All @@ -40,7 +32,7 @@ else
fi

echo ""
echo -e "Building nangohq/nango:$ENV\n"
echo -e "Building nangohq/nango\n"

docker buildx build \
--platform linux/amd64 \
Expand Down

0 comments on commit c7a8410

Please sign in to comment.