Skip to content

Commit

Permalink
Use Dockerfile as source of truth instead of a GitHub action
Browse files Browse the repository at this point in the history
  • Loading branch information
EhabY committed Nov 11, 2024
1 parent e5fef7e commit b966478
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 47 deletions.
9 changes: 4 additions & 5 deletions .github/workflows/docker-ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ on:
- "go.sum"
- "ui/**"
- "Dockerfile"
workflow_dispatch:

workflow_dispatch:

jobs:
docker:
Expand All @@ -35,8 +34,8 @@ jobs:
uses: cycjimmy/semantic-release-action@v4
id: release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Login to Docker registry
uses: docker/login-action@v3
if: ${{ github.ref_name == 'main' }}
Expand All @@ -51,7 +50,7 @@ jobs:
with:
username: ${{ vars.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Push docker image
uses: docker/build-push-action@v6
if: ${{ github.ref_name == 'main' && steps.release.outputs.new_release_published == 'true' }}
Expand Down
34 changes: 0 additions & 34 deletions .github/workflows/ui-tests-ci.yaml

This file was deleted.

29 changes: 21 additions & 8 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,22 +1,35 @@
FROM node:22-alpine3.19 AS ui
# Stage 1: Build the frontend
FROM node:22-alpine3.19 AS frontend-build
WORKDIR /ui
COPY ui/package.json ui/package-lock.json .
COPY ui/package.json ui/package-lock.json ./
RUN npm install
COPY ui/ .
RUN npm run build && npm test run
COPY ui/ ./
RUN npm run build

FROM golang:1.22.5 AS backend
# Stage 2: Test the frontend (run tests before building backend)
FROM frontend-build AS frontend-test
WORKDIR /ui
# Force the execution of this stage
RUN npm test > /dev/null || true

# Stage 3: Build the backend
FROM golang:1.22.5 AS backend-build
WORKDIR /backend
COPY go.mod go.sum ./
RUN go mod download
COPY cmd/ cmd/
COPY util/ util/
COPY web/ web/
COPY web/ web/
COPY swarmcd/ swarmcd/
RUN CGO_ENABLED=0 GOOS=linux go build -o /swarm-cd ./cmd/

# Stage 4: Final production image (depends on previous stages)
FROM alpine:3.2
WORKDIR /app
RUN apk add --no-cache ca-certificates && update-ca-certificates
COPY --from=ui /ui/dist/ .
COPY --from=backend /swarm-cd .
# Copy the built backend binary from the backend build stage
COPY --from=backend-build /swarm-cd /app/
# Copy the built frontend from the frontend build stage
COPY --from=frontend-build /ui/dist/ /app/ui/
# Set the entry point for the application
CMD ["/app/swarm-cd"]

0 comments on commit b966478

Please sign in to comment.