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

动机

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

hello world效果展示

在这里插入图片描述
在这里插入图片描述

corss_compiler.dockerfile

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

工作流

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

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
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值