Skip to content

Commit 352c8df

Browse files
committed
Separate alpine image
1 parent 8557172 commit 352c8df

File tree

6 files changed

+113
-16
lines changed

6 files changed

+113
-16
lines changed

.github/workflows/atlantis-base.yml

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@ name: atlantis-base
33
on:
44
push:
55
paths:
6-
- 'docker-base/**'
6+
- 'docker-base/Dockerfile.*'
77
- '.github/workflows/atlantis-base.yml'
88
branches:
99
- "main"
1010
pull_request:
1111
paths:
12-
- 'docker-base/**'
12+
- 'docker-base/Dockerfile.*'
1313
- '.github/workflows/atlantis-base.yml'
1414
workflow_dispatch:
1515

@@ -23,7 +23,13 @@ concurrency:
2323

2424
jobs:
2525
build:
26+
strategy:
27+
matrix:
28+
image_type: [alpine, debian]
2629
runs-on: ubuntu-22.04
30+
env:
31+
DOCKER_FILE: "Dockerfile.${{ matrix.image_type }}"
32+
IMAGE_SUFFIX: ${{ !contains(matrix.image_type, 'alpine') && "-${{ matrix.image_type }}" || "" }}
2733
steps:
2834
- uses: actions/checkout@v3
2935

@@ -42,16 +48,19 @@ jobs:
4248
registry: ghcr.io
4349
username: ${{ github.actor }}
4450
password: ${{ secrets.GITHUB_TOKEN }}
45-
- run: echo "TODAY=$(date +"%Y.%m.%d")" >> $GITHUB_ENV
4651

47-
- name: Build and push atlantis-base:${{env.TODAY}} image
52+
- name: Populate release version
53+
run: echo "TODAY=$(date +"%Y.%m.%d")" >> $GITHUB_ENV
54+
55+
- name: Build and push atlantis-base:${{ env.TODAY }}${{ env.IMAGE_SUFFIX }} image
4856
uses: docker/build-push-action@v3
4957
with:
5058
cache-from: type=gha
5159
cache-to: type=gha,mode=max
5260
context: docker-base
61+
file: docker-base/${{ env.DOCKER_FILE }}
5362
platforms: linux/arm64/v8,linux/amd64,linux/arm/v7
5463
push: ${{ github.event_name != 'pull_request' }}
5564
tags: |
56-
ghcr.io/${{ github.repository_owner }}/atlantis-base:${{env.TODAY}}
57-
ghcr.io/${{ github.repository_owner }}/atlantis-base:latest
65+
ghcr.io/${{ github.repository_owner }}/atlantis-base:${{ env.TODAY }}${{ env.IMAGE_SUFFIX }}
66+
ghcr.io/${{ github.repository_owner }}/atlantis-base:latest${{ env.IMAGE_SUFFIX }}

.github/workflows/atlantis-image.yml

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,17 @@ concurrency:
1919

2020
jobs:
2121
build:
22+
strategy:
23+
matrix:
24+
image_type: [alpine]
2225
runs-on: ubuntu-22.04
2326
env:
2427
RELEASE_TYPE: ${{ contains(github.ref, 'pre') && 'pre' || 'stable' }}
2528
RELEASE_TAG: ${{ contains(github.ref, 'pre') && 'prerelease-latest' || 'latest' }}
29+
IMAGE_SUFFIX: ${{ !contains(matrix.image_type, 'alpine') && "-${{ matrix.image_type }}" || "" }}
2630
steps:
2731
- uses: actions/checkout@v3
32+
2833
- uses: actions/setup-go@v3
2934
with:
3035
go-version: 1.19
@@ -46,7 +51,7 @@ jobs:
4651
password: ${{ secrets.GITHUB_TOKEN }}
4752

4853
# Publish dev image to container registry
49-
- name: Build and push atlantis:dev image
54+
- name: Build and push atlantis:dev${{ env.IMAGE_SUFFIX }} image
5055
if: ${{ contains(fromJson('["push", "pull_request"]'), github.event_name) }}
5156
uses: docker/build-push-action@v3
5257
with:
@@ -56,10 +61,10 @@ jobs:
5661
platforms: linux/arm64/v8,linux/amd64,linux/arm/v7
5762
push: ${{ github.event_name != 'pull_request' }}
5863
tags: |
59-
ghcr.io/${{ github.repository_owner }}/atlantis:dev
64+
ghcr.io/${{ github.repository_owner }}/atlantis:dev${{ env.IMAGE_SUFFIX }}
6065
6166
# Publish release to container registry
62-
- name: populate release version
67+
- name: Populate release version
6368
if: |
6469
contains(fromJson('["push", "pull_request"]'), github.event_name) &&
6570
startsWith(github.ref, 'refs/tags/')
@@ -74,8 +79,9 @@ jobs:
7479
cache-from: type=gha
7580
cache-to: type=gha,mode=max
7681
context: .
82+
build-args: ATLANTIS_BASE_TAG_TYPE=${{ matrix.image_type }}
7783
platforms: linux/arm64/v8,linux/amd64,linux/arm/v7
7884
push: ${{ github.event_name != 'pull_request' }}
7985
tags: |
80-
ghcr.io/${{ github.repository_owner }}/atlantis:${{ env.RELEASE_VERSION }}
81-
ghcr.io/${{ github.repository_owner }}/atlantis:${{ env.RELEASE_TAG }}
86+
ghcr.io/${{ github.repository_owner }}/atlantis:${{ env.RELEASE_VERSION }}${{ env.IMAGE_SUFFIX }}
87+
ghcr.io/${{ github.repository_owner }}/atlantis:${{ env.RELEASE_TAG }}${{ env.IMAGE_SUFFIX }}

Dockerfile

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1+
ARG ATLANTIS_BASE=ghcr.io/runatlantis/atlantis-base
2+
ARG ATLANTIS_BASE_TAG_DATE=2022.12.11
3+
ARG ATLANTIS_BASE_TAG_TYPE=alpine
4+
15
# Stage 1: build artifact
6+
27
FROM golang:1.19.4-alpine AS builder
38

49
WORKDIR /app
@@ -9,7 +14,7 @@ RUN --mount=type=cache,target=/go/pkg/mod \
914

1015
# Stage 2
1116
# The runatlantis/atlantis-base is created by docker-base/Dockerfile
12-
FROM ghcr.io/runatlantis/atlantis-base:2022.12.11 AS base
17+
FROM ${ATLANTIS_BASE}:${ATLANTIS_BASE_TAG_DATE}-${ATLANTIS_BASE_TAG_TYPE} AS base
1318

1419
# Get the architecture the image is being built for
1520
ARG TARGETPLATFORM
File renamed without changes.

docker-base/Dockerfile.debian

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
# This Dockerfile builds our base image with gosu, dumb-init and the atlantis
2+
# user. We split this from the main Dockerfile because this base doesn't change
3+
# and also because it kept breaking the build due to flakiness.
4+
FROM debian:bullseye-20221205-slim
5+
6+
# We use gosu to step down from root and run as the atlantis user so we need
7+
# to create that user and group.
8+
# We add the atlantis user to the root group and make its home directory
9+
# owned by root so that OpenShift users can use /home/atlantis as their
10+
# data dir because OpenShift runs containers as a random uid that's part of
11+
# the root group.
12+
RUN useradd --create-home --user-group --shell /bin/bash atlantis && \
13+
adduser atlantis root && \
14+
chown atlantis:root /home/atlantis/ && \
15+
chmod g=u /home/atlantis/ && \
16+
chmod g=u /etc/passwd
17+
18+
# Install gosu and git-lfs.
19+
ENV GOSU_VERSION=1.14
20+
ENV GIT_LFS_VERSION=3.1.2
21+
22+
# Automatically populated with the architecture the image is being built for.
23+
ARG TARGETPLATFORM
24+
25+
# Install packages needed for running Atlantis.
26+
RUN apt-get update \
27+
&& apt-get install -y --no-install-recommends \
28+
ca-certificates=20210119 \
29+
curl=7.74.0-1.3+deb11u3 \
30+
git=1:2.30.2-1 \
31+
unzip=6.0-26+deb11u1 \
32+
bash=5.1-2+deb11u1 \
33+
openssh-server=1:8.4p1-5+deb11u1 \
34+
libcap2=1:2.44-1 \
35+
dumb-init=1.2.5-1 \
36+
# Install packages needed for building dependencies.
37+
&& apt-get install -y --no-install-recommends \
38+
gnupg=2.2.27-2+deb11u2 \
39+
openssl=1.1.1n-0+deb11u3 && \
40+
mkdir -p /tmp/build && \
41+
cd /tmp/build && \
42+
# git-lfs
43+
case ${TARGETPLATFORM} in \
44+
"linux/amd64") GIT_LFS_ARCH=amd64 ;; \
45+
"linux/arm64") GIT_LFS_ARCH=arm64 ;; \
46+
"linux/arm/v7") GIT_LFS_ARCH=arm ;; \
47+
esac && \
48+
curl -L -s --output git-lfs.tar.gz "https://github.com/git-lfs/git-lfs/releases/download/v${GIT_LFS_VERSION}/git-lfs-linux-${GIT_LFS_ARCH}-v${GIT_LFS_VERSION}.tar.gz" && \
49+
tar -xf git-lfs.tar.gz && \
50+
chmod +x git-lfs && \
51+
mv git-lfs /usr/bin/git-lfs && \
52+
git-lfs --version && \
53+
# gosu
54+
case ${TARGETPLATFORM} in \
55+
"linux/amd64") GOSU_ARCH=amd64 ;; \
56+
"linux/arm64") GOSU_ARCH=arm64 ;; \
57+
"linux/arm/v7") GOSU_ARCH=armhf ;; \
58+
esac && \
59+
curl -L -s --output gosu "https://github.com/tianon/gosu/releases/download/${GOSU_VERSION}/gosu-${GOSU_ARCH}" && \
60+
curl -L -s --output gosu.asc "https://github.com/tianon/gosu/releases/download/${GOSU_VERSION}/gosu-${GOSU_ARCH}.asc" && \
61+
for server in $(shuf -e ipv4.pool.sks-keyservers.net \
62+
hkp://p80.pool.sks-keyservers.net:80 \
63+
keyserver.ubuntu.com \
64+
hkp://keyserver.ubuntu.com:80 \
65+
pgp.mit.edu) ; do \
66+
gpg --keyserver "$server" --recv-keys B42F6819007F00F88E364FD4036A9C25BF357DD4 && break || : ; \
67+
done && \
68+
gpg --batch --verify gosu.asc gosu && \
69+
chmod +x gosu && \
70+
cp gosu /bin && \
71+
gosu --version && \
72+
# Cleanup
73+
cd /tmp && \
74+
rm -rf /tmp/build && \
75+
gpgconf --kill dirmngr && \
76+
gpgconf --kill gpg-agent && \
77+
rm -rf /root/.gnupg

docker-entrypoint.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ set -e
55

66
# If the user is trying to run atlantis directly with some arguments, then
77
# pass them to atlantis.
8-
if [ "${1:0:1}" = '-' ]; then
8+
if [ "$(echo "${1}" | cut -c1)" ]; then
99
set -- atlantis "$@"
1010
fi
1111

@@ -23,7 +23,7 @@ if atlantis help "$1" 2>&1 | grep -q "atlantis $1"; then
2323
fi
2424

2525
# If the current uid running does not have a user create one in /etc/passwd
26-
if ! whoami &> /dev/null; then
26+
if ! whoami > /dev/null 2>&1; then
2727
if [ -w /etc/passwd ]; then
2828
echo "${USER_NAME:-default}:x:$(id -u):0:${USER_NAME:-default} user:/home/atlantis:/sbin/nologin" >> /etc/passwd
2929
fi
@@ -32,11 +32,11 @@ fi
3232
# If we're running as root and we're trying to execute atlantis then we use
3333
# gosu to step down from root and run as the atlantis user.
3434
# In OpenShift, containers are run as a random users so we don't need to use gosu.
35-
if [[ $(id -u) == 0 ]] && [[ "$1" = 'atlantis' ]]; then
35+
if [ "$(id -u)" = 0 ] && [ "$1" = 'atlantis' ]; then
3636
# If requested, set the capability to bind to privileged ports before
3737
# we drop to the non-root user. Note that this doesn't work with all
3838
# storage drivers (it won't work with AUFS).
39-
if [ ! -z ${ATLANTIS_ALLOW_PRIVILEGED_PORTS+x} ]; then
39+
if [ -n "${ATLANTIS_ALLOW_PRIVILEGED_PORTS+x}" ]; then
4040
setcap "cap_net_bind_service=+ep" /bin/atlantis
4141
fi
4242

0 commit comments

Comments
 (0)