summaryrefslogtreecommitdiff
path: root/.github/workflows/build-containers.yml
blob: 020cedbcc96cdac3f48f3fb22efcb714d075817f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
name: Containers

on:
  # This Workflow can be triggered manually
  workflow_dispatch:
  # Build new Spack develop containers nightly.
  schedule:
    - cron: '34 0 * * *'
  # Run on pull requests that modify this file
  pull_request:
    branches:
      - develop
    paths:
      - '.github/workflows/build-containers.yml'
      - 'share/spack/docker/*'
      - 'share/spack/templates/container/*'
      - 'lib/spack/spack/container/*'
  # Let's also build & tag Spack containers on releases.
  release:
    types: [published]

concurrency:
  group: build_containers-${{github.ref}}-${{github.event.pull_request.number || github.run_number}}
  cancel-in-progress: true

jobs:
  deploy-images:
    runs-on: ubuntu-latest
    permissions:
      packages: write
    strategy:
      # Even if one container fails to build we still want the others
      # to continue their builds.
      fail-fast: false
      # A matrix of Dockerfile paths, associated tags, and which architectures
      # they support.
      matrix:
        # Meaning of the various items in the matrix list
        # 0: Container name (e.g. ubuntu-bionic)
        # 1: Platforms to build for
        # 2: Base image (e.g. ubuntu:22.04)
        dockerfile: [[amazon-linux, 'linux/amd64,linux/arm64', 'amazonlinux:2'],
                     [centos7, 'linux/amd64,linux/arm64,linux/ppc64le', 'centos:7'],
                     [centos-stream, 'linux/amd64,linux/arm64,linux/ppc64le', 'centos:stream'],
                     [leap15, 'linux/amd64,linux/arm64,linux/ppc64le', 'opensuse/leap:15'],
                     [ubuntu-focal, 'linux/amd64,linux/arm64,linux/ppc64le', 'ubuntu:20.04'],
                     [ubuntu-jammy, 'linux/amd64,linux/arm64,linux/ppc64le', 'ubuntu:22.04'],
                     [almalinux8, 'linux/amd64,linux/arm64,linux/ppc64le', 'almalinux:8'],
                     [almalinux9, 'linux/amd64,linux/arm64,linux/ppc64le', 'almalinux:9'],
                     [rockylinux8, 'linux/amd64,linux/arm64', 'rockylinux:8'],
                     [rockylinux9, 'linux/amd64,linux/arm64', 'rockylinux:9'],
                     [fedora37, 'linux/amd64,linux/arm64,linux/ppc64le', 'fedora:37'],
                     [fedora38, 'linux/amd64,linux/arm64,linux/ppc64le', 'fedora:38']]
    name: Build ${{ matrix.dockerfile[0] }}
    if: github.repository == 'spack/spack'
    steps:
      - name: Checkout
        uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # @v2

      - uses: docker/metadata-action@31cebacef4805868f9ce9a0cb03ee36c32df2ac4
        id: docker_meta
        with:
          images: |
              ghcr.io/${{ github.repository_owner }}/${{ matrix.dockerfile[0] }}
              ${{ github.repository_owner }}/${{ matrix.dockerfile[0] }}
          tags: |
              type=schedule,pattern=nightly
              type=schedule,pattern=develop
              type=semver,pattern={{version}}
              type=semver,pattern={{major}}.{{minor}}
              type=semver,pattern={{major}}
              type=ref,event=branch
              type=ref,event=pr

      - name: Generate the Dockerfile
        env:
          SPACK_YAML_OS: "${{ matrix.dockerfile[2] }}"
        run: |
          .github/workflows/generate_spack_yaml_containerize.sh
          . share/spack/setup-env.sh
          mkdir -p dockerfiles/${{ matrix.dockerfile[0] }}
          spack containerize --last-stage=bootstrap | tee dockerfiles/${{ matrix.dockerfile[0] }}/Dockerfile
          printf "Preparing to build ${{ env.container }} from dockerfiles/${{ matrix.dockerfile[0] }}/Dockerfile"
          if [ ! -f "dockerfiles/${{ matrix.dockerfile[0] }}/Dockerfile" ]; then
              printf "dockerfiles/${{ matrix.dockerfile[0] }}/Dockerfile does not exist"
              exit 1;
          fi

      - name: Upload Dockerfile
        uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32
        with:
          name: dockerfiles
          path: dockerfiles

      - name: Set up QEMU
        uses: docker/setup-qemu-action@68827325e0b33c7199eb31dd4e31fbe9023e06e3

      - name: Set up Docker Buildx
        uses: docker/setup-buildx-action@f95db51fddba0c2d1ec667646a06c2ce06100226

      - name: Log in to GitHub Container Registry
        uses: docker/login-action@343f7c4344506bcbf9b4de18042ae17996df046d
        with:
          registry: ghcr.io
          username: ${{ github.actor }}
          password: ${{ secrets.GITHUB_TOKEN }}

      - name: Log in to DockerHub
        if: github.event_name != 'pull_request'
        uses: docker/login-action@343f7c4344506bcbf9b4de18042ae17996df046d
        with:
          username: ${{ secrets.DOCKERHUB_USERNAME }}
          password: ${{ secrets.DOCKERHUB_TOKEN }}

      - name: Build & Deploy ${{ matrix.dockerfile[0] }}
        uses: docker/build-push-action@4a13e500e55cf31b7a5d59a38ab2040ab0f42f56
        with:
          context: dockerfiles/${{ matrix.dockerfile[0] }}
          platforms: ${{ matrix.dockerfile[1] }}
          push: ${{ github.event_name != 'pull_request' }}
          cache-from: type=gha
          cache-to: type=gha,mode=max
          tags: ${{ steps.docker_meta.outputs.tags }}
          labels: ${{ steps.docker_meta.outputs.labels }}