Skip to content

Commit

Permalink
Use archive.debian.org for apt sources on debian 7 (#16)
Browse files Browse the repository at this point in the history
The debian 7 (wheezy) mirrors were archived since it's EOL.
I don't think we statically link with anything from wheezy we just use it because it
has an early version of glibc so we get decent OS compatibility. But we should
still consider moving to a new version.

https://lists.debian.org/debian-devel-announce/2019/03/msg00006.html

I added templating so I could make the inclusion of the sources.list file conditional.
  • Loading branch information
andrewkroh authored Mar 22, 2019
1 parent 7e36cab commit 9684a28
Show file tree
Hide file tree
Showing 22 changed files with 109 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@
.idea
.vagrant
_obj
Dockerfile
File renamed without changes.
1 change: 1 addition & 0 deletions fpm/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ VERSION := 1.11.0

build:
@echo ">> Building $(REPOSITORY)/$(NAME):$(VERSION)$(SUFFIX)"
@go run ../template.go -t Dockerfile.tmpl -o Dockerfile
@docker build -t "$(REPOSITORY)/$(NAME):$(VERSION)$(SUFFIX)" \
--build-arg FPM_VERSION=$(VERSION) \
--build-arg IMAGE="$(REPOSITORY)/$(NAME):$(VERSION)$(SUFFIX)$(TAG_EXTENSION)" \
Expand Down
3 changes: 3 additions & 0 deletions go1.10/Makefile.common
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,11 @@ DEBIAN_VERSION ?= 9
SUFFIX := -$(shell basename $(CURDIR))
TAG_EXTENSION ?=

export DEBIAN_VERSION TAG_EXTENSION

build:
@echo ">> Building $(REPOSITORY)/$(NAME):$(VERSION)$(SUFFIX)$(TAG_EXTENSION)"
@go run $(SELF_DIR)/../template.go -t Dockerfile.tmpl -o Dockerfile
@docker build -t "$(REPOSITORY)/$(NAME):$(VERSION)$(SUFFIX)$(TAG_EXTENSION)" \
--build-arg REPOSITORY=$(REPOSITORY) \
--build-arg VERSION=$(VERSION) \
Expand Down
File renamed without changes.
5 changes: 5 additions & 0 deletions go1.10/base/Dockerfile → go1.10/base/Dockerfile.tmpl
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
ARG DEBIAN_VERSION
FROM debian:${DEBIAN_VERSION}

{{if eq .DEBIAN_VERSION "7" -}}
# Replace sources.list in order to use archive.debian.org.
COPY sources-debian{{.DEBIAN_VERSION}}.list /etc/apt/sources.list
{{end -}}

RUN \
apt-get update \
&& apt-get dist-upgrade -y \
Expand Down
2 changes: 2 additions & 0 deletions go1.10/base/sources-debian7.list
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
deb http://archive.debian.org/debian wheezy main
deb http://security.debian.org/debian-security wheezy/updates main
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
3 changes: 3 additions & 0 deletions go1.11/Makefile.common
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,11 @@ DEBIAN_VERSION ?= 9
SUFFIX := -$(shell basename $(CURDIR))
TAG_EXTENSION ?=

export DEBIAN_VERSION TAG_EXTENSION

build:
@echo ">> Building $(REPOSITORY)/$(NAME):$(VERSION)$(SUFFIX)$(TAG_EXTENSION)"
@go run $(SELF_DIR)/../template.go -t Dockerfile.tmpl -o Dockerfile
@docker build -t "$(REPOSITORY)/$(NAME):$(VERSION)$(SUFFIX)$(TAG_EXTENSION)" \
--build-arg REPOSITORY=$(REPOSITORY) \
--build-arg VERSION=$(VERSION) \
Expand Down
File renamed without changes.
5 changes: 5 additions & 0 deletions go1.11/base/Dockerfile → go1.11/base/Dockerfile.tmpl
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
ARG DEBIAN_VERSION
FROM debian:${DEBIAN_VERSION}

{{if eq .DEBIAN_VERSION "7" -}}
# Replace sources.list in order to use archive.debian.org.
COPY sources-debian{{.DEBIAN_VERSION}}.list /etc/apt/sources.list
{{end -}}

RUN \
apt-get update \
&& apt-get dist-upgrade -y \
Expand Down
2 changes: 2 additions & 0 deletions go1.11/base/sources-debian7.list
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
deb http://archive.debian.org/debian wheezy main
deb http://security.debian.org/debian-security wheezy/updates main
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
87 changes: 87 additions & 0 deletions template.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
// Licensed to Elasticsearch B.V. under one or more contributor
// license agreements. See the NOTICE file distributed with
// this work for additional information regarding copyright
// ownership. Elasticsearch B.V. licenses this file to you under
// the Apache License, Version 2.0 (the "License"); you may
// not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.

package main

import (
"bytes"
"flag"
"fmt"
"io/ioutil"
"log"
"os"
"path/filepath"
"strings"
"text/template"
)

var usageText = `
Usage: template -t <tmpl file> [-o output]
This command renders the specified template file using the Go text/template
package. It makes the current environment available as variables.
Options:
`[1:]

var (
templateFile string
outputFile string
)

func init() {
flag.StringVar(&templateFile, "t", "", "template file")
flag.StringVar(&outputFile, "o", "", "output file")
flag.Usage = func() {
fmt.Fprintf(os.Stderr, usageText)
flag.PrintDefaults()
}
}

func main() {
flag.Parse()
log.SetFlags(0)

if templateFile == "" {
log.Fatal("Template file (-t) is required.")
}

t := template.Must(template.
New(filepath.Base(templateFile)).
ParseFiles(templateFile))

data := envVars()
buf := new(bytes.Buffer)
if err := t.Execute(buf, data); err != nil {
log.Fatal(err)
}

if outputFile == "-" || outputFile == "" {
fmt.Println(buf.String())
} else {
if err := ioutil.WriteFile(outputFile, buf.Bytes(), 0644); err != nil {
log.Fatal(err)
}
}
}

func envVars() map[string]string {
env := map[string]string{}
for _, e := range os.Environ() {
parts := strings.SplitN(e, "=", 2)
env[parts[0]] = parts[1]
}
return env
}

0 comments on commit 9684a28

Please sign in to comment.