# Copyright 2023 PingCAP, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

FROM hub.pingcap.net/wangweizhen/base_image:go12320241009
ENV GOPATH /go
ENV GOROOT /usr/local/go
ENV PATH $GOPATH/bin:$GOROOT/bin:$PATH
USER root
WORKDIR /root
COPY .ci_bazel /data/bazel
# create user jenkins and add it to sudoers.
RUN --mount=type=cache,target=/var/cache/dnf \
    dnf install -y sudo
RUN groupadd -g 1000 jenkins && \
    useradd -u 1000 -g 1000 -m -s /bin/bash jenkins && \
    echo "jenkins:password" | chpasswd && \
    echo "jenkins ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers
RUN mkdir -p /data/tikv1 /data/tikv2 /data/tikv3 /data/pd && \
    mkdir /go && chown jenkins:jenkins /go && \
    chown -R jenkins:jenkins /data && \
    chown jenkins:jenkins /usr/bin/bazel
# Switch to the non-root user jenkins and set the working directory
USER jenkins
WORKDIR /home/jenkins
RUN go install github.com/hawkingrei/bazel_collect@latest && \
    go install github.com/bazelbuild/bazel-gazelle/cmd/gazelle@latest
