从alpine构建预装vcpkg的docker image用于gitea actions CI

动机

想要构建一个基于vcpkg的交叉编译容器平台用于cpp项目的CI(自动集成),此处仅提供最基础的image,amd64的机子上构建完成后大小为533兆(着实不小😓),各位看官可以在此基础上自行构建需要的版本。

hello world效果展示


corss_compiler.dockerfile

bash 复制代码
FROM alpine:latest
RUN apk update && apk upgrade
RUN apk add --no-cache build-base
RUN apk add --no-cache cmake
RUN apk add --no-cache wget
RUN apk add --no-cache zip
RUN apk add --no-cache unzip
RUN apk add --no-cache curl
RUN apk add --no-cache git
RUN apk add --no-cache nodejs
RUN apk add --no-cache re2c
RUN apk add --no-cache pkgconf
# 安装ninja-1.10.2 apk安装的固定为1.9版本 但vcpkg需要版本>=1.10.2,所以从源码来安装
# 种种原因如果wget下载失败就下载好了再拷贝进来
RUN cd /home && wget https://github.com/ninja-build/ninja/archive/refs/tags/v1.10.2.tar.gz -o ninja-1.10.2.tar.gz
# COPY ninja-1.10.2.tar.gz /home
RUN cd /home && tar -axvf ninja-1.10.2.tar.gz && rm ninja-1.10.2.tar.gz
RUN cd /home && cd ninja-1.10.2 && mkdir build && cd build && cmake .. && cmake --build . && make && make install
RUN cd /home && rm -r ninja-1.10.2
# 这一步执行时间较长失败请重试,请务必完全克隆vcpkg仓库,因为vcpkg的基线管理是基于git commit的sha码的详情请看vcpkg的相关文档,如果想要每次使用最新的版本不锁定库的版本,请每次执行工作流的时候使用git pull拉取最新的vcpkg
RUN cd /home && git clone https://github.com/microsoft/vcpkg.git && cd vcpkg && sh bootstrap-vcpkg.sh
# 设置VCPKG_ROOT 环境变量,项目中的cmake脚本中使用该变量即可找到vcpkg的安装位置
ENV VCPKG_ROOT /home/vcpkg
# 此处之后可以预先下载编译一些库用于离线状态下的安装并加可以快工作流的速度
RUN cd /home/vcpkg && ./vcpkg install gtest:x64-linux

写好dockerfile后执行构建镜像,有代理的话使用代理可以更快完成

复制代码
docker build . \
 -f corss_compiler.dockerfile \
 -t alpine-cross \
 --build-arg HTTP_PROXY=$HTTP_PROXY
 --build-arg HTTPs_PROXY=$HTTPS_PROXY

工作流

测试的工作流供参考,此处就不贴被测源码了

yaml 复制代码
name: Gitea Actions Demo2
run-name: ${{ github.actor }} is testing out Gitea Actions 🚀
on: [push]
jobs:
  Explore-Gitea-Actions2:
    runs-on: ubuntu-latest
    container:
      image: alpine-cross:latest
    steps:
      - run: echo "🎉 The job was automatically triggered by a ${{ github.event_name }} event."
      - run: echo "🐧 This job is now running on a ${{ runner.os }} server hosted by Gitea!"
      - run: echo "🔎 The name of your branch is ${{ github.ref }} and your repository is ${{ github.repository }}."
      - name: Check out repository code
        env:
          GITHUB_TOKEN: ${{ github.token }}
        run: |
          git clone --depth=1 http://$GITHUB_TOKEN@192.168.1.100:3000/xxxxx/cpp_proj_template.git
          cd cpp_proj_template/unittest
          sh test4x64_g++_linux_release.sh
相关推荐
p***q783 分钟前
springboot整合libreoffice(两种方式,使用本地和远程的libreoffice);docker中同时部署应用和libreoffice
spring boot·后端·docker
de之梦-御风21 分钟前
【远程控制】RustDesk 自建服务端完整方案(Docker + Windows 客户端)
windows·docker·容器
de之梦-御风25 分钟前
【远程控制】开箱即用的 RustDesk 自建服务端完整 Docker Compose 模板
运维·docker·容器
意疏1 小时前
openGauss 数据库快速上手评测:从 Docker 安装到SQL 实战
数据库·sql·docker
y***13641 小时前
docker离线安装及部署各类中间件(x86系统架构)
docker·中间件·系统架构
努力也学不会java1 小时前
【docker】Docker Register(镜像仓库)
运维·人工智能·机器学习·docker·容器
roman_日积跬步-终至千里1 小时前
【Starrocks】以库为单位StarRocks数据迁移实战
docker
青啊青斯2 小时前
Dify Docker部署
运维·docker·容器·dify
胡萝卜的兔2 小时前
ci/cd自动化部署
运维·ci/cd·自动化
saber_andlibert2 小时前
【docker】入门基础和镜像、容器
linux·运维·docker·容器