diff --git a/.gitea/workflows/build.yml b/.gitea/workflows/build.yml index e007824..6c018db 100644 --- a/.gitea/workflows/build.yml +++ b/.gitea/workflows/build.yml @@ -8,6 +8,7 @@ on: env: REGISTRY: git.sebse.de IMAGE: git.sebse.de/sebse/factorio-signal-exporter + IMAGE_MIGRATE: git.sebse.de/sebse/factorio-signal-exporter-migrate jobs: build: @@ -27,7 +28,7 @@ jobs: username: ${{ secrets.REGISTRY_USERNAME }} password: ${{ secrets.REGISTRY_TOKEN }} - - name: Extract metadata + - name: Extract metadata (app) id: meta uses: docker/metadata-action@v5 with: @@ -36,7 +37,7 @@ jobs: type=sha,prefix=,format=short type=raw,value=latest - - name: Build and push + - name: Build and push app uses: docker/build-push-action@v5 with: context: ./web @@ -46,18 +47,58 @@ jobs: cache-from: type=registry,ref=${{ env.IMAGE }}:latest cache-to: type=inline - - name: Package Helm chart + - name: Extract metadata (migrate) + id: meta-migrate + uses: docker/metadata-action@v5 + with: + images: ${{ env.IMAGE_MIGRATE }} + tags: | + type=sha,prefix=,format=short + type=raw,value=latest + + - name: Build and push migrate + uses: docker/build-push-action@v5 + with: + context: ./web + file: ./web/Dockerfile.migrate + push: true + tags: ${{ steps.meta-migrate.outputs.tags }} + labels: ${{ steps.meta-migrate.outputs.labels }} + cache-from: type=registry,ref=${{ env.IMAGE_MIGRATE }}:latest + cache-to: type=inline + + - name: Inject image tags into chart values + run: | + SHORT_SHA=$(echo "${{ github.sha }}" | cut -c1-7) + sed -i "s|^\(\s*tag:\).*|\1 ${SHORT_SHA}|" web/charts/factorio-signal-exporter/values.yaml + + - name: Package Helm chart (SHA) run: | SHORT_SHA=$(echo "${{ github.sha }}" | cut -c1-7) helm package web/charts/factorio-signal-exporter \ --version "0.0.0-${SHORT_SHA}" \ --app-version "${SHORT_SHA}" - - name: Push Helm chart to Gitea + - name: Push Helm chart (SHA) to Gitea run: | SHORT_SHA=$(echo "${{ github.sha }}" | cut -c1-7) curl -u ${{ secrets.REGISTRY_USERNAME }}:${{ secrets.REGISTRY_TOKEN }} \ -X POST \ https://${{ env.REGISTRY }}/api/packages/sebse/helm/api/charts \ -F "chart=@factorio-signal-exporter-0.0.0-${SHORT_SHA}.tgz" \ + --fail-with-body + + - name: Package Helm chart (latest) + run: | + SHORT_SHA=$(echo "${{ github.sha }}" | cut -c1-7) + helm package web/charts/factorio-signal-exporter \ + --version "0.0.0-latest" \ + --app-version "${SHORT_SHA}" + + - name: Push Helm chart (latest) to Gitea + run: | + curl -u ${{ secrets.REGISTRY_USERNAME }}:${{ secrets.REGISTRY_TOKEN }} \ + -X POST \ + https://${{ env.REGISTRY }}/api/packages/sebse/helm/api/charts \ + -F "chart=@factorio-signal-exporter-0.0.0-latest.tgz" \ --fail-with-body \ No newline at end of file diff --git a/web/Dockerfile.migrate b/web/Dockerfile.migrate new file mode 100644 index 0000000..f1ad2f2 --- /dev/null +++ b/web/Dockerfile.migrate @@ -0,0 +1,10 @@ +FROM node:24-alpine + +WORKDIR /app + +COPY package.json package-lock.json* ./ +RUN npm ci + +COPY migrations/ ./migrations/ + +CMD ["npm", "run", "migrate"] \ No newline at end of file diff --git a/web/charts/factorio-signal-exporter/templates/deployment.yaml b/web/charts/factorio-signal-exporter/templates/deployment.yaml index 6f64aee..67de2e8 100644 --- a/web/charts/factorio-signal-exporter/templates/deployment.yaml +++ b/web/charts/factorio-signal-exporter/templates/deployment.yaml @@ -21,9 +21,8 @@ spec: {{- end }} initContainers: - name: migrate - image: {{ .Values.image.repository }}:{{ .Values.image.tag }} - imagePullPolicy: {{ .Values.image.pullPolicy }} - command: ["npm", "run", "migrate"] + image: {{ .Values.initImage.repository }}:{{ .Values.initImage.tag }} + imagePullPolicy: {{ .Values.initImage.pullPolicy }} env: - name: DATABASE_URL valueFrom: diff --git a/web/charts/factorio-signal-exporter/values.yaml b/web/charts/factorio-signal-exporter/values.yaml index 6d50edd..84e2154 100644 --- a/web/charts/factorio-signal-exporter/values.yaml +++ b/web/charts/factorio-signal-exporter/values.yaml @@ -1,7 +1,12 @@ image: repository: git.sebse.de/sebse/factorio-signal-exporter tag: latest - pullPolicy: IfNotPresent + pullPolicy: Always + +initImage: + repository: git.sebse.de/sebse/factorio-signal-exporter-migrate + tag: latest + pullPolicy: Always imagePullSecrets: []