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

chore: update deploy workflow #349

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
38 changes: 19 additions & 19 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
{
"presets": ["next/babel"],
"plugins": [
[
"transform-imports",
{
"material-ui/core": {
"transform": "material-ui/core/esm/${member}",
"preventFullImport": true
"presets": ["next/babel"],
"plugins": [
[
"transform-imports",
{
"material-ui/core": {
"transform": "material-ui/core/esm/${member}",
"preventFullImport": true
}
}
}
],
[
"module-resolver",
{
"root": ["./src"],
"alias": {
"@/sensorsafrica": "./src"
],
[
"module-resolver",
{
"root": ["./src"],
"alias": {
"@/sensorsafrica": "./src"
}
}
}
]
]
]
}
}
66 changes: 45 additions & 21 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -1,52 +1,69 @@
name: main
on:
push:
branches: [main]
branches:
- main
- chore/update-workflow

# This allows a subsequently queued workflow run to interrupt previous runs
concurrency:
group: "${{ github.workflow }} @ ${{ github.ref }}"
cancel-in-progress: true

env:
DOKKU_REMOTE_BRANCH: "master"
DOKKU_REMOTE_URL: "ssh://[email protected]/sensors-africa-ui"
DOKKU_REMOTE_URL: "ssh://[email protected]/sensors-africa-ui"
NEXT_PUBLIC_APP_URL: "https://sensors.africa"
NEXT_PUBLIC_APP_API_BASE_URL: "https://api.sensors.africa/v2"
NEXT_PUBLIC_APP_MAP_URL: "https://v2.map.aq.sensors.africa/"
IMAGE_NAME: "codeforafrica/sensors-africa-ui"
GIT_PUSH_FLAGS: "--force"
VERSION_FILE_NAME: "package.json"

jobs:
deploy:
runs-on: ubuntu-latest
runs-on: ${{ matrix.os }}
strategy:
matrix:
node-version: [20.18]
os: [ubuntu-latest]
steps:
- name: Cancel Previous Runs
uses: styfle/[email protected]
with:
access_token: ${{ github.token }}

- name: Checkout
uses: actions/checkout@v2
uses: actions/checkout@v4
with:
fetch-depth: 0

# Set up Node since it's required by version-check
# https://github.com/EndBug/version-check#github-workflow
- name: Setup Node.js
uses: actions/setup-node@v2
uses: actions/setup-node@v4
with:
node-version: "18"
node-version: ${{ matrix.node-version }}

- name: Check if version is bumped
id: version-check
uses: EndBug/version-check@v1
uses: EndBug/version-check@v2
with:
# Whether to search in every commit's diff.
# This is useful if you often do change the version without saying it
# in the commit message. If you always include the semver of the new
# version in your commit message when you bump versions then you can
# omit this.
diff-search: true
file-name: "${{ env.VERSION_FILE_NAME }}"

# Add support for more platforms with QEMU (optional)
# https://github.com/docker/setup-qemu-action
- name: Setup up QEMU
if: steps.version-check.outputs.changed == 'true'
uses: docker/setup-qemu-action@v3

- name: Set up Docker Buildx
if: steps.version-check.outputs.changed == 'true'
uses: docker/setup-buildx-action@v1
uses: docker/setup-buildx-action@v3

- name: Cache Docker layers
if: steps.version-check.outputs.changed == 'true'
uses: actions/cache@v2
uses: actions/cache@v4
with:
key: ${{ runner.os }}-buildx-${{ github.sha }}
path: /tmp/.buildx-cache
Expand All @@ -55,15 +72,23 @@ jobs:

- name: Login to DockerHub
if: steps.version-check.outputs.changed == 'true'
uses: docker/login-action@v1
uses: docker/login-action@v3
with:
password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }}
username: ${{ secrets.DOCKER_HUB_USERNAME }}

- name: Build Docker image
if: steps.version-check.outputs.changed == 'true'
uses: docker/build-push-action@v2
uses: docker/build-push-action@v6
with:
# TO_DO: Xavier - yarn build fails for linux/amd64
platforms: linux/arm64
build-args: |
NEXT_PUBLIC_APP_URL=${{ env.NEXT_PUBLIC_APP_URL }}
NEXT_PUBLIC_APP_API_BASE_URL=${{ env.NEXT_PUBLIC_APP_API_BASE_URL }}
NEXT_PUBLIC_APP_MAP_URL=${{ env.NEXT_PUBLIC_APP_MAP_URL }}
GOOGLE_ANALYTICS_ID=${{ secrets.SENSORS_AFRICA_GA_ANALYTICS_ID }}
API_TOKEN=${{ secrets.SENSORS_AFRICA_API_TOKEN }}
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache-new
context: .
Expand All @@ -78,9 +103,8 @@ jobs:

- name: Push to Dokku
if: steps.version-check.outputs.changed == 'true'
uses: dokku/github-action@v1.0.2
uses: dokku/github-action@v1.6.1
with:
branch: ${{ env.DOKKU_REMOTE_BRANCH }}
ssh_private_key: ${{ secrets.SSH_PRIVATE_KEY }}
git_push_flags: ${{ env.GIT_PUSH_FLAGS }}
git_remote_url: ${{ env.DOKKU_REMOTE_URL }}
ssh_private_key: ${{ secrets.SSH_PRIVATE_KEY }}
deploy_docker_image: ${{ env.IMAGE_NAME }}:${{ steps.version-check.outputs.version }}
22 changes: 16 additions & 6 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@ ARG \
# Next.js collects completely anonymous telemetry data about general usage.
# Learn more here: https://nextjs.org/telemetry
NEXT_TELEMETRY_DISABLED=1

# ============================================================================
# Node
# ============================================================================

FROM node:20.14-alpine as node
FROM node:20.14-alpine AS node

# Always install security updated e.g. https://pythonspeed.com/articles/security-updates-in-docker/
# Update local cache so that other stages don't need to update cache
Expand All @@ -19,7 +18,7 @@ RUN apk update \
# Node
# ============================================================================
#
FROM node as deps
FROM node AS deps
# Check https://github.com/nodejs/docker-node/tree/b4117f9333da4138b03a546ec926ef50a31506c3#nodealpine to understand why libc6-compat might be needed.
RUN apk add --no-cache libc6-compat
WORKDIR /app
Expand All @@ -36,8 +35,19 @@ WORKDIR /app
COPY --from=deps /app/node_modules ./node_modules
COPY . .

ARG NEXT_TELEMETRY_DISABLED
ENV NEXT_TELEMETRY_DISABLED=${NEXT_TELEMETRY_DISABLED}
ARG NEXT_TELEMETRY_DISABLED\
NEXT_PUBLIC_APP_URL \
NEXT_PUBLIC_APP_API_BASE_URL \
NEXT_PUBLIC_APP_MAP_URL \
GOOGLE_ANALYTICS_ID \
API_TOKEN

ENV NEXT_TELEMETRY_DISABLED=${NEXT_TELEMETRY_DISABLED}\
NEXT_PUBLIC_APP_URL=${NEXT_PUBLIC_APP_URL} \
NEXT_PUBLIC_APP_API_BASE_URL=${NEXT_PUBLIC_APP_API_BASE_URL} \
NEXT_PUBLIC_APP_MAP_URL=${NEXT_PUBLIC_APP_MAP_URL} \
GOOGLE_ANALYTICS_ID=${GOOGLE_ANALYTICS_ID} \
API_TOKEN=${API_TOKEN}

RUN yarn build

Expand Down Expand Up @@ -67,7 +77,7 @@ RUN set -ex \

COPY --from=builder /app/public ./public

# Automatically leverage output traces to reduce image size
# Automatically leverage output traces to reduce image size
# https://nextjs.org/docs/advanced-features/output-file-tracing
COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./
COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "sensors.africa",
"description": "sensors.AFRICA",
"version": "0.4.26",
"version": "0.4.31",
"private": true,
"main": "index.js",
"homepage": "https://sensors.africa/",
Expand Down
Loading
Loading