Skip to content

Commit

Permalink
Multi-arch docker image support (#124)
Browse files Browse the repository at this point in the history
* chore: Update Docker multi-arch build workflow

* chore: Clean up old Docker images in multi-arch build workflow

* Switched to use single Dockerfile configured for multi-arch

* Revert "Switched to use single Dockerfile configured for multi-arch"

* chore: Update readme with new instructions for cpu arch, remove Dockerfile 
due to migration to individual dockerfiles per arch

* fix: incorrect location of arch message
  • Loading branch information
Codycody31 authored Aug 10, 2024
1 parent 9ac7460 commit 844d154
Show file tree
Hide file tree
Showing 4 changed files with 113 additions and 8 deletions.
41 changes: 40 additions & 1 deletion .github/workflows/docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,49 @@ jobs:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Build and push Docker image
- name: Build and push Docker image for ARM64
uses: docker/build-push-action@v5
with:
platforms: linux/arm64
push: true
file: docker/Dockerfile.arm64
tags: |
discuit/discuit:${{ github.sha }}-arm64
- name: Build and push Docker image for AMD64
uses: docker/build-push-action@v5
with:
platforms: linux/amd64
push: true
file: docker/Dockerfile.amd64
tags: |
discuit/discuit:${{ github.sha }}-amd64
- name: Create and push Docker manifest
uses: int128/docker-manifest-create-action@v2
with:
tags: |
discuit/discuit:latest
discuit/discuit:${{ github.sha }}
sources: |
discuit/discuit:${{ github.sha }}-arm64
discuit/discuit:${{ github.sha }}-amd64
- name: Authenticate and obtain Docker Hub JWT token (for cleanup)
id: get_token
run: |
TOKEN=$(curl -s -H "Content-Type: application/json" \
-X POST -d '{"username": "${{ secrets.DOCKERHUB_USERNAME }}", "password": "${{ secrets.DOCKERHUB_TOKEN }}"}' \
https://hub.docker.com/v2/users/login/ | jq -r .token)
echo "::add-mask::$TOKEN" # Mask the token in the logs
echo "TOKEN=$TOKEN" >> $GITHUB_ENV
env:
DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }}
DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Clean up old images
env:
TOKEN: ${{ env.TOKEN }}
run: |
curl -s -H "Authorization: JWT $TOKEN" -X DELETE "https://hub.docker.com/v2/repositories/discuit/discuit/tags/${{ github.sha }}-arm64/"
curl -s -H "Authorization: JWT $TOKEN" -X DELETE "https://hub.docker.com/v2/repositories/discuit/discuit/tags/${{ github.sha }}-amd64/"
16 changes: 9 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,17 +90,19 @@ Note: Do not install the discuit binary using go install or move it somewhere el
1. **Build the Docker Image**
```shell
docker build -t discuit .
```
> **Note**: If you need to run discuit on a different architecture, simply change the Dockerfile in the `-f` flag to the appropriate Dockerfile for your architecture, currently we support `linux/amd64` (docker/Dockerfile.amd64), and `linux/arm64` (docker/Dockerfile.arm64).
```shell
docker build -t discuit -f docker/Dockerfile.amd64 .
```
2. **Run the Docker Container**
> **Note**: The following command while having a persistent database, the included config.yaml file is not. You will need to mount the file to the container if you want to persist the configuration.
> **Note**: The following command while having a persistent database, the included config.yaml file is not. You will need to mount the file to the container if you want to persist the configuration.
```shell
docker run -d --name discuit -v discuit-db:/var/lib/mysql -v discuit-redis:/var/lib/redis -v discuit-images:/app/images -p 8080:80 discuit
```
```shell
docker run -d --name discuit -v discuit-db:/var/lib/mysql -v discuit-redis:/var/lib/redis -v discuit-images:/app/images -p 8080:80 discuit
```
3. **Accessing Discuit**: After the container starts, you can access Discuit by navigating to `http://localhost:8080` on your web browser, or to the specific port if you customized the port mapping.
Expand Down
File renamed without changes.
64 changes: 64 additions & 0 deletions docker/Dockerfile.arm64
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# Use official Go image for the backend build
FROM golang:1.21 AS backend-builder

# Install runtime dependencies (libvips)
RUN apt-get update && apt-get install -y --no-install-recommends \
libvips-dev && \
libvips=8.8.4 && \
apt-get clean && \
rm -rf /var/lib/apt/lists/*

# Set the environment variables for the build
ENV GOOS=linux
ENV GOARCH=arm64

# Copy the source code and build the backend
WORKDIR /app
COPY go.* ./
RUN go mod download
COPY . .
RUN go build -ldflags "-s -w" -o discuit .

# Use official Node image for the frontend build
FROM node:18 AS frontend-builder

# Copy required configuration files and build files
WORKDIR /app
COPY config.default.yaml .
RUN mv config.default.yaml config.yaml
COPY --from=backend-builder /app/discuit /app/discuit

# Copy the source code and build the frontend
WORKDIR /app/ui
COPY ui/package*.json ./
RUN npm ci
COPY ui/ .

# Final stage: setup the runtime environment
FROM node:18
# Avoid prompts from the package manager during build
ENV DEBIAN_FRONTEND=noninteractive

# Install runtime dependencies
RUN apt-get update && apt-get install -y --no-install-recommends \
mariadb-server \
redis-server \
libvips-dev && \
libvips=8.8.4 && \
apt-get clean && \
rm -rf /var/lib/apt/lists/*

# Copy built artifacts from previous stages
COPY --from=frontend-builder /app/ui /app/ui
COPY --from=backend-builder /app/discuit /app/discuit
COPY config.default.yaml /app/config.yaml
COPY migrations /app/migrations
COPY docker/entrypoint.sh /entrypoint.sh
RUN chmod +x /entrypoint.sh

WORKDIR /app

# Setup the environment and ports
EXPOSE 80
ENTRYPOINT ["/entrypoint.sh"]
CMD ["/app/discuit", "serve"]

0 comments on commit 844d154

Please sign in to comment.