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

ci: publish docker image on release #561

Merged
merged 1 commit into from
Mar 19, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 3 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
node_modules
dist
.github
22 changes: 22 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ on:
branches:
- next

env:
REGISTRY: ghcr.io
IMAGE_NAME: geostyler/geostyler-demo

jobs:
release:
name: Release
Expand All @@ -31,3 +35,21 @@ jobs:
env:
GITHUB_TOKEN: ${{ secrets.GH_RELEASE_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}

- name: Log in to the Container registry
if: steps.semantic.outputs.new_release_published == 'true'
uses: docker/login-action@3b8fed7e4b60203b2aa0ecc6c6d6d91d12c06760
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Build and push Docker image
if: steps.semantic.outputs.new_release_published == 'true'
uses: docker/build-push-action@4f58ea79222b3b9dc2c8bbdd6debcef730109a75
with:
context: .
push: true
tags: |
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.semantic.outputs.new_release_version }}
19 changes: 19 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
FROM node:20-alpine3.21 AS builder

WORKDIR /app

COPY package.json package-lock.json ./

RUN npm ci

COPY . .

RUN npm run build-docker

############

FROM nginx:1.27.4-alpine AS runner

COPY --from=builder /app/dist /usr/share/nginx/html

EXPOSE 80
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@
},
"scripts": {
"start": "vite",
"build": "vite build && copyfiles \"./public/**/*.png\" dist --up 1 && copyfiles \"./public/**/*.json\" dist --up 1"
"build": "vite build && copyfiles \"./public/**/*.png\" dist --up 1 && copyfiles \"./public/**/*.json\" dist --up 1",
"build-docker": "vite build --config vite.config.docker.ts && copyfiles \"./public/**/*.png\" dist --up 1 && copyfiles \"./public/**/*.json\" dist --up 1"
},
"eslintConfig": {
"extends": "react-app"
Expand Down
23 changes: 23 additions & 0 deletions vite.config.docker.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { defineConfig } from 'vite';
import react from '@vitejs/plugin-react';
import VitePluginMetaEnv from 'vite-plugin-meta-env';
import packageLockJson from './package-lock.json';

const metaEnv = {
GEOSTYLER_VERSION: packageLockJson.packages['node_modules/geostyler'].version
};

// https://vitejs.dev/config/
export default defineConfig({
plugins: [
react(),
VitePluginMetaEnv(metaEnv, 'import.meta.env'),
],
base: '/',
server: {
host: '0.0.0.0',
},
define: {
global: {},
},
});