Skip to content

Commit

Permalink
Merge pull request #1 from christopherime/main
Browse files Browse the repository at this point in the history
Dockerfile image size optimisation
  • Loading branch information
fnzv authored Dec 13, 2023
2 parents 945ddf3 + 834ec75 commit 4575bf7
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 6 deletions.
29 changes: 29 additions & 0 deletions .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: "CodeQL"
on:
push:
branches: [ master ]
jobs:
analyze:
name: Analyze
runs-on: ubuntu-latest
permissions:
actions: read
contents: read
security-events: write
strategy:
fail-fast: false
matrix:
language: [ 'go' ]
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Initialize CodeQL
uses: github/codeql-action/init@v2
with:
languages: ${{ matrix.language }}
- name: Autobuild
uses: github/codeql-action/autobuild@v2
- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v2
with:
category: "/language:${{matrix.language}}"
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# Ignore text editor files
.vscode
.idea

# If you prefer the allow list template instead of the deny list, see community template:
# https://github.com/github/gitignore/blob/main/community/Golang/Go.AllowList.gitignore
#
Expand Down
25 changes: 19 additions & 6 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,11 +1,24 @@
FROM golang:1.21.1
FROM golang:1.21-alpine AS builder

RUN mkdir -p /app
ARG ARCH=amd64

WORKDIR /app
ENV GOROOT /usr/local/go
ENV GOPATH /go
ENV PATH $GOPATH/bin:$GOROOT/bin:$PATH
ENV GO_VERSION 1.21
ENV GO111MODULE on
ENV CGO_ENABLED=0

ADD . /app
# Build dependencies
WORKDIR /go/src/
COPY . .
RUN apk update && apk add make git
RUN go get .
RUN mkdir /go/src/build
RUN go build -a -gcflags=all="-l -B" -ldflags="-w -s" -o build/p2c .

RUN go build ./p2c.go
# Second stage
FROM alpine:3.19

CMD ["./p2c"]
COPY --from=builder /go/src/build/p2c /usr/local/bin/p2c
CMD ["/usr/local/bin/p2c"]

0 comments on commit 4575bf7

Please sign in to comment.