gpt4 book ai didi

github-actions - GitHub Action : How do I run commands inside a docker container

转载 作者:行者123 更新时间:2023-12-03 13:44:00 25 4
gpt4 key购买 nike

今天才刚刚开始学习CI/CD。不知道今天以前 docker 是什么。我可以通过Unity项目使CD在CircleCI上工作。所有的运行命令都在docker容器内发生。

version: 2.1
executors:
unity:
docker:
# https://hub.docker.com/r/gableroux/unity3d/tags
- image: gableroux/unity3d:2018.2.21f1
jobs:
build-test:
executor: unity
steps:
- checkout

# Install zip
- run: apt-get update
- run: apt-get install zip -y

# Decrypt the license file
- run: openssl aes-256-cbc -d -in .circleci/Unity_v2018.x.ulf.enc -k ${UNITY_LICENSE_DECRYPT_KEY} >> .circleci/Unity_v2018.x.ulf

# Activate unity
- run: /opt/Unity/Editor/Unity -quit -batchmode -nographics -silent-crashes -logFile -manualLicenseFile .circleci/Unity_v2018.x.ulf || exit 0

# Build Windows and OSX
- run: /opt/Unity/Editor/Unity -quit -batchmode -nographics -silent-crashes -noUpm -logFile -projectPath . -buildWindows64Player ./bin-win64/CISample.exe
- run: /opt/Unity/Editor/Unity -quit -batchmode -nographics -silent-crashes -noUpm -logFile -projectPath . -buildOSXUniversalPlayer ./bin-osx/CISample.app

# Zip builds
- run: zip -r CISampleWin64Binary.zip ./bin-win64
- run: zip -r CISampleOSXBinary.zip ./bin-osx

# Store builds
- store_artifacts:
path: ./CISampleWin64Binary.zip
- store_artifacts:
path: ./CISampleOSXBinary.zip

workflows:
version: 2
build:
jobs:
- build-test

无法弄清楚如何使用GitHub Actions做到这一点。我可以运行docker镜像,但无法弄清楚如何在其中运行命令。我所有的命令都在Ubuntu VM级别上运行。我的测试是运行 ls命令以查看它是否正在从不是的docker容器中运行。

这是我尝试过的一些方法。
name: CI
on: [push]
jobs:
build:
runs-on: ubuntu-latest
steps:
- run: |
docker run gableroux/unity3d:2018.2.21f1 bash
ls
name: CI
on: [push]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: docker://gableroux/unity3d:2018.2.21f1
- run: ls

最佳答案

弄清楚了。您可以为作业指定container。我的整个工作流程如下所示:

name: CI
on: [push]
jobs:
build:
runs-on: ubuntu-latest
container: gableroux/unity3d:2018.2.21f1
steps:
- name: Checkout Project
uses: actions/checkout@v1

- name: Intall Zip
run: |
apt-get update
apt-get install zip -y

- name: Decrypt the license file
run: openssl aes-256-cbc -d -in .github/Unity_v2018.x.ulf.enc -k ${{ secrets.UNITY_LICENSE_DECRYPT_KEY }} >> .github/Unity_v2018.x.ulf

# Activate unity
- name: Activate Unity
run: /opt/Unity/Editor/Unity -quit -batchmode -nographics -silent-crashes -logFile -manualLicenseFile .github/Unity_v2018.x.ulf || exit 0

# Build Windows and OSX
- name: Build Windows Player
run: /opt/Unity/Editor/Unity -quit -batchmode -nographics -silent-crashes -noUpm -logFile -projectPath . -buildWindows64Player ./bin-win64/CISample.exe
- name: Build OSX Player
run: /opt/Unity/Editor/Unity -quit -batchmode -nographics -silent-crashes -noUpm -logFile -projectPath . -buildOSXUniversalPlayer ./bin-osx/CISample.app

- name: Zip Builds
run: |
zip -r CISampleWin64Binary.zip ./bin-win64
zip -r CISampleOSXBinary.zip ./bin-osx

- name: Archive Windows Build
uses: actions/upload-artifact@v1
with:
name: CISampleWin64Binary
path: ./CISampleWin64Binary.zip

- name: Archive Mac Build
uses: actions/upload-artifact@v1
with:
name: CISampleOSXBinary
path: ./CISampleOSXBinary.zip

关于github-actions - GitHub Action : How do I run commands inside a docker container,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58930529/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com