为GitHub Actions创建管道,这是一个很棒的功能。几个问题
1)哪些图像可用于构建?我可以将我的公共Docker Hub映像之一用作基础映像,以便节省安装Linux依赖项和gem的时间吗?
2)如何将MongoDB配置为服务?是否有可用的图像?
下面的main.yaml:
name: CI
on: [pull_request]
jobs:
test:
runs-on: ubuntu-latest
services:
db:
image: postgres:11
ports: ['5432:5432']
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
steps:
- uses: actions/checkout@v1
- name: Setup Ruby
uses: actions/setup-ruby@v1
with:
ruby-version: 2.5.5
- name: Build and run tests
env:
DATABASE_URL: postgres://postgres:@localhost:5432/test
RAILS_MASTER_KEY: ${{ secrets.RAILS_MASTER_KEY }}
run: |
sudo sed -i 's/none/read|write/g' /etc/ImageMagick-6/policy.xml
wget -qO - https://www.mongodb.org/static/pgp/server-3.6.asc | sudo apt-key add -
echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu xenial/mongodb-org/3.6 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.6.list
sudo apt-get update
sudo apt-get install -y mongodb-org mongodb-org-server
sudo systemctl start mongod
sudo apt-get -yqq install libpq-dev
wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
RELEASE=$(lsb_release -cs)
echo "deb http://apt.postgresql.org/pub/repos/apt/ ${RELEASE}"-pgdg main | sudo tee /etc/apt/sources.list.d/pgdg.list
cat /etc/apt/sources.list.d/pgdg.list
sudo apt update
sudo apt -y install postgresql-11
sudo apt-get install build-essential supervisor nodejs libxml2-dev libxslt1-dev tidy ghostscript less ffmpeg imagemagick -y
gem install -N bundler -v 1.17.3
gem install -N nokogiri -- --use-system-libraries
cp vendor/platform/phantomjs-*-linux-x86_64.tar.bz2 /tmp
sudo tar -C /usr/local/bin --strip-components=2 --wildcards -xvjf /tmp/phantomjs-*-linux-x86_64.tar.bz2 phantomjs-*-linux-x86_64/bin/phantomjs
bundle install --jobs 4 --retry 3
RAILS_ENV=test bundle exec rake db:create
bundle exec rspec
答案 0 :(得分:0)
1)哪些图像可用于构建?我可以使用我的公共Docker Hub公用映像之一作为基础映像,这样我就可以省去安装linux依赖项和gems了吗?
是的!像这样在关键字第一步中使用 uses 来随意使用图片,
- uses: docker://{host}/{image}:{tag}
2)如何将MongoDB配置为服务?是否有可用的图像?
您可以这样做:
services:
mongodb:
image: mongo:3.4.23
ports:
- 27017:27017
此外,还有an article关于Docker服务的信息,也许它可以帮助您更好地理解Github Actions中的服务。