-
Notifications
You must be signed in to change notification settings - Fork 10
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
Update Docker setup #23
Merged
jonbarrow
merged 4 commits into
PretendoNetwork:nex-go-rewrite
from
MatthewL246:docker-updates
Jul 1, 2024
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
531d9f8
chore: update Docker setup
MatthewL246 dd3c236
feat: create Docker build and publish action
MatthewL246 d5395eb
chore: separate app_dir and build_string arguments for readability
MatthewL246 4f0c4e7
chore: mkdir and chown on one layer
MatthewL246 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,5 +3,4 @@ | |
build | ||
log | ||
go.work | ||
*.test | ||
go.work.sum | ||
go.work.sum |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
name: Build and Publish Docker Image | ||
|
||
on: | ||
push: | ||
pull_request: | ||
workflow_dispatch: | ||
|
||
jobs: | ||
build-publish: | ||
env: | ||
SHOULD_PUSH_IMAGE: ${{ (github.event_name == 'push' && (github.ref == 'refs/heads/master' || github.ref == 'refs/heads/dev')) || github.event_name == 'workflow_dispatch' }} | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Set up QEMU for Docker | ||
uses: docker/setup-qemu-action@v3 | ||
|
||
- name: Set up Docker Buildx | ||
uses: docker/setup-buildx-action@v3 | ||
|
||
- name: Log into the Docker container registry | ||
if: ${{ env.SHOULD_PUSH_IMAGE == 'true' }} | ||
uses: docker/login-action@v3 | ||
with: | ||
username: ${{ secrets.DOCKER_USERNAME }} | ||
password: ${{ secrets.DOCKER_PASSWORD }} | ||
|
||
- name: Extract Docker metadata | ||
id: meta | ||
uses: docker/metadata-action@v5 | ||
with: | ||
images: ${{ github.repository }} | ||
tags: | | ||
type=raw,value=latest,enable=${{ github.ref == 'refs/heads/master' }} | ||
type=raw,value=edge,enable=${{ github.ref == 'refs/heads/dev' }} | ||
type=sha | ||
|
||
- name: Build and push Docker image | ||
id: build-and-push | ||
uses: docker/build-push-action@v6 | ||
with: | ||
platforms: linux/amd64,linux/arm64 | ||
push: ${{ env.SHOULD_PUSH_IMAGE }} | ||
tags: ${{ steps.meta.outputs.tags }} | ||
labels: ${{ steps.meta.outputs.labels }} | ||
cache-from: type=gha | ||
cache-to: type=gha,mode=max |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,36 @@ | ||
# --- builder --- | ||
FROM golang:1.20.6-alpine3.17 as builder | ||
LABEL stage=builder | ||
RUN apk add git | ||
WORKDIR /build | ||
# syntax=docker/dockerfile:1 | ||
|
||
COPY go.* ./ | ||
RUN go mod download | ||
ARG app_dir="/home/go/app" | ||
|
||
COPY . ./ | ||
ARG BUILD_STRING=pretendo.friends.docker | ||
RUN go build -ldflags "-X 'main.serverBuildString=${BUILD_STRING}'" -v -o server | ||
|
||
# --- runner --- | ||
FROM alpine:3.17 as runner | ||
WORKDIR /build | ||
# * Building the application | ||
FROM golang:1.22-alpine3.20 AS build | ||
ARG app_dir | ||
ARG build_string=pretendo.friends.docker | ||
|
||
COPY --from=builder /build/server /build/ | ||
CMD ["/build/server"] | ||
WORKDIR ${app_dir} | ||
|
||
RUN --mount=type=cache,target=/go/pkg/mod/ \ | ||
--mount=type=bind,source=go.sum,target=go.sum \ | ||
--mount=type=bind,source=go.mod,target=go.mod \ | ||
go mod download -x | ||
|
||
COPY . . | ||
RUN --mount=type=cache,target=/go/pkg/mod/ \ | ||
CGO_ENABLED=0 go build -v -o ${app_dir}/build/server -ldflags "-X 'main.serverBuildString=${build_string}'" | ||
|
||
|
||
# * Running the final application | ||
FROM alpine:3.20 AS final | ||
ARG app_dir | ||
WORKDIR ${app_dir} | ||
|
||
RUN addgroup go && adduser -D -G go go | ||
|
||
RUN mkdir -p ${app_dir}/log && chown go:go ${app_dir}/log | ||
|
||
USER go | ||
|
||
COPY --from=build ${app_dir}/build/server ${app_dir}/server | ||
|
||
CMD [ "./server" ] |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Out of curiosity, what is the build string? Is this a Go/Pretendo thing?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a Pretendo-specific thing. @jonbarrow can explain more accurately about what it does.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@binaryoverload Every game server has 2 servers, the authentication server and the real server (called the "secure server"). The client must first pass through the authentication server before being given the address of the secure server
In the login methods the client uses for the authentication server, the servers build string is sent. It contains information about the server like it's build number, branch, NEX version, etc.
Most games don't care what is set here, but some do scan the build string for relevant data. So it must be set. For example Mario Kart 8 has the following build string
branch:origin/project/nfs build:3_10_26_2006_0