Skip to content

Commit

Permalink
Merge pull request #320 from reubenmiller/fix-arm64-docker-images
Browse files Browse the repository at this point in the history
fix: update goreleaser docker build definition to support multi platform images
  • Loading branch information
reubenmiller authored Nov 29, 2023
2 parents ff0a4a8 + a7b85b4 commit a1c2a39
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 42 deletions.
28 changes: 16 additions & 12 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,7 @@ brews:
dockers:
- dockerfile: docker/shell.dockerfile
use: buildx
goarch: amd64

# Templates of the Docker image names.
image_templates:
Expand All @@ -261,11 +262,12 @@ dockers:

- dockerfile: docker/shell.dockerfile
use: buildx
goarch: arm64

# Templates of the Docker image names.
image_templates:
- "ghcr.io/reubenmiller/{{.ProjectName}}-shell:latest-arm64"
- "ghcr.io/reubenmiller/{{.ProjectName}}-shell:{{ .Tag }}-arm64"
- "ghcr.io/reubenmiller/{{.ProjectName}}-shell:latest-arm64v8"
- "ghcr.io/reubenmiller/{{.ProjectName}}-shell:{{ .Tag }}-arm64v8"

# Template of the docker build flags.
build_flag_templates:
Expand All @@ -274,13 +276,14 @@ dockers:
- "--label=org.opencontainers.image.title={{.ProjectName}}"
- "--label=org.opencontainers.image.revision={{.FullCommit}}"
- "--label=org.opencontainers.image.version={{.Version}}"
- "--platform=linux/arm64"
- "--platform=linux/arm64/v8"

#
# pwsh image
#
- dockerfile: docker/pwsh2.dockerfile
- dockerfile: docker/pwsh.dockerfile
use: buildx
goarch: amd64

# Templates of the Docker image names.
image_templates:
Expand All @@ -300,13 +303,14 @@ dockers:
- docker/profile.ps1
- output_pwsh/PSc8y

- dockerfile: docker/pwsh2.dockerfile
- dockerfile: docker/pwsh.dockerfile
use: buildx
goarch: arm64

# Templates of the Docker image names.
image_templates:
- "ghcr.io/reubenmiller/{{.ProjectName}}-pwsh:latest-arm64"
- "ghcr.io/reubenmiller/{{.ProjectName}}-pwsh:{{ .Tag }}-arm64"
- "ghcr.io/reubenmiller/{{.ProjectName}}-pwsh:latest-arm64v8"
- "ghcr.io/reubenmiller/{{.ProjectName}}-pwsh:{{ .Tag }}-arm64v8"

# Template of the docker build flags.
build_flag_templates:
Expand All @@ -315,7 +319,7 @@ dockers:
- "--label=org.opencontainers.image.title={{.ProjectName}}"
- "--label=org.opencontainers.image.revision={{.FullCommit}}"
- "--label=org.opencontainers.image.version={{.Version}}"
- "--platform=linux/arm64"
- "--platform=linux/arm64/v8"

extra_files:
- docker/profile.ps1
Expand All @@ -325,19 +329,19 @@ docker_manifests:
- name_template: "ghcr.io/reubenmiller/{{.ProjectName}}-shell:{{ .Tag }}"
image_templates:
- "ghcr.io/reubenmiller/{{.ProjectName}}-shell:{{ .Tag }}-amd64"
- "ghcr.io/reubenmiller/{{.ProjectName}}-shell:{{ .Tag }}-arm64"
- "ghcr.io/reubenmiller/{{.ProjectName}}-shell:{{ .Tag }}-arm64v8"

- name_template: "ghcr.io/reubenmiller/{{.ProjectName}}-shell:latest"
image_templates:
- "ghcr.io/reubenmiller/{{.ProjectName}}-shell:latest-amd64"
- "ghcr.io/reubenmiller/{{.ProjectName}}-shell:latest-arm64"
- "ghcr.io/reubenmiller/{{.ProjectName}}-shell:latest-arm64v8"

- name_template: "ghcr.io/reubenmiller/{{.ProjectName}}-pwsh:{{ .Tag }}"
image_templates:
- "ghcr.io/reubenmiller/{{.ProjectName}}-pwsh:{{ .Tag }}-amd64"
- "ghcr.io/reubenmiller/{{.ProjectName}}-pwsh:{{ .Tag }}-arm64"
- "ghcr.io/reubenmiller/{{.ProjectName}}-pwsh:{{ .Tag }}-arm64v8"

- name_template: "ghcr.io/reubenmiller/{{.ProjectName}}-pwsh:latest"
image_templates:
- "ghcr.io/reubenmiller/{{.ProjectName}}-pwsh:latest-amd64"
- "ghcr.io/reubenmiller/{{.ProjectName}}-pwsh:latest-arm64"
- "ghcr.io/reubenmiller/{{.ProjectName}}-pwsh:latest-arm64v8"
40 changes: 31 additions & 9 deletions docker/pwsh.dockerfile
Original file line number Diff line number Diff line change
@@ -1,19 +1,41 @@
FROM mcr.microsoft.com/powershell:7.1.1-ubuntu-18.04
FROM ubuntu:22.04
ARG TARGETARCH

RUN apt-get update \
&& apt-get install -y vim git jq \
ARG USERNAME=c8yuser

# Install powershell as currently there is no official docker image
ENV DOTNET_SYSTEM_GLOBALIZATION_INVARIANT=true
RUN apt-get update && apt-get install -y --no-install-recommends curl wget ca-certificates \
&& case ${TARGETARCH} in \
"amd64") PWSH_ARCH=x64 ;; \
"arm64") PWSH_ARCH=arm64 ;; \
"arm64/v8") PWSH_ARCH=arm64 ;; \
esac \
&& curl -L -o /tmp/powershell.tar.gz https://github.com/PowerShell/PowerShell/releases/download/v7.4.0/powershell-7.4.0-linux-${PWSH_ARCH}.tar.gz\
&& mkdir -p /opt/microsoft/powershell/7 \
&& tar zxf /tmp/powershell.tar.gz -C /opt/microsoft/powershell/7 \
&& chmod +x /opt/microsoft/powershell/7/pwsh \
&& ln -s /opt/microsoft/powershell/7/pwsh /usr/bin/pwsh

RUN apt-get update \
&& apt-get install -y vim git jq sudo \
&& adduser --disabled-password --gecos '' $USERNAME \
&& adduser $USERNAME sudo \
&& echo '%sudo ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers \
&& rm -rf /var/lib/apt/lists/* \
&& git clone https://github.com/reubenmiller/go-c8y-cli-addons.git /root/.go-c8y-cli
&& git clone https://github.com/reubenmiller/go-c8y-cli-addons.git /home/${USERNAME}/.go-c8y-cli

ENV C8Y_HOME=/root/.go-c8y-cli
ENV C8Y_HOME=/home/${USERNAME}/.go-c8y-cli
ENV C8Y_SESSION_HOME=/sessions
ENV C8Y_INSTALL_OPTIONS="-AllowPrerelease"
COPY output_pwsh/PSc8y /home/${USERNAME}/modules/PSc8y
ENV PSModulePath=/home/${USERNAME}/modules
VOLUME [ "/sessions" ]

COPY profile.ps1 /root/.config/powershell/Microsoft.PowerShell_profile.ps1
COPY docker/profile.ps1 /home/${USERNAME}/.config/powershell/Microsoft.PowerShell_profile.ps1
RUN chown -R $USERNAME /home/$USERNAME

RUN pwsh -c "Set-PSRepository -Name 'PSGallery' -InstallationPolicy Trusted; " \
&& pwsh -c "Install-Module PSc8y -Repository PSGallery -AllowClobber $C8Y_INSTALL_OPTIONS -Force" \
&& rm -f /root/c8y.activitylog*
USER $USERNAME

WORKDIR /home/${USERNAME}
ENTRYPOINT [ "pwsh", "-NoExit", "-c", "Import-Module PSc8y" ]
18 changes: 0 additions & 18 deletions docker/pwsh2.dockerfile

This file was deleted.

5 changes: 2 additions & 3 deletions docker/shell.dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
FROM alpine:3.11
FROM alpine:3.18

ARG USERNAME=c8yuser
ARG C8Y_VERSION=1.3.0

RUN apk update \
&& apk add curl unzip bash bash-completion zsh fish git vim jq sudo coreutils \
Expand All @@ -15,7 +14,7 @@ RUN apk update \
WORKDIR /home/$USERNAME

USER $USERNAME
RUN sh -c "$(wget https://raw.github.com/robbyrussell/oh-my-zsh/master/tools/install.sh -O -)" -s --batch
RUN sh -c "$(wget -qO- https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)" -s --batch
USER root

# add binary to path
Expand Down

0 comments on commit a1c2a39

Please sign in to comment.