diff --git a/.dockerignore b/.dockerignore index fa33e64..de898e5 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,24 +1,9 @@ -# IDE folders -.idea/ -.vscode/ -./src-ui/.vscode -# OS turds -.DS_Store -# VCS -.git -.github -# App files -*.http -*.sql -.env -.env.example -.gitignore -app.json -flake.lock -flake.nix -fly.toml -http-client.private.env.json -LICENSE -Procfile -README.md -docker-compose.yml +* +!bot/ +!logger/ +!model/ +!plugin/ +!utils/ +!go.mod +!go.sum +!main.go diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index d1f3d9e..b9c9591 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -13,8 +13,8 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - GOOS: [ windows, linux ] - GOARCH: [ amd64, arm ] + GOOS: [windows, linux] + GOARCH: [amd64, arm] exclude: - GOOS: windows GOARCH: arm @@ -55,3 +55,35 @@ jobs: path: dist/* retention-days: 90 + docker: + name: docker + runs-on: ubuntu-latest + permissions: + packages: write + contents: read + + steps: + - uses: actions/checkout@v4 + + - name: Build image + run: docker build . --file Dockerfile --tag $NAME --label "runnumber=${GITHUB_RUN_ID}" + + - name: Log in to registry + run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u $ --password-stdin + + - name: Push image + run: | + IMAGE_ID=ghcr.io/${{ github.repository_owner }}/$NAME + + # This changes all uppercase characters to lowercase. + IMAGE_ID=$(echo $IMAGE_ID | tr '[A-Z]' '[a-z]') + # This strips the git ref prefix from the version. + VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,') + # This strips the "v" prefix from the tag name. + [[ "${{ github.ref }}" == "refs/tags/"* ]] && VERSION=$(echo $VERSION | sed -e 's/^v//') + # This uses the Docker `latest` tag convention. + [ "$VERSION" == "master" ] && VERSION=latest + echo IMAGE_ID=$IMAGE_ID + echo VERSION=$VERSION + docker tag $NAME $IMAGE_ID:$VERSION + docker push $IMAGE_ID:$VERSION diff --git a/Dockerfile b/Dockerfile index af3ee24..5fc993e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -5,8 +5,8 @@ RUN go mod download COPY . ./ RUN CGO_ENABLED=0 GOOS=linux go build -o /gobot -FROM gcr.io/distroless/base-debian12 AS release-stage -WORKDIR /gobot -COPY --from=build-stage /gobot /gobot/gobot +FROM gcr.io/distroless/static-debian12 AS release-stage +WORKDIR /app +COPY --from=build-stage /gobot /app/gobot USER nonroot:nonroot -ENTRYPOINT ["/gobot/gobot"] +ENTRYPOINT ["/app/gobot"] diff --git a/docker-compose.yml b/docker-compose.yml index f7d4042..f90c79a 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -3,7 +3,9 @@ version: '3.8' name: gobot services: bot: - build: . + # build: . + pull_policy: always + image: ghcr.io/brawl345/gobot:latest restart: always user: '${DOCKER_UID}:${DOCKER_GID}' env_file: .env