Skip to content

Commit

Permalink
fix #21 (#24)
Browse files Browse the repository at this point in the history
  • Loading branch information
felix-schott authored Oct 22, 2024
1 parent e81803e commit fd6335d
Show file tree
Hide file tree
Showing 6 changed files with 5 additions and 21 deletions.
2 changes: 0 additions & 2 deletions .github/workflows/build-docker-backend.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,6 @@ jobs:
context: ./backend
build-args: |
GO_VERSION=${{ env.GO_VERSION }}
USER=${{ secrets.USER }}
UID=${{ secrets.UID }}
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
Expand Down
10 changes: 0 additions & 10 deletions backend/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,12 @@ ARG GO_VERSION

FROM golang:$GO_VERSION AS builder

ARG USER
ARG UID

# Add a work directory
WORKDIR /app
# Cache and install dependencies
COPY go.mod go.sum ./
RUN go mod download

# create user - choose UID of host machine user that you want files to be owned by
RUN adduser $USER --no-create-home --disabled-password --disabled-login --uid $UID --quiet

# Copy app files
COPY . .
# Build app
Expand All @@ -29,15 +23,11 @@ RUN make bin/server && make bin/healthcheck

FROM scratch AS production

ARG USER

# Copy built binary from builder
COPY --from=builder /app/bin/server /bin/server
COPY --from=builder /app/bin/healthcheck /bin/healthcheck
COPY --from=builder /etc/passwd /etc/passwd

USER $USER

# Expose port
EXPOSE 80

Expand Down
8 changes: 1 addition & 7 deletions backend/Dockerfile.dev
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,17 @@ ARG GO_VERSION

FROM golang:$GO_VERSION AS development

ARG USER
ARG UID

# Add a work directory
WORKDIR /app
# Cache and install dependencies
COPY go.mod go.sum ./
RUN go mod download

# create user
RUN adduser $USER --no-create-home --disabled-password --disabled-login --uid $UID

# Copy app files
COPY . .

# install air for hot reload
RUN make bin/healthcheck && go install github.com/air-verse/air@latest
RUN go install github.com/air-verse/air@latest
# Expose port
EXPOSE 80

Expand Down
2 changes: 2 additions & 0 deletions deploy/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ First, make sure there is a .env file present in $directory that contains the fo
- READ_ONLY_PASSWORD (password for read-only db user)
- READ_WRITE_PASSWORD (password for rw db user)
- POSTGRES_DB (name of the database)
- PROD_UID (host uid that you want files in volumes to be owned by)
- PROD_GID (group id of image user)
If you wish, you can modify the docker-compose.yml file according to your needs. Note that running the default docker-compose won't work
if you're not the project owner, and you will have to build your own production docker images.
Expand Down
1 change: 1 addition & 0 deletions deploy/prod.docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ services:

prod_api:
image: ghcr.io/felix-schott/jamsessions-server:latest
user: $PROD_UID:$PROD_GID
container_name: jamsessions_prod_api
volumes:
- "$PWD/migrations:/app/migrations"
Expand Down
3 changes: 1 addition & 2 deletions dev.docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,8 @@ services:
dockerfile: Dockerfile.dev
args:
GO_VERSION: 1.23
USER: $DEV_USER
UID: $DEV_UID
image: jamsessions_dev_api
user: $DEV_UID:$DEV_GID
container_name: jamsessions_dev_api
volumes:
- "./backend:/app"
Expand Down

0 comments on commit fd6335d

Please sign in to comment.